0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/simple/test-eval-cx.js
isaacs 943b2c61a8 Make evalcx work like it's supposed to.
1. Move the context->Enter() call so that the global obj is available for writing.
2. On success, copy the modified global out to the sandbox object.
3. Don't copy functions in either direction.  They have scope and closures, and make for craziness when trying to keep contexts separate.
4. Only do the ->ToObject->Clone() on objects, so that simple values stay simple.
5. Update the test so that it tests all this stuff.
2010-03-16 10:27:47 -07:00

33 lines
714 B
JavaScript

require("../common");
debug('evalcx a string');
var result = process.evalcx('"passed";');
assert.equal('passed', result);
debug('evalcx a thrown error');
assert.throws(function() {
process.evalcx('throw new Error("test");');
});
hello = 5;
process.evalcx('hello = 2');
assert.equal(5, hello);
code = "foo = 1;"
+ "bar = 2;"
+ "if (baz !== 3) throw new Error('test fail');"
+ "quux.pwned = true;";
foo = 2;
var quux = { pwned : false };
obj = { foo : 0, baz : 3, quux : quux };
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);