Skip to content

Commit 452011b

Browse files
KhafraDevtargos
authored andcommitted
lib: speed up MessageEvent creation internally
PR-URL: #52951 Refs: nodejs/undici#3170 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent eded1e9 commit 452011b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎lib/internal/worker/io.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ const messageTypes = {
8585
LOAD_SCRIPT: 'loadScript',
8686
};
8787

88-
letmessageEvent;
89-
functionlazyMessageEvent(){
90-
returnmessageEvent??=require('internal/deps/undici/undici').MessageEvent;
88+
// createFastMessageEvent skips webidl argument validation when the arguments
89+
// passed are known to be valid.
90+
letfastCreateMessageEvent;
91+
functionlazyMessageEvent(type,init){
92+
fastCreateMessageEvent??=require('internal/deps/undici/undici').createFastMessageEvent;
93+
returnfastCreateMessageEvent(type,init);
9194
}
9295

9396
// We have to mess with the MessagePort prototype a bit, so that a) we can make
@@ -128,7 +131,7 @@ ObjectDefineProperty(
128131
}
129132
constports=this[kCurrentlyReceivingPorts];
130133
this[kCurrentlyReceivingPorts]=undefined;
131-
returnnew(lazyMessageEvent())(type,{ data, ports });
134+
returnlazyMessageEvent(type,{ data, ports });
132135
},
133136
configurable: false,
134137
writable: false,
@@ -321,7 +324,7 @@ function receiveMessageOnPort(port) {
321324
}
322325

323326
functiononMessageEvent(type,data){
324-
this.dispatchEvent(new(lazyMessageEvent())(type,{ data }));
327+
this.dispatchEvent(lazyMessageEvent(type,{ data }));
325328
}
326329

327330
functionisBroadcastChannel(value){

0 commit comments

Comments
 (0)