Skip to content

Commit cc088db

Browse files
Copilotbartlomieju
andcommitted
fix: normalize capture option to boolean in removeEventListener
When an empty object {} is passed as options to removeEventListener, the capture property was undefined instead of false, causing the listener comparison to fail. Now normalizeEventHandlerOptions always converts capture to a boolean. Co-authored-by: bartlomieju <13602871+bartlomieju@users.noreply.github.com>
1 parent f133c2b commit cc088db

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/web/02_event.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,9 @@ function normalizeEventHandlerOptions(
838838
capture: Boolean(options),
839839
};
840840
} else {
841-
return options;
841+
return {
842+
capture: Boolean(options.capture),
843+
};
842844
}
843845
}
844846

tests/unit/event_test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ Deno.test(function inspectEvent() {
142142
);
143143
});
144144

145+
Deno.test(function removeEventListenerWithEmptyObjectOptions() {
146+
const target = new EventTarget();
147+
let callCount = 0;
148+
const listener = () => {
149+
callCount++;
150+
};
151+
152+
target.addEventListener("foo", listener);
153+
target.removeEventListener("foo", listener, {});
154+
target.dispatchEvent(new Event("foo"));
155+
assertEquals(callCount, 0);
156+
});
157+
145158
Deno.test("default argument is null prototype", () => {
146159
const event = new Event("test");
147160
assertEquals(event.bubbles, false);

0 commit comments

Comments
 (0)