11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst childProcess = require('child_process'); 51cb0ef41Sopenharmony_ciconst os = require('os'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 81cb0ef41Sopenharmony_ci child(process.argv[3], process.argv[4]); 91cb0ef41Sopenharmony_ci} else { 101cb0ef41Sopenharmony_ci main(); 111cb0ef41Sopenharmony_ci} 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction child(type, valueType) { 141cb0ef41Sopenharmony_ci const { createHook } = require('async_hooks'); 151cb0ef41Sopenharmony_ci const fs = require('fs'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci createHook({ 181cb0ef41Sopenharmony_ci [type]() { 191cb0ef41Sopenharmony_ci if (valueType === 'symbol') { 201cb0ef41Sopenharmony_ci throw Symbol('foo'); 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci // eslint-disable-next-line no-throw-literal 231cb0ef41Sopenharmony_ci throw null; 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci }).enable(); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci // Trigger `promiseResolve`. 281cb0ef41Sopenharmony_ci new Promise((resolve) => resolve()) 291cb0ef41Sopenharmony_ci // Trigger `after`/`destroy`. 301cb0ef41Sopenharmony_ci .then(() => fs.promises.readFile(__filename, 'utf8')) 311cb0ef41Sopenharmony_ci // Make process exit with code 0 if no error caught. 321cb0ef41Sopenharmony_ci .then(() => process.exit(0)); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cifunction main() { 361cb0ef41Sopenharmony_ci const types = [ 'init', 'before', 'after', 'destroy', 'promiseResolve' ]; 371cb0ef41Sopenharmony_ci const valueTypes = [ 381cb0ef41Sopenharmony_ci [ 'null', 'Error: null' ], 391cb0ef41Sopenharmony_ci [ 'symbol', 'Error: Symbol(foo)' ], 401cb0ef41Sopenharmony_ci ]; 411cb0ef41Sopenharmony_ci for (const type of types) { 421cb0ef41Sopenharmony_ci for (const [valueType, expect] of valueTypes) { 431cb0ef41Sopenharmony_ci const cp = childProcess.spawnSync( 441cb0ef41Sopenharmony_ci process.execPath, 451cb0ef41Sopenharmony_ci [ __filename, 'child', type, valueType ], 461cb0ef41Sopenharmony_ci { 471cb0ef41Sopenharmony_ci encoding: 'utf8', 481cb0ef41Sopenharmony_ci }); 491cb0ef41Sopenharmony_ci assert.strictEqual(cp.status, 1, type); 501cb0ef41Sopenharmony_ci assert.strictEqual(cp.stderr.trim().split(os.EOL)[0], expect, type); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci} 54