11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst domain = require('domain'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// Make sure that when an error is thrown from a nested domain, its error 71cb0ef41Sopenharmony_ci// handler runs outside of that domain, but within the context of any parent 81cb0ef41Sopenharmony_ci// domain. 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst d = domain.create(); 111cb0ef41Sopenharmony_ciconst d2 = domain.create(); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cid2.on('error', common.mustCall((err) => { 141cb0ef41Sopenharmony_ci if (domain._stack.length !== 1) { 151cb0ef41Sopenharmony_ci console.error('domains stack length should be 1 but is %d', 161cb0ef41Sopenharmony_ci domain._stack.length); 171cb0ef41Sopenharmony_ci process.exit(1); 181cb0ef41Sopenharmony_ci } 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci if (process.domain !== d) { 211cb0ef41Sopenharmony_ci console.error('active domain should be %j but is %j', d, process.domain); 221cb0ef41Sopenharmony_ci process.exit(1); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci process.nextTick(() => { 261cb0ef41Sopenharmony_ci if (domain._stack.length !== 1) { 271cb0ef41Sopenharmony_ci console.error('domains stack length should be 1 but is %d', 281cb0ef41Sopenharmony_ci domain._stack.length); 291cb0ef41Sopenharmony_ci process.exit(1); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci if (process.domain !== d) { 331cb0ef41Sopenharmony_ci console.error('active domain should be %j but is %j', d, 341cb0ef41Sopenharmony_ci process.domain); 351cb0ef41Sopenharmony_ci process.exit(1); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci})); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_cid.run(() => { 411cb0ef41Sopenharmony_ci d2.run(() => { 421cb0ef41Sopenharmony_ci throw new Error('oops'); 431cb0ef41Sopenharmony_ci }); 441cb0ef41Sopenharmony_ci}); 45