for (i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = sandbox->Get(key);
- if (value->IsFunction()) continue;
- if (value->IsObject()) {
- value = value->ToObject()->Clone();
- }
context->Global()->Set(key, value);
}
for (i = 0; i < keys->Length(); i++) {
Handle<String> key = keys->Get(Integer::New(i))->ToString();
Handle<Value> value = context->Global()->Get(key);
- if (value->IsFunction()) continue;
- if (value->IsObject()) {
- value = value->ToObject()->Clone();
- }
sandbox->Set(key, value);
}
}
assert.equal(5, hello);
+debug("pass values in and out");
code = "foo = 1;"
+ "bar = 2;"
- + "if (baz !== 3) throw new Error('test fail');"
- + "quux.pwned = true;";
-
+ + "if (baz !== 3) throw new Error('test fail');";
foo = 2;
-var quux = { pwned : false };
-obj = { foo : 0, baz : 3, quux : quux };
+obj = { foo : 0, baz : 3 };
var baz = process.evalcx(code, obj);
assert.equal(1, obj.foo);
assert.equal(2, obj.bar);
-assert.equal(obj.quux.pwned, true);
-assert.equal(quux.pwned, false);
-assert.notEqual(quux, obj.quux);
-
assert.equal(2, foo);
+
+debug("call a function by reference");
+function changeFoo () { foo = 100 }
+process.evalcx("f()", { f : changeFoo });
+assert.equal(foo, 100);
+
+debug("modify an object by reference");
+var f = { a : 1 };
+process.evalcx("f.a = 2", { f : f });
+assert.equal(f.a, 2);
+