mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

Having an experimental feature behind a flag makes change if we are expecting significant breaking changes to its API. Since the Worker API has been essentially stable since its initial introduction, and no noticeable doubt about possibly not keeping the feature around has been voiced, removing the flag and thereby reducing the barrier to experimentation, and consequently receiving feedback on the implementation, seems like a good idea. PR-URL: https://github.com/nodejs/node/pull/25361 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { MessageChannel } = require('worker_threads');
|
|
|
|
{
|
|
const { port1, port2 } = new MessageChannel();
|
|
|
|
// Returning a non-function in the getter should not crash.
|
|
Object.defineProperty(port1, 'onmessage', {
|
|
get() {
|
|
port1.unref();
|
|
return 42;
|
|
}
|
|
});
|
|
|
|
port2.postMessage({ foo: 'bar' });
|
|
|
|
// We need to start the port manually because .onmessage assignment tracking
|
|
// has been overridden.
|
|
port1.start();
|
|
port1.ref();
|
|
}
|
|
|
|
{
|
|
const err = new Error('eyecatcher');
|
|
process.on('uncaughtException', common.mustCall((exception) => {
|
|
port1.unref();
|
|
assert.strictEqual(exception, err);
|
|
}));
|
|
|
|
const { port1, port2 } = new MessageChannel();
|
|
|
|
// Throwing in the getter should not crash.
|
|
Object.defineProperty(port1, 'onmessage', {
|
|
get() {
|
|
throw err;
|
|
}
|
|
});
|
|
|
|
port2.postMessage({ foo: 'bar' });
|
|
|
|
// We need to start the port manually because .onmessage assignment tracking
|
|
// has been overridden.
|
|
port1.start();
|
|
port1.ref();
|
|
}
|