• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const async_hooks = require('async_hooks');
6const { AsyncResource } = async_hooks;
7const { spawn } = require('child_process');
8
9const initHooks = require('./init-hooks');
10
11if (process.argv[2] === 'child') {
12  initHooks().enable();
13
14  class Foo extends AsyncResource {
15    constructor(type) {
16      super(type, async_hooks.executionAsyncId());
17    }
18  }
19
20  [null, undefined, 1, Date, {}, []].forEach((i) => {
21    assert.throws(() => new Foo(i), {
22      code: 'ERR_INVALID_ARG_TYPE',
23      name: 'TypeError'
24    });
25  });
26
27} else {
28  const args = process.argv.slice(1).concat('child');
29  spawn(process.execPath, args)
30    .on('close', common.mustCall((code) => {
31      // No error because the type was defaulted
32      assert.strictEqual(code, 0);
33    }));
34}
35