mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 02:06:12 +00:00

Update docs and type checking for AsyncResource type PR-URL: https://github.com/nodejs/node/pull/15103 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
35 lines
846 B
JavaScript
35 lines
846 B
JavaScript
'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) => {
|
|
common.expectsError(() => new Foo(i), {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
type: TypeError
|
|
});
|
|
});
|
|
|
|
} 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);
|
|
}));
|
|
}
|