-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch fixes the problem with variables that are declared only on the sandbox but not on the global proxy. PR-URL: #16487 Fixes: #12300 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
3 changed files
with
27 additions
and
41 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,27 +1,14 @@ | ||
'use strict'; | ||
// https://github.com/nodejs/node/issues/12300 | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const vm = require('vm'); | ||
const ctx = vm.createContext(); | ||
|
||
// Test strict mode inside a vm script, i.e., using an undefined variable | ||
// throws a ReferenceError. Also check that variables | ||
// that are not successfully set in the vm, must not be set | ||
// on the sandboxed context. | ||
|
||
vm.runInContext('w = 1;', ctx); | ||
assert.strictEqual(1, ctx.w); | ||
|
||
assert.throws(function() { vm.runInContext('"use strict"; x = 1;', ctx); }, | ||
/ReferenceError: x is not defined/); | ||
assert.strictEqual(undefined, ctx.x); | ||
|
||
vm.runInContext('"use strict"; var y = 1;', ctx); | ||
assert.strictEqual(1, ctx.y); | ||
const ctx = vm.createContext({ x: 42 }); | ||
|
||
vm.runInContext('"use strict"; this.z = 1;', ctx); | ||
assert.strictEqual(1, ctx.z); | ||
// This might look as if x has not been declared, but x is defined on the | ||
// sandbox and the assignment should not throw. | ||
vm.runInContext('"use strict"; x = 1', ctx); | ||
|
||
// w has been defined | ||
vm.runInContext('"use strict"; w = 2;', ctx); | ||
assert.strictEqual(2, ctx.w); | ||
assert.strictEqual(ctx.x, 1); |