Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7a12dd5

Browse filesBrowse files
Renegade334aduh95
authored andcommitted
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: #62571 Refs: #62371 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 3f42f96 commit 7a12dd5
Copy full SHA for 7a12dd5

1 file changed

+19Lines changed: 19 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+19Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.