summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/runtime/terminate-execution.js
blob: feaf52eb2c1915df65cc714a096f28938502a0f9 (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
// 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();

  await Protocol.Runtime.disable();
  InspectorTest.completeTest();
})();