node/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js
Michaël Zasso 508890d795
test: use assert.match instead of regexp.test
PR-URL: https://github.com/nodejs/node/pull/39928
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
2021-08-31 18:50:16 +02:00

34 lines
863 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.match(exception.description, /Possible side-effect/);
assert(context); // Keep 'context' alive and make linter happy.
});