Sha256: 1973908109514607854178217de6dff183f446f3d9852347468c007573876577

Contents?: true

Size: 837 Bytes

Versions: 5

Compression:

Stored size: 837 Bytes

Contents

'use strict';
require('../common');
const assert = require('assert');
const vm = require('vm');
const ctx = vm.createContext();

// Test strict mode inside a vm script, i.e., using an undefined variable
// throws a ReferenceError. Also check that variables
// that are not successfully set in the vm, must not be set
// on the sandboxed context.

vm.runInContext('w = 1;', ctx);
assert.strictEqual(1, ctx.w);

assert.throws(function() { vm.runInContext('"use strict"; x = 1;', ctx); },
              /ReferenceError: x is not defined/);
assert.strictEqual(undefined, ctx.x);

vm.runInContext('"use strict"; var y = 1;', ctx);
assert.strictEqual(1, ctx.y);

vm.runInContext('"use strict"; this.z = 1;', ctx);
assert.strictEqual(1, ctx.z);

// w has been defined
vm.runInContext('"use strict"; w = 2;', ctx);
assert.strictEqual(2, ctx.w);

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-vm-strict-mode.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-vm-strict-mode.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-vm-strict-mode.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-vm-strict-mode.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-vm-strict-mode.js