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