1'use strict';
2const common = require('../common');
3const util = require('util');
4const assert = require('assert');
5const async_hooks = require('async_hooks');
6const { MessageChannel } = require('worker_threads');
7
8// Regression test: Inspecting a `MessagePort` object before it is finished
9// constructing does not crash the process.
10
11async_hooks.createHook({
12  init: common.mustCall((id, type, triggerId, resource) => {
13    assert.strictEqual(
14      util.inspect(resource),
15      'MessagePort [EventTarget] { active: true, refed: false }');
16  }, 2)
17}).enable();
18
19const { port1 } = new MessageChannel();
20const inspection = util.inspect(port1);
21assert(inspection.includes('active: true'));
22assert(inspection.includes('refed: false'));
23