Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/internal/worker/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,12 @@ const messageTypes = {
LOAD_SCRIPT: 'loadScript',
};

let messageEvent;
function lazyMessageEvent() {
return messageEvent ??= require('internal/deps/undici/undici').MessageEvent;
// createFastMessageEvent skips webidl argument validation when the arguments
// passed are known to be valid.
let fastCreateMessageEvent;
function lazyMessageEvent(type, init) {
fastCreateMessageEvent ??= require('internal/deps/undici/undici').createFastMessageEvent;
return fastCreateMessageEvent(type, init);
}

// We have to mess with the MessagePort prototype a bit, so that a) we can make
Expand Down Expand Up @@ -128,7 +131,7 @@ ObjectDefineProperty(
}
const ports = this[kCurrentlyReceivingPorts];
this[kCurrentlyReceivingPorts] = undefined;
return new (lazyMessageEvent())(type, { data, ports });
return lazyMessageEvent(type, { data, ports });
},
configurable: false,
writable: false,
Expand Down Expand Up @@ -321,7 +324,7 @@ function receiveMessageOnPort(port) {
}

function onMessageEvent(type, data) {
this.dispatchEvent(new (lazyMessageEvent())(type, { data }));
this.dispatchEvent(lazyMessageEvent(type, { data }));
}

function isBroadcastChannel(value) {
Expand Down