|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const vm = require('vm'); |
| 6 | + |
| 7 | +const ctx = vm.createContext({ x: 0 }); |
| 8 | + |
| 9 | +// Global properties should be intercepted in strict mode |
| 10 | +vm.runInContext('"use strict"; x = 42', ctx); |
| 11 | +assert.strictEqual(ctx.x, 42); |
| 12 | + |
| 13 | +// Contextual store should only be intercepted in non-strict mode |
| 14 | +vm.runInContext('y = 42', ctx); |
| 15 | +assert.strictEqual(ctx.y, 42); |
| 16 | + |
| 17 | +assert.throws(() => vm.runInContext('"use strict"; z = 42', ctx), |
| 18 | +/ReferenceError: z is not defined/); |
| 19 | +assert.strictEqual(Object.hasOwn(ctx, 'z'), false); |