From 0913a153b4586ab46a25dfa2a4dd34566aac0262 Mon Sep 17 00:00:00 2001 From: Renegade334 Date: Fri, 3 Apr 2026 10:32:33 +0100 Subject: [PATCH] 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. --- .../test-vm-global-contextual-store.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/parallel/test-vm-global-contextual-store.js diff --git a/test/parallel/test-vm-global-contextual-store.js b/test/parallel/test-vm-global-contextual-store.js new file mode 100644 index 00000000000000..1ae74adb541b58 --- /dev/null +++ b/test/parallel/test-vm-global-contextual-store.js @@ -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);