diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-05-01 23:22:47 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-05-14 01:34:32 +0200 |
commit | 815b3aa8332479a99f06327d76492b887b1b1edf (patch) | |
tree | 4b015a94a6a4e191cdd0c0492b4367bf470a9f0b /test | |
parent | ddbaddcce108855f517308f7bd5d910379b59a3b (diff) | |
download | android-node-v8-815b3aa8332479a99f06327d76492b887b1b1edf.tar.gz android-node-v8-815b3aa8332479a99f06327d76492b887b1b1edf.tar.bz2 android-node-v8-815b3aa8332479a99f06327d76492b887b1b1edf.zip |
vm: mark global proxy as side-effect-free
Fixes: https://github.com/nodejs/node/issues/27518
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js | 33 | ||||
-rw-r--r-- | test/parallel/test-inspector-vm-global-accessors-sideeffects.js | 31 |
2 files changed, 64 insertions, 0 deletions
diff --git a/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js new file mode 100644 index 0000000000..5dc9c9bb2d --- /dev/null +++ b/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js @@ -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. +}); diff --git a/test/parallel/test-inspector-vm-global-accessors-sideeffects.js b/test/parallel/test-inspector-vm-global-accessors-sideeffects.js new file mode 100644 index 0000000000..31551a08cb --- /dev/null +++ b/test/parallel/test-inspector-vm-global-accessors-sideeffects.js @@ -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' + } + }); +}); |