From 956eb1032970777db8ec81913ceb6f87a6deb6c5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 21 Feb 2026 22:37:30 +0100 Subject: [PATCH] Use `FinalizationRegistry` unconditionally in the `src/scripting_api/app.js` file After the QuickJS update in PR 20708 this code can now be simplified. --- src/scripting_api/app.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/scripting_api/app.js b/src/scripting_api/app.js index 3c8619615..1680686bc 100644 --- a/src/scripting_api/app.js +++ b/src/scripting_api/app.js @@ -52,18 +52,14 @@ class App extends PDFObject { ); this._timeoutIds = new WeakMap(); - if (typeof FinalizationRegistry !== "undefined") { - // About setTimeOut/setInterval return values (specs): - // The return value of this method must be held in a - // JavaScript variable. - // Otherwise, the timeout object is subject to garbage-collection, - // which would cause the clock to stop. - this._timeoutIdsRegistry = new FinalizationRegistry( - this._cleanTimeout.bind(this) - ); - } else { - this._timeoutIdsRegistry = null; - } + // About setTimeOut/setInterval return values (specs): + // The return value of this method must be held in a + // JavaScript variable. + // Otherwise, the timeout object is subject to garbage-collection, + // which would cause the clock to stop. + this._timeoutIdsRegistry = new FinalizationRegistry( + this._cleanTimeout.bind(this) + ); this._timeoutCallbackIds = new Map(); this._timeoutCallbackId = USERACTIVATION_CALLBACKID + 1; @@ -113,12 +109,12 @@ class App extends PDFObject { const timeout = Object.create(null); const id = { callbackId, interval }; this._timeoutIds.set(timeout, id); - this._timeoutIdsRegistry?.register(timeout, id); + this._timeoutIdsRegistry.register(timeout, id); return timeout; } _unregisterTimeout(timeout) { - this._timeoutIdsRegistry?.unregister(timeout); + this._timeoutIdsRegistry.unregister(timeout); const data = this._timeoutIds.get(timeout); if (!data) {