mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
834 B
36 lines
834 B
13 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
12 years ago
|
var vm = require('vm');
|
||
13 years ago
|
|
||
|
common.globalCheck = false;
|
||
|
|
||
12 years ago
|
console.error('run a string');
|
||
|
var result = vm.runInThisContext('\'passed\';');
|
||
13 years ago
|
assert.equal('passed', result);
|
||
|
|
||
12 years ago
|
console.error('thrown error');
|
||
13 years ago
|
assert.throws(function() {
|
||
12 years ago
|
vm.runInThisContext('throw new Error(\'test\');');
|
||
|
}, /test/);
|
||
13 years ago
|
|
||
|
hello = 5;
|
||
12 years ago
|
vm.runInThisContext('hello = 2');
|
||
13 years ago
|
assert.equal(2, hello);
|
||
|
|
||
|
|
||
12 years ago
|
console.error('pass values');
|
||
13 years ago
|
code = 'foo = 1;' +
|
||
|
'bar = 2;' +
|
||
|
'if (typeof baz !== \'undefined\') throw new Error(\'test fail\');';
|
||
|
foo = 2;
|
||
|
obj = { foo: 0, baz: 3 };
|
||
12 years ago
|
var baz = vm.runInThisContext(code);
|
||
13 years ago
|
assert.equal(0, obj.foo);
|
||
|
assert.equal(2, bar);
|
||
|
assert.equal(1, foo);
|
||
|
|
||
12 years ago
|
console.error('call a function');
|
||
13 years ago
|
f = function() { foo = 100 };
|
||
12 years ago
|
vm.runInThisContext('f()');
|
||
13 years ago
|
assert.equal(100, foo);
|