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>
19 lines
574 B
JavaScript
19 lines
574 B
JavaScript
'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);
|