11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
41cb0ef41Sopenharmony_cicommon.skipIf32Bits();
51cb0ef41Sopenharmony_ciconst { NodeInstance } = require('../common/inspector-helper');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst script = 'setInterval(() => { debugger; }, 50);';
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciasync function skipFirstBreakpoint(session) {
111cb0ef41Sopenharmony_ci  console.log('[test]', 'Skipping the first breakpoint in the eval script');
121cb0ef41Sopenharmony_ci  await session.waitForBreakOnLine(0, '[eval]');
131cb0ef41Sopenharmony_ci  await session.send({ 'method': 'Debugger.resume' });
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciasync function checkAsyncStackTrace(session) {
171cb0ef41Sopenharmony_ci  console.error('[test]', 'Verify basic properties of asyncStackTrace');
181cb0ef41Sopenharmony_ci  const paused = await session.waitForBreakOnLine(0, '[eval]');
191cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace,
201cb0ef41Sopenharmony_ci         `${Object.keys(paused.params)} contains "asyncStackTrace" property`);
211cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace.description, 'Timeout');
221cb0ef41Sopenharmony_ci  assert(paused.params.asyncStackTrace.callFrames
231cb0ef41Sopenharmony_ci           .some((frame) => frame.url === 'node:internal/process/execution'));
241cb0ef41Sopenharmony_ci}
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciasync function runTests() {
271cb0ef41Sopenharmony_ci  const instance = new NodeInstance(undefined, script);
281cb0ef41Sopenharmony_ci  const session = await instance.connectInspectorSession();
291cb0ef41Sopenharmony_ci  await session.send([
301cb0ef41Sopenharmony_ci    { 'method': 'Runtime.enable' },
311cb0ef41Sopenharmony_ci    { 'method': 'Debugger.enable' },
321cb0ef41Sopenharmony_ci    { 'method': 'Debugger.setAsyncCallStackDepth',
331cb0ef41Sopenharmony_ci      'params': { 'maxDepth': 10 } },
341cb0ef41Sopenharmony_ci    { 'method': 'Debugger.setBlackboxPatterns',
351cb0ef41Sopenharmony_ci      'params': { 'patterns': [] } },
361cb0ef41Sopenharmony_ci    { 'method': 'Runtime.runIfWaitingForDebugger' },
371cb0ef41Sopenharmony_ci  ]);
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci  await skipFirstBreakpoint(session);
401cb0ef41Sopenharmony_ci  await checkAsyncStackTrace(session);
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci  console.error('[test]', 'Stopping child instance');
431cb0ef41Sopenharmony_ci  session.disconnect();
441cb0ef41Sopenharmony_ci  instance.kill();
451cb0ef41Sopenharmony_ci}
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_cirunTests().then(common.mustCall());
48