11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { Session } = require('inspector'); 91cb0ef41Sopenharmony_ciconst path = require('path'); 101cb0ef41Sopenharmony_ciconst { pathToFileURL } = require('url'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifunction debugged() { 131cb0ef41Sopenharmony_ci return 42; 141cb0ef41Sopenharmony_ci} 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciasync function test() { 171cb0ef41Sopenharmony_ci const session1 = new Session(); 181cb0ef41Sopenharmony_ci const session2 = new Session(); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci session1.connect(); 211cb0ef41Sopenharmony_ci session2.connect(); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci let session1Paused = false; 241cb0ef41Sopenharmony_ci let session2Paused = false; 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci session1.on('Debugger.paused', () => session1Paused = true); 271cb0ef41Sopenharmony_ci session2.on('Debugger.paused', () => session2Paused = true); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci console.log('Connected'); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci session1.post('Debugger.enable'); 321cb0ef41Sopenharmony_ci session2.post('Debugger.enable'); 331cb0ef41Sopenharmony_ci console.log('Debugger was enabled'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci await new Promise((resolve, reject) => { 361cb0ef41Sopenharmony_ci session1.post('Debugger.setBreakpointByUrl', { 371cb0ef41Sopenharmony_ci 'lineNumber': 12, 381cb0ef41Sopenharmony_ci 'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(), 391cb0ef41Sopenharmony_ci 'columnNumber': 0, 401cb0ef41Sopenharmony_ci 'condition': '' 411cb0ef41Sopenharmony_ci }, (error, result) => { 421cb0ef41Sopenharmony_ci return error ? reject(error) : resolve(result); 431cb0ef41Sopenharmony_ci }); 441cb0ef41Sopenharmony_ci }); 451cb0ef41Sopenharmony_ci console.log('Breakpoint was set'); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci debugged(); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci // Both sessions will receive the paused event 501cb0ef41Sopenharmony_ci assert(session1Paused); 511cb0ef41Sopenharmony_ci assert(session2Paused); 521cb0ef41Sopenharmony_ci console.log('Breakpoint was hit'); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci session1.disconnect(); 551cb0ef41Sopenharmony_ci session2.disconnect(); 561cb0ef41Sopenharmony_ci console.log('Sessions were disconnected'); 571cb0ef41Sopenharmony_ci} 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ciconst interval = setInterval(() => {}, 1000); 601cb0ef41Sopenharmony_citest().then(common.mustCall(() => { 611cb0ef41Sopenharmony_ci clearInterval(interval); 621cb0ef41Sopenharmony_ci console.log('Done!'); 631cb0ef41Sopenharmony_ci})); 64