2017-08-30 21:45:21 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const async_hooks = require('async_hooks');
|
|
|
|
const { AsyncResource } = async_hooks;
|
|
|
|
const { spawn } = require('child_process');
|
|
|
|
|
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
initHooks().enable();
|
|
|
|
|
|
|
|
class Foo extends AsyncResource {
|
|
|
|
constructor(type) {
|
|
|
|
super(type, async_hooks.executionAsyncId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[null, undefined, 1, Date, {}, []].forEach((i) => {
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(() => new Foo(i), {
|
2017-08-30 21:45:21 +00:00
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2022-11-21 17:43:47 +00:00
|
|
|
name: 'TypeError',
|
2017-08-30 21:45:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const args = process.argv.slice(1).concat('child');
|
|
|
|
spawn(process.execPath, args)
|
|
|
|
.on('close', common.mustCall((code) => {
|
|
|
|
// No error because the type was defaulted
|
|
|
|
assert.strictEqual(code, 0);
|
|
|
|
}));
|
|
|
|
}
|