diff --git a/src/node.js b/src/node.js index 9d94f88d93..e16f13ecb0 100644 --- a/src/node.js +++ b/src/node.js @@ -433,6 +433,7 @@ var module = (function () { sandbox.__filename = filename; sandbox.__dirname = dirname; sandbox.module = self; + sandbox.global = sandbox; sandbox.root = root; Script.runInNewContext(content, sandbox, filename); diff --git a/src/node_script.cc b/src/node_script.cc index cbe8d12b5d..d9631ec2f3 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -212,6 +212,7 @@ template Length(); i++) { Handle key = keys->Get(Integer::New(i))->ToString(); Handle value = sandbox->Get(key); + if (value == sandbox) { value = context->Global(); } context->Global()->Set(key, value); } } @@ -264,6 +265,7 @@ template Length(); i++) { Handle key = keys->Get(Integer::New(i))->ToString(); Handle value = context->Global()->Get(key); + if (value == context->Global()) { value = sandbox; } sandbox->Set(key, value); } }