summaryrefslogtreecommitdiff
path: root/test/parallel/test-inspector-vm-global-accessors-getter-sideeffect.js
blob: 5dc9c9bb2dff3a2788cb0052155da9586cbeea75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.
});