summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/terminate-execution.js
blob: 3fd6b60242c7d62cc86922df68073efb833534b0 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// 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 Runtime.terminateExecution');

(async function test() {
  Protocol.Runtime.enable();
  Protocol.Runtime.onConsoleAPICalled(
      message => InspectorTest.logMessage(message.params.args[0]));
  InspectorTest.log(
      'Terminate first evaluation (it forces injected-script-source compilation)');
  await Promise.all([
    Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
    Protocol.Runtime.evaluate({expression: 'console.log(42)'})
        .then(InspectorTest.logMessage)
  ]);

  InspectorTest.log('Checks that we reset termination after evaluation');
  InspectorTest.logMessage(
      await Protocol.Runtime.evaluate({expression: 'console.log(42)'}));
  InspectorTest.log(
      'Terminate evaluation when injected-script-source already compiled');
  await Promise.all([
    Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
    Protocol.Runtime.evaluate({expression: 'console.log(42)'})
        .then(InspectorTest.logMessage)
  ]);

  InspectorTest.log('Terminate script evaluated with v8 API');
  const terminated =
      Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage);
  contextGroup.addScript('console.log(42)');
  await terminated;

  InspectorTest.log('Terminate chained callback');
  Protocol.Debugger.enable();
  const paused = Protocol.Debugger.oncePaused();
  await Protocol.Runtime.evaluate({
    expression: `let p = new Promise(resolve => setTimeout(resolve, 0));
    p.then(() => {
        while(true){ debugger; }
      }).then(() => console.log('chained after chained callback'));
    p.then(() => { console.log('another chained callback'); });
    undefined`
  });
  await paused;

  InspectorTest.log('Pause inside microtask and terminate execution');
  Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage);
  await Protocol.Debugger.resume();
  await Protocol.Runtime
      .evaluate({expression: `console.log('separate eval after while(true)')`})
      .then(InspectorTest.logMessage);
  await Protocol.Debugger.disable();

  InspectorTest.log('Terminate execution with pending microtasks');
  Protocol.Debugger.enable();
  const paused2 = Protocol.Debugger.oncePaused();
  Protocol.Runtime.evaluate({expression: `
      Promise.resolve().then(() => { console.log('FAIL: microtask ran'); });
      debugger;
      for (;;) {}
  `});
  await paused2;
  Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage);
  await Protocol.Debugger.resume();
  await Protocol.Runtime.disable();

  InspectorTest.log('Terminate execution does not crash on destroy');
  Protocol.Debugger.enable();
  Protocol.Runtime.evaluate({
    expression: `
    while(true) {
      let p = new Promise(resolve => setTimeout(resolve, 0));
      await p;
    }`
  });
  Protocol.Runtime.terminateExecution();
  await Protocol.Debugger.disable();

  InspectorTest.completeTest();
})();