0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-vm-basic.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

50 lines
1.3 KiB
JavaScript

var common = require('../common');
var assert = require('assert');
var vm = require('vm');
// Test 1: vm.runInNewContext
var sandbox = {};
var result = vm.runInNewContext(
'foo = "bar"; this.typeofProcess = typeof process; typeof Object;',
sandbox
);
assert.deepEqual(sandbox, {
foo: 'bar',
typeofProcess: 'undefined',
});
assert.strictEqual(result, 'function');
// Test 2: vm.runInContext
var sandbox2 = { foo: 'bar' };
var context = vm.createContext(sandbox2);
var result = vm.runInContext(
'baz = foo; this.typeofProcess = typeof process; typeof Object;',
context
);
assert.deepEqual(sandbox2, {
foo: 'bar',
baz: 'bar',
typeofProcess: 'undefined'
});
assert.strictEqual(result, 'function');
// Test 3: vm.runInThisContext
var result = vm.runInThisContext(
'vmResult = "foo"; Object.prototype.toString.call(process);'
);
assert.strictEqual(global.vmResult, 'foo');
assert.strictEqual(result, '[object process]');
delete global.vmResult;
// Test 4: vm.runInNewContext
var result = vm.runInNewContext(
'vmResult = "foo"; typeof process;'
);
assert.strictEqual(global.vmResult, undefined);
assert.strictEqual(result, 'undefined');
// Test 5: vm.createContext
var sandbox3 = {};
var context2 = vm.createContext(sandbox3);
assert.strictEqual(sandbox3, context2);