node/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js
Anna Henningsen 815b3aa833
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>
2019-05-14 01:34:32 +02:00

34 lines
862 B
JavaScript

'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.
});