fix(web-push): accept WebIDL notifications whose data is a prototype getter (06-01)

Real Notification objects expose `data` as a getter on the prototype, so the
own-property check dropped every click. The runtime test now uses a
class-based fake with the WebIDL shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-25 23:58:19 +09:00
co-authored by Claude Opus 5.5
parent 4d17259037
commit 8522cb5256
2 changed files with 28 additions and 2 deletions
@@ -273,7 +273,9 @@ function notificationClickEventFacade(
typeof value.waitUntil !== "function" ||
!isRecord(value.notification) ||
typeof value.notification.close !== "function" ||
!Object.hasOwn(value.notification, "data")
// 06-01. `data` is a WebIDL getter on `Notification.prototype`, never an
// own property, so the check must follow the prototype chain.
!("data" in value.notification)
) {
return null;
}
+25 -1
View File
@@ -106,6 +106,25 @@ function manualScheduler(): Readonly<{
};
}
/**
* 06-01. WebIDL shape of a real `Notification`: `data` is a getter and
* `close` a method on the prototype, so the instance has no own keys
* (checked in Chromium, Firefox and WebKit).
*/
class WebIdlNotification {
readonly #data: unknown;
closed = 0;
constructor(data: unknown) {
this.#data = data;
}
get data(): unknown {
return this.#data;
}
close(): void {
this.closed += 1;
}
}
describe("Web Push worker runtime", () => {
it("waits for strict hint handling and shows only registry-owned safe copy", async () => {
const store = await activeFence();
@@ -703,13 +722,18 @@ describe("Web Push worker runtime", () => {
"pushsubscriptionchange",
]);
let clickWait: Promise<void> | null = null;
const notification = new WebIdlNotification(clickData());
expect(Object.keys(notification)).toEqual(["closed"]);
expect(Object.hasOwn(notification, "data")).toBe(false);
listeners.get("notificationclick")?.({
notification: { data: clickData(), close() {} },
notification,
waitUntil(task: Promise<void>) {
clickWait = task;
},
});
expect(clickWait).not.toBeNull();
await clickWait;
expect(notification.closed).toBe(1);
let subscriptionWait: Promise<void> | null = null;
listeners.get("pushsubscriptionchange")?.({
waitUntil(task: Promise<void>) {