node/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js
James M Snell 97a3a8204c test: replace more uses of global with globalThis
PR-URL: https://github.com/nodejs/node/pull/56712
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2025-01-25 07:23:11 +00:00

34 lines
867 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() {
globalThis.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.
});