11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks'); 91cb0ef41Sopenharmony_ciconst call_log = [0, 0, 0, 0]; // [before, callback, exception, after]; 101cb0ef41Sopenharmony_cilet call_id = null; 111cb0ef41Sopenharmony_cilet hooks = null; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciprocess.on('beforeExit', common.mustCall(() => { 151cb0ef41Sopenharmony_ci process.removeAllListeners('uncaughtException'); 161cb0ef41Sopenharmony_ci hooks.disable(); 171cb0ef41Sopenharmony_ci assert.strictEqual(typeof call_id, 'number'); 181cb0ef41Sopenharmony_ci assert.deepStrictEqual(call_log, [1, 1, 1, 1]); 191cb0ef41Sopenharmony_ci})); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_cihooks = async_hooks.createHook({ 231cb0ef41Sopenharmony_ci init(id, type) { 241cb0ef41Sopenharmony_ci if (type === 'RANDOMBYTESREQUEST') 251cb0ef41Sopenharmony_ci call_id = id; 261cb0ef41Sopenharmony_ci }, 271cb0ef41Sopenharmony_ci before(id) { 281cb0ef41Sopenharmony_ci if (id === call_id) call_log[0]++; 291cb0ef41Sopenharmony_ci }, 301cb0ef41Sopenharmony_ci after(id) { 311cb0ef41Sopenharmony_ci if (id === call_id) call_log[3]++; 321cb0ef41Sopenharmony_ci }, 331cb0ef41Sopenharmony_ci}).enable(); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustCall(() => { 371cb0ef41Sopenharmony_ci assert.strictEqual(call_id, async_hooks.executionAsyncId()); 381cb0ef41Sopenharmony_ci call_log[2]++; 391cb0ef41Sopenharmony_ci})); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_cirequire('crypto').randomBytes(1, common.mustCall(() => { 431cb0ef41Sopenharmony_ci assert.strictEqual(call_id, async_hooks.executionAsyncId()); 441cb0ef41Sopenharmony_ci call_log[1]++; 451cb0ef41Sopenharmony_ci throw new Error(); 461cb0ef41Sopenharmony_ci})); 47