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_ci
111cb0ef41Sopenharmony_ciconst cli = startCLI(['--port=0', fixtures.path('debugger/alive.js')]);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciasync function waitInitialBreak() {
141cb0ef41Sopenharmony_ci  try {
151cb0ef41Sopenharmony_ci    await cli.waitForInitialBreak();
161cb0ef41Sopenharmony_ci    await cli.waitForPrompt();
171cb0ef41Sopenharmony_ci    await cli.command('exec [typeof heartbeat, typeof process.exit]');
181cb0ef41Sopenharmony_ci    assert.match(cli.output, /\[ 'function', 'function' \]/, 'works w/o paren');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci    await cli.command('p [typeof heartbeat, typeof process.exit]');
211cb0ef41Sopenharmony_ci    assert.match(
221cb0ef41Sopenharmony_ci      cli.output,
231cb0ef41Sopenharmony_ci      /\[ 'function', 'function' \]/,
241cb0ef41Sopenharmony_ci      'works w/o paren, short'
251cb0ef41Sopenharmony_ci    );
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci    await cli.command('repl');
281cb0ef41Sopenharmony_ci    assert.match(
291cb0ef41Sopenharmony_ci      cli.output,
301cb0ef41Sopenharmony_ci      /Press Ctrl\+C to leave debug repl\n+> /,
311cb0ef41Sopenharmony_ci      'shows hint for how to leave repl'
321cb0ef41Sopenharmony_ci    );
331cb0ef41Sopenharmony_ci    assert.doesNotMatch(cli.output, /debug>/, 'changes the repl style');
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci    await cli.command('[typeof heartbeat, typeof process.exit]');
361cb0ef41Sopenharmony_ci    await cli.waitFor(/function/);
371cb0ef41Sopenharmony_ci    await cli.waitForPrompt();
381cb0ef41Sopenharmony_ci    assert.match(
391cb0ef41Sopenharmony_ci      cli.output,
401cb0ef41Sopenharmony_ci      /\[ 'function', 'function' \]/,
411cb0ef41Sopenharmony_ci      'can evaluate in the repl'
421cb0ef41Sopenharmony_ci    );
431cb0ef41Sopenharmony_ci    assert.match(cli.output, /> $/);
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci    await cli.ctrlC();
461cb0ef41Sopenharmony_ci    await cli.waitFor(/debug> $/);
471cb0ef41Sopenharmony_ci    await cli.command('exec("[typeof heartbeat, typeof process.exit]")');
481cb0ef41Sopenharmony_ci    assert.match(cli.output, /\[ 'function', 'function' \]/, 'works w/ paren');
491cb0ef41Sopenharmony_ci    await cli.command('p("[typeof heartbeat, typeof process.exit]")');
501cb0ef41Sopenharmony_ci    assert.match(
511cb0ef41Sopenharmony_ci      cli.output,
521cb0ef41Sopenharmony_ci      /\[ 'function', 'function' \]/,
531cb0ef41Sopenharmony_ci      'works w/ paren, short'
541cb0ef41Sopenharmony_ci    );
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci    await cli.command('cont');
571cb0ef41Sopenharmony_ci    await cli.command('exec [typeof heartbeat, typeof process.exit]');
581cb0ef41Sopenharmony_ci    assert.match(
591cb0ef41Sopenharmony_ci      cli.output,
601cb0ef41Sopenharmony_ci      /\[ 'undefined', 'function' \]/,
611cb0ef41Sopenharmony_ci      'non-paused exec can see global but not module-scope values'
621cb0ef41Sopenharmony_ci    );
631cb0ef41Sopenharmony_ci  } finally {
641cb0ef41Sopenharmony_ci    await cli.quit();
651cb0ef41Sopenharmony_ci  }
661cb0ef41Sopenharmony_ci}
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ciwaitInitialBreak();
69