mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(ext/node): count MessagePort message listeners in hasMessageEventListener (#23209)
This commit is contained in:
parent
de3f0b93f5
commit
e01bc09573
2 changed files with 20 additions and 1 deletions
|
@ -22,6 +22,7 @@ const {
|
|||
Symbol,
|
||||
SymbolFor,
|
||||
SymbolIterator,
|
||||
SafeArrayIterator,
|
||||
TypeError,
|
||||
} = primordials;
|
||||
const {
|
||||
|
@ -40,6 +41,8 @@ import {
|
|||
import { isDetachedBuffer } from "./06_streams.js";
|
||||
import { DOMException } from "./01_dom_exception.js";
|
||||
|
||||
let messageEventListenerCount = 0;
|
||||
|
||||
class MessageChannel {
|
||||
/** @type {MessagePort} */
|
||||
#port1;
|
||||
|
@ -222,6 +225,20 @@ class MessagePort extends EventTarget {
|
|||
}
|
||||
}
|
||||
|
||||
removeEventListener(...args) {
|
||||
if (args[0] == "message") {
|
||||
messageEventListenerCount--;
|
||||
}
|
||||
super.removeEventListener(...new SafeArrayIterator(args));
|
||||
}
|
||||
|
||||
addEventListener(...args) {
|
||||
if (args[0] == "message") {
|
||||
messageEventListenerCount++;
|
||||
}
|
||||
super.addEventListener(...new SafeArrayIterator(args));
|
||||
}
|
||||
|
||||
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
||||
return inspect(
|
||||
createFilteredInspectProxy({
|
||||
|
@ -406,6 +423,7 @@ function structuredClone(value, options) {
|
|||
export {
|
||||
deserializeJsMessageData,
|
||||
MessageChannel,
|
||||
messageEventListenerCount,
|
||||
MessagePort,
|
||||
MessagePortIdSymbol,
|
||||
MessagePortPrototype,
|
||||
|
|
|
@ -282,7 +282,8 @@ let isClosing = false;
|
|||
let globalDispatchEvent;
|
||||
|
||||
function hasMessageEventListener() {
|
||||
return event.listenerCount(globalThis, "message") > 0;
|
||||
return event.listenerCount(globalThis, "message") > 0 ||
|
||||
messagePort.messageEventListenerCount > 0;
|
||||
}
|
||||
|
||||
async function pollForMessages() {
|
||||
|
|
Loading…
Reference in a new issue