vm: assign Environment to created context
ContextifyContext::CreateV8Context is now create context with Environment pointer Signed-off-by: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
parent
bd24ab2bd7
commit
681fe599d7
@ -190,10 +190,14 @@ inline void Environment::TickInfo::set_last_threw(bool value) {
|
|||||||
|
|
||||||
inline Environment* Environment::New(v8::Local<v8::Context> context) {
|
inline Environment* Environment::New(v8::Local<v8::Context> context) {
|
||||||
Environment* env = new Environment(context);
|
Environment* env = new Environment(context);
|
||||||
context->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, env);
|
env->AssignToContext(context);
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Environment::AssignToContext(v8::Local<v8::Context> context) {
|
||||||
|
context->SetAlignedPointerInEmbedderData(kContextEmbedderDataIndex, this);
|
||||||
|
}
|
||||||
|
|
||||||
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
|
inline Environment* Environment::GetCurrent(v8::Isolate* isolate) {
|
||||||
return GetCurrent(isolate->GetCurrentContext());
|
return GetCurrent(isolate->GetCurrentContext());
|
||||||
}
|
}
|
||||||
|
@ -362,6 +362,8 @@ class Environment {
|
|||||||
void StartGarbageCollectionTracking(v8::Local<v8::Function> callback);
|
void StartGarbageCollectionTracking(v8::Local<v8::Function> callback);
|
||||||
void StopGarbageCollectionTracking();
|
void StopGarbageCollectionTracking();
|
||||||
|
|
||||||
|
void AssignToContext(v8::Local<v8::Context> context);
|
||||||
|
|
||||||
inline v8::Isolate* isolate() const;
|
inline v8::Isolate* isolate() const;
|
||||||
inline uv_loop_t* event_loop() const;
|
inline uv_loop_t* event_loop() const;
|
||||||
inline bool has_async_listener() const;
|
inline bool has_async_listener() const;
|
||||||
|
@ -231,6 +231,9 @@ class ContextifyContext {
|
|||||||
Local<Context> ctx = Context::New(env->isolate(), NULL, object_template);
|
Local<Context> ctx = Context::New(env->isolate(), NULL, object_template);
|
||||||
if (!ctx.IsEmpty())
|
if (!ctx.IsEmpty())
|
||||||
ctx->SetSecurityToken(env->context()->GetSecurityToken());
|
ctx->SetSecurityToken(env->context()->GetSecurityToken());
|
||||||
|
|
||||||
|
env->AssignToContext(ctx);
|
||||||
|
|
||||||
return scope.Escape(ctx);
|
return scope.Escape(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
test/simple/test-regress-GH-7511.js
Normal file
30
test/simple/test-regress-GH-7511.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
// copy of this software and associated documentation files (the
|
||||||
|
// "Software"), to deal in the Software without restriction, including
|
||||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||||
|
// persons to whom the Software is furnished to do so, subject to the
|
||||||
|
// following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included
|
||||||
|
// in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
var common = require('../common'),
|
||||||
|
assert = require('assert'),
|
||||||
|
vm = require('vm');
|
||||||
|
|
||||||
|
assert.doesNotThrow(function() {
|
||||||
|
var context = vm.createContext({ process: process });
|
||||||
|
var result = vm.runInContext('process.env["PATH"]', context);
|
||||||
|
assert.notEqual(undefined, result);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user