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, Symbol,
SymbolFor, SymbolFor,
SymbolIterator, SymbolIterator,
SafeArrayIterator,
TypeError, TypeError,
} = primordials; } = primordials;
const { const {
@ -40,6 +41,8 @@ import {
import { isDetachedBuffer } from "./06_streams.js"; import { isDetachedBuffer } from "./06_streams.js";
import { DOMException } from "./01_dom_exception.js"; import { DOMException } from "./01_dom_exception.js";
let messageEventListenerCount = 0;
class MessageChannel { class MessageChannel {
/** @type {MessagePort} */ /** @type {MessagePort} */
#port1; #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) { [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
return inspect( return inspect(
createFilteredInspectProxy({ createFilteredInspectProxy({
@ -406,6 +423,7 @@ function structuredClone(value, options) {
export { export {
deserializeJsMessageData, deserializeJsMessageData,
MessageChannel, MessageChannel,
messageEventListenerCount,
MessagePort, MessagePort,
MessagePortIdSymbol, MessagePortIdSymbol,
MessagePortPrototype, MessagePortPrototype,

View file

@ -282,7 +282,8 @@ let isClosing = false;
let globalDispatchEvent; let globalDispatchEvent;
function hasMessageEventListener() { function hasMessageEventListener() {
return event.listenerCount(globalThis, "message") > 0; return event.listenerCount(globalThis, "message") > 0 ||
messagePort.messageEventListenerCount > 0;
} }
async function pollForMessages() { async function pollForMessages() {