mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: speed up MessageEvent creation internally
PR-URL: https://github.com/nodejs/node/pull/52951 Refs: https://github.com/nodejs/undici/pull/3170 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user