Skip to content

Commit 681fe59

Browse files
denzpindutny
authored andcommitted
vm: assign Environment to created context
ContextifyContext::CreateV8Context is now create context with Environment pointer Signed-off-by: Fedor Indutny <[email protected]>
1 parent bd24ab2 commit 681fe59

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/env-inl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,14 @@ inline void Environment::TickInfo::set_last_threw(bool value) {
190190

191191
inline Environment* Environment::New(v8::Local<v8::Context> context) {
192192
Environment* env = new Environment(context);
193-
context->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, env);
193+
env->AssignToContext(context);
194194
return env;
195195
}
196196

197+
inline void Environment::AssignToContext(v8::Local<v8::Context> context) {
198+
context->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, this);
199+
}
200+
197201
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
198202
return GetCurrent(isolate->GetCurrentContext());
199203
}

src/env.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ class Environment {
362362
void StartGarbageCollectionTracking(v8::Local<v8::Function> callback);
363363
void StopGarbageCollectionTracking();
364364

365+
void AssignToContext(v8::Local<v8::Context> context);
366+
365367
inline v8::Isolate* isolate() const;
366368
inline uv_loop_t* event_loop() const;
367369
inline bool has_async_listener() const;

src/node_contextify.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class ContextifyContext {
231231
Local<Context> ctx = Context::New(env->isolate(), NULL, object_template);
232232
if (!ctx.IsEmpty())
233233
ctx->SetSecurityToken(env->context()->GetSecurityToken());
234+
235+
env->AssignToContext(ctx);
236+
234237
return scope.Escape(ctx);
235238
}
236239

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Joyent, Inc. and other Node contributors.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a
4+
// copy of this software and associated documentation files (the
5+
// "Software"), to deal in the Software without restriction, including
6+
// without limitation the rights to use, copy, modify, merge, publish,
7+
// distribute, sublicense, and/or sell copies of the Software, and to permit
8+
// persons to whom the Software is furnished to do so, subject to the
9+
// following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included
12+
// in all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
var common = require('../common'),
23+
assert = require('assert'),
24+
vm = require('vm');
25+
26+
assert.doesNotThrow(function() {
27+
var context = vm.createContext({ process: process });
28+
var result = vm.runInContext('process.env["PATH"]', context);
29+
assert.notEqual(undefined, result);
30+
});

0 commit comments

Comments
 (0)