Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 26834b0

Browse files
committed
Revert "vm context with accessors"
This reverts commit 4527de8. Causes segfault in test/message/undefined_reference_in_new_context.js
1 parent 65e6ba9 commit 26834b0

3 files changed

Lines changed: 22 additions & 74 deletions

File tree

lib/vm.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121

2222
var binding = process.binding('evals');
2323

24-
binding.NodeScript._setCloneMethod(function(source, target) {
25-
Object.getOwnPropertyNames(source).forEach(function(key) {
26-
try {
27-
var desc = Object.getOwnPropertyDescriptor(source, key);
28-
if (desc.value === source) desc.value = target;
29-
30-
Object.defineProperty(target, key, desc);
31-
} catch (e) {
32-
// Catch sealed properties errors
33-
}
34-
});
35-
});
36-
3724
exports.Script = binding.NodeScript;
3825
exports.createScript = function(code, ctx, name) {
3926
return new exports.Script(code, ctx, name);

src/node_script.cc

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ using v8::TryCatch;
3737
using v8::String;
3838
using v8::Exception;
3939
using v8::Local;
40-
using v8::Null;
4140
using v8::Array;
4241
using v8::Persistent;
4342
using v8::Integer;
44-
using v8::Function;
4543
using 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-
116101
void 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

305279
template <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) {

test/simple/test-vm-create-context-accessors.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)