11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { NodeInstance } = require('../common/inspector-helper.js'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_cifunction mainContextDestroyed(notification) { 101cb0ef41Sopenharmony_ci return notification.method === 'Runtime.executionContextDestroyed' && 111cb0ef41Sopenharmony_ci notification.params.executionContextId === 1; 121cb0ef41Sopenharmony_ci} 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciasync function runTest() { 151cb0ef41Sopenharmony_ci const child = new NodeInstance(['--inspect-brk=0', '-e', 'process.exit(55)']); 161cb0ef41Sopenharmony_ci const session = await child.connectInspectorSession(); 171cb0ef41Sopenharmony_ci const oldStyleSession = await child.connectInspectorSession(); 181cb0ef41Sopenharmony_ci await oldStyleSession.send([ 191cb0ef41Sopenharmony_ci { method: 'Runtime.enable' }]); 201cb0ef41Sopenharmony_ci await session.send([ 211cb0ef41Sopenharmony_ci { method: 'Runtime.enable' }, 221cb0ef41Sopenharmony_ci { method: 'NodeRuntime.notifyWhenWaitingForDisconnect', 231cb0ef41Sopenharmony_ci params: { enabled: true } }, 241cb0ef41Sopenharmony_ci { method: 'Runtime.runIfWaitingForDebugger' }]); 251cb0ef41Sopenharmony_ci await session.waitForNotification((notification) => { 261cb0ef41Sopenharmony_ci return notification.method === 'NodeRuntime.waitingForDisconnect'; 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci const receivedExecutionContextDestroyed = 291cb0ef41Sopenharmony_ci session.unprocessedNotifications().some(mainContextDestroyed); 301cb0ef41Sopenharmony_ci if (receivedExecutionContextDestroyed) { 311cb0ef41Sopenharmony_ci assert.fail('When NodeRuntime enabled, ' + 321cb0ef41Sopenharmony_ci 'Runtime.executionContextDestroyed should not be sent'); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci const { result: { value } } = await session.send({ 351cb0ef41Sopenharmony_ci method: 'Runtime.evaluate', params: { expression: '42' } 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci assert.strictEqual(value, 42); 381cb0ef41Sopenharmony_ci await session.disconnect(); 391cb0ef41Sopenharmony_ci await oldStyleSession.waitForNotification(mainContextDestroyed); 401cb0ef41Sopenharmony_ci await oldStyleSession.disconnect(); 411cb0ef41Sopenharmony_ci assert.strictEqual((await child.expectShutdown()).exitCode, 55); 421cb0ef41Sopenharmony_ci} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_cirunTest().then(common.mustCall()); 45