Merge pull request #20709 from Snuffleupagus/scripting-unconditional-FinalizationRegistry

Use `FinalizationRegistry` unconditionally in the `src/scripting_api/app.js` file
This commit is contained in:
Tim van der Meij 2026-02-22 14:59:03 +01:00 committed by GitHub
commit cc516d0dd4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,7 +52,6 @@ class App extends PDFObject {
); );
this._timeoutIds = new WeakMap(); this._timeoutIds = new WeakMap();
if (typeof FinalizationRegistry !== "undefined") {
// About setTimeOut/setInterval return values (specs): // About setTimeOut/setInterval return values (specs):
// The return value of this method must be held in a // The return value of this method must be held in a
// JavaScript variable. // JavaScript variable.
@ -61,9 +60,6 @@ class App extends PDFObject {
this._timeoutIdsRegistry = new FinalizationRegistry( this._timeoutIdsRegistry = new FinalizationRegistry(
this._cleanTimeout.bind(this) this._cleanTimeout.bind(this)
); );
} else {
this._timeoutIdsRegistry = null;
}
this._timeoutCallbackIds = new Map(); this._timeoutCallbackIds = new Map();
this._timeoutCallbackId = USERACTIVATION_CALLBACKID + 1; this._timeoutCallbackId = USERACTIVATION_CALLBACKID + 1;
@ -113,12 +109,12 @@ class App extends PDFObject {
const timeout = Object.create(null); const timeout = Object.create(null);
const id = { callbackId, interval }; const id = { callbackId, interval };
this._timeoutIds.set(timeout, id); this._timeoutIds.set(timeout, id);
this._timeoutIdsRegistry?.register(timeout, id); this._timeoutIdsRegistry.register(timeout, id);
return timeout; return timeout;
} }
_unregisterTimeout(timeout) { _unregisterTimeout(timeout) {
this._timeoutIdsRegistry?.unregister(timeout); this._timeoutIdsRegistry.unregister(timeout);
const data = this._timeoutIds.get(timeout); const data = this._timeoutIds.get(timeout);
if (!data) { if (!data) {