summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/promise-chain-when-limit-hit.js
blob: 072af732c49026225d9b288685dc661127ba5b29 (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
// Copyright 2017 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.

// TODO(kozyatinskiy): fix or remove it later.
let {session, contextGroup, Protocol} = InspectorTest.start('Tests how async promise chains behave when reaching the limit of stacks');

(async function test(){
  InspectorTest.log('Checks correctness of promise chains when limit hit');
  await Protocol.Runtime.enable();
  await Protocol.Debugger.enable();
  Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128});

  await setMaxAsyncTaskStacks(3);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  await setMaxAsyncTaskStacks(4);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  await setMaxAsyncTaskStacks(5);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  await setMaxAsyncTaskStacks(6);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  await setMaxAsyncTaskStacks(7);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  await setMaxAsyncTaskStacks(8);
  runWithAsyncChainPromise(3, 'console.trace()');
  InspectorTest.logMessage(await Protocol.Runtime.onceConsoleAPICalled());

  InspectorTest.completeTest();
})();

function runWithAsyncChainPromise(len, source) {
  InspectorTest.log(`Run expression '${source}' with async chain len: ${len}`);
  let then = '.then(() => 1)';
  let pause = `.then(() => { ${source} })`;
  Protocol.Runtime.evaluate({
    expression: `Promise.resolve()${then.repeat(len - 1)}${pause}`
  });
}

async function setMaxAsyncTaskStacks(max) {
  let expression = `inspector.setMaxAsyncTaskStacks(${max})`;
  InspectorTest.log(expression);
  await Protocol.Runtime.evaluate({expression});
}