evaluate-without-side-effects.js 1.95 KB
Newer Older
1 2 3 4 5 6
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

let {session, contextGroup, Protocol} = InspectorTest.start("Tests that Runtime.evaluate can run without side effects.");

7 8 9 10 11
session.setupScriptMap();
contextGroup.addScript(`
    function f() {
      return 2;
    } //# sourceURL=test.js`);
12 13
Protocol.Runtime.enable();
Protocol.Debugger.enable();
14 15 16 17 18 19

Protocol.Debugger.onPaused(message => {
  InspectorTest.log("paused");
  Protocol.Debugger.resume();
});

20 21 22 23 24 25 26
(async function() {
  InspectorTest.log("Test throwOnSideEffect: false");
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "var x = 2; x;",
    throwOnSideEffect: false
  }));

27 28 29 30 31 32
  InspectorTest.log("Test prototype extension expression with side-effect, with throwOnSideEffect: true");
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "f.prototype.test = () => console.log('test fn');",
    throwOnSideEffect: true
  }));

33 34 35 36 37 38 39 40 41 42 43 44
  InspectorTest.log("Test expression with side-effect, with throwOnSideEffect: true");
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "x = 3; x;",
    throwOnSideEffect: true
  }));

  InspectorTest.log("Test expression without side-effect, with throwOnSideEffect: true");
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "x * 2",
    throwOnSideEffect: true
  }));

45 46 47 48 49 50 51 52 53 54 55 56 57
  InspectorTest.log("Test that debug break triggers without throwOnSideEffect");
  await Protocol.Debugger.setBreakpointByUrl({ url: 'test.js', lineNumber: 2 });
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "f()",
    throwOnSideEffect: false
  }));

  InspectorTest.log("Test that debug break does not trigger with throwOnSideEffect");
  InspectorTest.logMessage(await Protocol.Runtime.evaluate({
    expression: "f()",
    throwOnSideEffect: true
  }));

58 59
  InspectorTest.completeTest();
})();