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