From 870b94256819b347eebb96765226f404d3a0d3df Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 23 Apr 2023 13:01:35 +0200 Subject: [PATCH] Don't use the deprecated `CustomEvent.initCustomEvent` method anymore In PR #16295 one occurrence of this was changed, but a few more remained in the codebase. This commit fixes the other occurrences so that we don't use the deprecated way of creating custom events anywhere anymore. According to MDN, see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent, using the `CustomEvent.initCustomEvent` method is deprecated and the `CustomEvent` constructor should be used instead. Extends d9bf571f5c49e1cac9054cf6b7acfc0b5b719876. --- web/event_utils.js | 11 +++++++---- web/firefoxcom.js | 28 +++++++++++++++++----------- web/pdf_print_service.js | 7 +++++-- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/web/event_utils.js b/web/event_utils.js index 3ae6910bec52e..e1d32728819d8 100644 --- a/web/event_utils.js +++ b/web/event_utils.js @@ -172,7 +172,7 @@ class AutomationEventBus extends EventBus { } super.dispatch(eventName, data); - const details = Object.create(null); + const detail = Object.create(null); if (data) { for (const key in data) { const value = data[key]; @@ -182,11 +182,14 @@ class AutomationEventBus extends EventBus { } continue; // Ignore the `source` property. } - details[key] = value; + detail[key] = value; } } - const event = document.createEvent("CustomEvent"); - event.initCustomEvent(eventName, true, true, details); + const event = new CustomEvent(eventName, { + bubbles: true, + cancelable: true, + detail, + }); document.dispatchEvent(event); } } diff --git a/web/firefoxcom.js b/web/firefoxcom.js index 141024f3b599f..137af0c3fe6bc 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -40,11 +40,14 @@ class FirefoxCom { const request = document.createTextNode(""); document.documentElement.append(request); - const sender = document.createEvent("CustomEvent"); - sender.initCustomEvent("pdf.js.message", true, false, { - action, - data, - sync: true, + const sender = new CustomEvent("pdf.js.message", { + bubbles: true, + cancelable: false, + detail: { + action, + data, + sync: true, + }, }); request.dispatchEvent(sender); const response = sender.detail.response; @@ -88,12 +91,15 @@ class FirefoxCom { } document.documentElement.append(request); - const sender = document.createEvent("CustomEvent"); - sender.initCustomEvent("pdf.js.message", true, false, { - action, - data, - sync: false, - responseExpected: !!callback, + const sender = new CustomEvent("pdf.js.message", { + bubbles: true, + cancelable: false, + detail: { + action, + data, + sync: false, + responseExpected: !!callback, + }, }); request.dispatchEvent(sender); } diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index 4b522a80ecdf1..52af95969963b 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -273,8 +273,11 @@ window.print = function () { }; function dispatchEvent(eventType) { - const event = document.createEvent("CustomEvent"); - event.initCustomEvent(eventType, false, false, "custom"); + const event = new CustomEvent(eventType, { + bubbles: false, + cancelable: false, + detail: "custom", + }); window.dispatchEvent(event); }