From 31fce45fbe586d8c46e61ce674b77bbf7cfb379c Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 8 Sep 2011 18:42:44 +0700 Subject: [PATCH 1/6] [script] true copy of sandbox properties --- lib/vm.js | 11 ++++++++++ src/node_script.cc | 55 +++++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/lib/vm.js b/lib/vm.js index d3348afac50..0d395f47341 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -21,6 +21,17 @@ var binding = process.binding('evals'); +binding.NodeScript._setCloneMethod(function(source, target) { + Object.getOwnPropertyNames(source).forEach(function(key) { + delete target[key]; + + var desc = Object.getOwnPropertyDescriptor(source, key); + if (desc.value === source) desc.value = target; + + Object.defineProperty(target, key, desc); + }); +}); + 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..65a9484bdd2 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,21 @@ class WrappedScript : ObjectWrap { static Handle CompileRunInThisContext(const Arguments& args); static Handle CompileRunInNewContext(const Arguments& args); + static Handle SetCloneMethod(const Arguments& args); + Persistent