From 4527de8cba3bf5f107fcefcf43dbdaa308881ba4 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 8 Sep 2011 18:42:44 +0700 Subject: [PATCH] vm context with accessors true copy of sandbox properties catch sealed errors, pass global's prototype to CloneObject Fixes #1673 --- lib/vm.js | 13 +++++ src/node_script.cc | 57 ++++++++++++------- .../test-vm-create-context-accessors.js | 26 +++++++++ 3 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 test/simple/test-vm-create-context-accessors.js diff --git a/lib/vm.js b/lib/vm.js index d3348afac50..45f0f59150b 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -21,6 +21,19 @@ var binding = process.binding('evals'); +binding.NodeScript._setCloneMethod(function(source, target) { + Object.getOwnPropertyNames(source).forEach(function(key) { + try { + var desc = Object.getOwnPropertyDescriptor(source, key); + if (desc.value === source) desc.value = target; + + Object.defineProperty(target, key, desc); + } catch (e) { + // Catch sealed properties errors + } + }); +}); + exports.Script = binding.NodeScript; exports.createScript = function(code, ctx, name) { return new exports.Script(code, ctx, name); diff --git a/src/node_script.cc b/src/node_script.cc index 4f4153caa98..019597485f2 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -37,9 +37,11 @@ using v8::TryCatch; using v8::String; using v8::Exception; using v8::Local; +using v8::Null; using v8::Array; using v8::Persistent; using v8::Integer; +using v8::Function; using v8::FunctionTemplate; @@ -94,10 +96,23 @@ class WrappedScript : ObjectWrap { static Handle CompileRunInThisContext(const Arguments& args); static Handle CompileRunInNewContext(const Arguments& args); + static Handle SetCloneMethod(const Arguments& args); + Persistent