nodejs-mozilla/test/parallel/test-worker-message-port-in...

22 lines
730 B
JavaScript

'use strict';
const common = require('../common');
const util = require('util');
const assert = require('assert');
const async_hooks = require('async_hooks');
const { MessageChannel } = require('worker_threads');
// Regression test: Inspecting a `MessagePort` object before it is finished
// constructing does not crash the process.
async_hooks.createHook({
init: common.mustCall((id, type, triggerId, resource) => {
assert.strictEqual(util.inspect(resource),
'MessagePort { active: true, refed: false }');
}, 2)
}).enable();
const { port1 } = new MessageChannel();
const inspection = util.inspect(port1);
assert(inspection.includes('active: true'));
assert(inspection.includes('refed: false'));