node/deps/v8/test/inspector/debugger/promise-chain-when-limit-hit.js
Michaël Zasso 4c4af643e5
deps: update V8 to 6.4.388.40
PR-URL: https://github.com/nodejs/node/pull/17489
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
2018-01-24 15:02:20 -08:00

58 lines
2.1 KiB
JavaScript

// 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 asyncCall = `(function asyncCall(num) {
if (num === 0) {
${source};
return;
}
Promise.resolve().then(() => asyncCall(num - 1));
})(${len})`;
Protocol.Runtime.evaluate({expression: asyncCall});
}
async function setMaxAsyncTaskStacks(max) {
let expression = `inspector.setMaxAsyncTaskStacks(${max})`;
InspectorTest.log(expression);
await Protocol.Runtime.evaluate({expression});
}