11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled();
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
71cb0ef41Sopenharmony_ciconst startCLI = require('../common/debugger');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ciconst path = require('path');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Break on (uncaught) exceptions.
131cb0ef41Sopenharmony_ci{
141cb0ef41Sopenharmony_ci  const scriptFullPath = fixtures.path('debugger', 'exceptions.js');
151cb0ef41Sopenharmony_ci  const script = path.relative(process.cwd(), scriptFullPath);
161cb0ef41Sopenharmony_ci  const cli = startCLI(['--port=0', script]);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  (async () => {
191cb0ef41Sopenharmony_ci    try {
201cb0ef41Sopenharmony_ci      await cli.waitForInitialBreak();
211cb0ef41Sopenharmony_ci      await cli.waitForPrompt();
221cb0ef41Sopenharmony_ci      await cli.waitForPrompt();
231cb0ef41Sopenharmony_ci      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci      // Making sure it will die by default:
261cb0ef41Sopenharmony_ci      await cli.command('c');
271cb0ef41Sopenharmony_ci      await cli.waitFor(/disconnect/);
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci      // Next run: With `breakOnException` it pauses in both places.
301cb0ef41Sopenharmony_ci      await cli.stepCommand('r');
311cb0ef41Sopenharmony_ci      await cli.waitForInitialBreak();
321cb0ef41Sopenharmony_ci      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
331cb0ef41Sopenharmony_ci      await cli.command('breakOnException');
341cb0ef41Sopenharmony_ci      await cli.stepCommand('c');
351cb0ef41Sopenharmony_ci      assert.ok(cli.output.includes(`exception in ${script}:3`));
361cb0ef41Sopenharmony_ci      await cli.stepCommand('c');
371cb0ef41Sopenharmony_ci      assert.ok(cli.output.includes(`exception in ${script}:9`));
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci      // Next run: With `breakOnUncaught` it only pauses on the 2nd exception.
401cb0ef41Sopenharmony_ci      await cli.command('breakOnUncaught');
411cb0ef41Sopenharmony_ci      await cli.stepCommand('r'); // Also, the setting survives the restart.
421cb0ef41Sopenharmony_ci      await cli.waitForInitialBreak();
431cb0ef41Sopenharmony_ci      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
441cb0ef41Sopenharmony_ci      await cli.stepCommand('c');
451cb0ef41Sopenharmony_ci      assert.ok(cli.output.includes(`exception in ${script}:9`));
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci      // Next run: Back to the initial state! It should die again.
481cb0ef41Sopenharmony_ci      await cli.command('breakOnNone');
491cb0ef41Sopenharmony_ci      await cli.stepCommand('r');
501cb0ef41Sopenharmony_ci      await cli.waitForInitialBreak();
511cb0ef41Sopenharmony_ci      assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 });
521cb0ef41Sopenharmony_ci      await cli.command('c');
531cb0ef41Sopenharmony_ci      await cli.waitFor(/disconnect/);
541cb0ef41Sopenharmony_ci    } finally {
551cb0ef41Sopenharmony_ci      cli.quit();
561cb0ef41Sopenharmony_ci    }
571cb0ef41Sopenharmony_ci  })().then(common.mustCall());
581cb0ef41Sopenharmony_ci}
59