◐ Shell
clean mode source ↗

test: check contextify contextual store behavior in strict mode · nodejs/node@c22d341

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,19 @@

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);