diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 6a6e307a9e5008..3263ddb88194fc 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -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 @@ -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, @@ -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) {