Skip to content

Commit 0913a15

Browse files
committed
test: check contextify contextual store behavior in strict mode
Previously, this behavior was tested indirectly by the REPL tests. However, REPL now uses DONT_CONTEXTIFY for its VM context.
1 parent b411f90 commit 0913a15

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
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);

0 commit comments

Comments
 (0)