mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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. PR-URL: https://github.com/nodejs/node/pull/62571 Refs: https://github.com/nodejs/node/pull/62371 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
1 file changed
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const vm = require('vm');
|
||||
|
||||
const ctx = vm.createContext({ x: 0 });
|
||||
|
||||
// Global properties should be intercepted in strict mode
|
||||
vm.runInContext('"use strict"; x = 42', ctx);
|
||||
assert.strictEqual(ctx.x, 42);
|
||||
|
||||
// Contextual store should only be intercepted in non-strict mode
|
||||
vm.runInContext('y = 42', ctx);
|
||||
assert.strictEqual(ctx.y, 42);
|
||||
|
||||
assert.throws(() => vm.runInContext('"use strict"; z = 42', ctx),
|
||||
/ReferenceError: z is not defined/);
|
||||
assert.strictEqual(Object.hasOwn(ctx, 'z'), false);
|
||||
Reference in new issue
Block a user