1'use strict'; 2 3const common = require('../common'); 4const domain = require('domain'); 5 6// Make sure that when an error is thrown from a nested domain, its error 7// handler runs outside of that domain, but within the context of any parent 8// domain. 9 10const d = domain.create(); 11const d2 = domain.create(); 12 13d2.on('error', common.mustCall((err) => { 14 if (domain._stack.length !== 1) { 15 console.error('domains stack length should be 1 but is %d', 16 domain._stack.length); 17 process.exit(1); 18 } 19 20 if (process.domain !== d) { 21 console.error('active domain should be %j but is %j', d, process.domain); 22 process.exit(1); 23 } 24 25 process.nextTick(() => { 26 if (domain._stack.length !== 1) { 27 console.error('domains stack length should be 1 but is %d', 28 domain._stack.length); 29 process.exit(1); 30 } 31 32 if (process.domain !== d) { 33 console.error('active domain should be %j but is %j', d, 34 process.domain); 35 process.exit(1); 36 } 37 }); 38})); 39 40d.run(() => { 41 d2.run(() => { 42 throw new Error('oops'); 43 }); 44}); 45