@@ -37,11 +37,9 @@ using v8::TryCatch;
3737using v8::String;
3838using v8::Exception;
3939using v8::Local;
40- using v8::Null;
4140using v8::Array;
4241using v8::Persistent;
4342using v8::Integer;
44- using v8::Function;
4543using v8::FunctionTemplate;
4644
4745
@@ -96,23 +94,10 @@ class WrappedScript : ObjectWrap {
9694 static Handle<Value> CompileRunInThisContext (const Arguments& args);
9795 static Handle<Value> CompileRunInNewContext (const Arguments& args);
9896
99- static Handle<Value> SetCloneMethod (const Arguments& args);
100-
10197 Persistent<Script> script_;
10298};
10399
104100
105- Persistent<Function> cloneObjectMethod;
106-
107- void CloneObject (Handle<Object> recv,
108- Handle<Value> source, Handle<Value> target) {
109- HandleScope scope;
110-
111- Handle<Value> args[] = {source, target};
112- cloneObjectMethod->Call (recv, 2 , args);
113- }
114-
115-
116101void WrappedContext::Initialize (Handle<Object> target) {
117102 HandleScope scope;
118103
@@ -192,10 +177,6 @@ void WrappedScript::Initialize(Handle<Object> target) {
192177 " runInNewContext" ,
193178 WrappedScript::RunInNewContext);
194179
195- NODE_SET_PROTOTYPE_METHOD (constructor_template,
196- " _setCloneMethod" ,
197- WrappedScript::SetCloneMethod);
198-
199180 NODE_SET_METHOD (constructor_template,
200181 " createContext" ,
201182 WrappedScript::CreateContext);
@@ -212,10 +193,6 @@ void WrappedScript::Initialize(Handle<Object> target) {
212193 " runInNewContext" ,
213194 WrappedScript::CompileRunInNewContext);
214195
215- NODE_SET_METHOD (constructor_template,
216- " _setCloneMethod" ,
217- WrappedScript::SetCloneMethod);
218-
219196 target->Set (String::NewSymbol (" NodeScript" ),
220197 constructor_template->GetFunction ());
221198}
@@ -248,8 +225,14 @@ Handle<Value> WrappedScript::CreateContext(const Arguments& args) {
248225
249226 if (args.Length () > 0 ) {
250227 Local<Object> sandbox = args[0 ]->ToObject ();
228+ Local<Array> keys = sandbox->GetPropertyNames ();
251229
252- CloneObject (args.This (), sandbox, context);
230+ for (uint32_t i = 0 ; i < keys->Length (); i++) {
231+ Handle<String> key = keys->Get (Integer::New (i))->ToString ();
232+ Handle<Value> value = sandbox->Get (key);
233+ if (value == sandbox) { value = context; }
234+ context->Set (key, value);
235+ }
253236 }
254237
255238
@@ -292,15 +275,6 @@ Handle<Value> WrappedScript::CompileRunInNewContext(const Arguments& args) {
292275 WrappedScript::EvalMachine<compileCode, newContext, returnResult>(args);
293276}
294277
295- Handle<Value> WrappedScript::SetCloneMethod (const Arguments& args) {
296- HandleScope scope;
297-
298- Local<Function> cloneObjectMethod_ = Local<Function>::Cast (args[0 ]);
299- cloneObjectMethod = Persistent<Function>::New (cloneObjectMethod_);
300-
301- return scope.Close (Null ());
302- }
303-
304278
305279template <WrappedScript::EvalInputFlags input_flag,
306280 WrappedScript::EvalContextFlags context_flag,
@@ -369,7 +343,14 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
369343
370344 // Copy everything from the passed in sandbox (either the persistent
371345 // context for runInContext(), or the sandbox arg to runInNewContext()).
372- CloneObject (args.This (), sandbox, context->Global ()->GetPrototype ());
346+ keys = sandbox->GetPropertyNames ();
347+
348+ for (i = 0 ; i < keys->Length (); i++) {
349+ Handle<String> key = keys->Get (Integer::New (i))->ToString ();
350+ Handle<Value> value = sandbox->Get (key);
351+ if (value == sandbox) { value = context->Global (); }
352+ context->Global ()->Set (key, value);
353+ }
373354 }
374355
375356 // Catch errors
@@ -427,7 +408,13 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
427408
428409 if (context_flag == userContext || context_flag == newContext) {
429410 // success! copy changes back onto the sandbox object.
430- CloneObject (args.This (), context->Global ()->GetPrototype (), sandbox);
411+ keys = context->Global ()->GetPropertyNames ();
412+ for (i = 0 ; i < keys->Length (); i++) {
413+ Handle<String> key = keys->Get (Integer::New (i))->ToString ();
414+ Handle<Value> value = context->Global ()->Get (key);
415+ if (value == context->Global ()) { value = sandbox; }
416+ sandbox->Set (key, value);
417+ }
431418 }
432419
433420 if (context_flag == newContext) {
0 commit comments