-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: do not copy on failing setProperty()
In vm, the setter interceptor should not copy a value onto the sandbox, if setting it on the global object will fail. It will fail if we are in strict mode and set a value without declaring it. Fixes: #5344 PR-URL: #7908 Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
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); | ||
|
||
vm.runInContext('"use strict"; this.z = 1;', ctx); | ||
assert.strictEqual(1, ctx.z); | ||
|
||
// w has been defined | ||
vm.runInContext('"use strict"; w = 2;', ctx); | ||
assert.strictEqual(2, ctx.w); |