1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(ext/node): count MessagePort message listeners in hasMessageEventListener (#23209)

This commit is contained in:
Satya Rohith 2024-04-04 20:38:51 +05:30 committed by GitHub
parent de3f0b93f5
commit e01bc09573
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -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,

View file

@ -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() {