-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm: mark global proxy as side-effect-free
Fixes: #27518 PR-URL: #27523 Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
3 changed files
with
76 additions
and
8 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
33 changes: 33 additions & 0 deletions
33
test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js
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,33 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
|
||
// Test that if there is a side effect in a getter invoked through the vm | ||
// global proxy, Runtime.evaluate recognizes that. | ||
|
||
const assert = require('assert'); | ||
const inspector = require('inspector'); | ||
const vm = require('vm'); | ||
|
||
const session = new inspector.Session(); | ||
session.connect(); | ||
|
||
const context = vm.createContext({ | ||
get a() { | ||
global.foo = '1'; | ||
return 100; | ||
} | ||
}); | ||
|
||
session.post('Runtime.evaluate', { | ||
expression: 'a', | ||
throwOnSideEffect: true, | ||
contextId: 2 // context's id | ||
}, (error, res) => { | ||
assert.ifError(error); | ||
const { exception } = res.exceptionDetails; | ||
assert.strictEqual(exception.className, 'EvalError'); | ||
assert(/Possible side-effect/.test(exception.description)); | ||
|
||
assert(context); // Keep 'context' alive and make linter happy. | ||
}); |
31 changes: 31 additions & 0 deletions
31
test/parallel/test-inspector-vm-global-accessors-sideeffects.js
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,31 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/27518. | ||
|
||
const assert = require('assert'); | ||
const inspector = require('inspector'); | ||
const vm = require('vm'); | ||
|
||
const session = new inspector.Session(); | ||
session.connect(); | ||
|
||
const context = vm.createContext({ | ||
a: 100 | ||
}); | ||
|
||
session.post('Runtime.evaluate', { | ||
expression: 'a', | ||
throwOnSideEffect: true, | ||
contextId: 2 // context's id | ||
}, (error, res) => { | ||
assert.ifError(error), | ||
assert.deepStrictEqual(res, { | ||
result: { | ||
type: 'number', | ||
value: context.a, | ||
description: '100' | ||
} | ||
}); | ||
}); |