forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: properly handle defining props on any value
While it was supposed to fix most of the remaining issues, nodejs#46458 missed some in strict mode. This PR adds some additional checks. It also clarifies what we are really checking to execute or not the `GetReturnValue`.
- Loading branch information
Showing
4 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable strict, no-var, no-delete-var, node-core/required-modules, node-core/require-common-first */ | ||
// While common, should be used as first require of the test, using it causes errors: Unexpected global(s) found: data, b. | ||
// Actually in this specific test case calling vm.runInThisContext exposes variables outside of the vm (behaviour existing since at least v14). | ||
// The other rules (strict, no-var, no-delete-var) have been disabled to test this specific not strict case. | ||
// Related to bug report: https://github.com/nodejs/node/issues/43129 | ||
var assert = require('assert'); | ||
var vm = require('vm'); | ||
|
||
var data = []; | ||
var a = 'direct'; | ||
delete a; | ||
data.push(a); | ||
|
||
var item2 = vm.runInThisContext(` | ||
var unusedB = 1; | ||
var data = []; | ||
var b = "this"; | ||
delete b; | ||
data.push(b); | ||
data[0] | ||
`); | ||
data.push(item2); | ||
|
||
vm.runInContext( | ||
` | ||
var unusedC = 1; | ||
var c = "new"; | ||
delete c; | ||
data.push(c); | ||
`, | ||
vm.createContext({ data: data }) | ||
); | ||
|
||
assert.deepStrictEqual(data, ['direct', 'this', 'new']); | ||
|
||
// While the variables have been declared in the vm context, they are accessible in the global one too. | ||
// This behaviour has been there at least from v14 of node, and still exist in 16 and 18. | ||
assert.equal(typeof unusedB, 'number'); | ||
assert.equal(typeof unusedC, 'number'); |