0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-worker-message-port-inspect-during-init-hook.js
Anna Henningsen 459d3a015a
worker: make MessagePort inherit from EventTarget
Use `NodeEventTarget` to provide a mixed `EventEmitter`/`EventTarget`
API interface.

PR-URL: https://github.com/nodejs/node/pull/34057
Refs: https://twitter.com/addaleax/status/1276289101671608320
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-07-22 22:59:11 +02:00

23 lines
734 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 [EventTarget] { 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'));