Skip to content

Commit

Permalink
Guard _finalizationRegistry based on availability.
Browse files Browse the repository at this point in the history
  • Loading branch information
DellaBitta committed Jun 25, 2024
1 parent b09a267 commit 256814a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/app/src/firebaseServerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FirebaseServerAppImpl
implements FirebaseServerApp
{
private readonly _serverConfig: FirebaseServerAppSettings;
private _finalizationRegistry: FinalizationRegistry<object>;
private _finalizationRegistry: FinalizationRegistry<object> | null;
private _refCount: number;

constructor(
Expand Down Expand Up @@ -67,9 +67,12 @@ export class FirebaseServerAppImpl
...serverConfig
};

this._finalizationRegistry = new FinalizationRegistry(() => {
this.automaticCleanup();
});
this._finalizationRegistry = null;
if (typeof FinalizationRegistry !== 'undefined') {
this._finalizationRegistry = new FinalizationRegistry(() => {
this.automaticCleanup();
});
}

this._refCount = 0;
this.incRefCount(this._serverConfig.releaseOnDeref);
Expand Down Expand Up @@ -97,7 +100,7 @@ export class FirebaseServerAppImpl
return;
}
this._refCount++;
if (obj !== undefined) {
if (obj !== undefined && this._finalizationRegistry !== null) {
this._finalizationRegistry.register(obj, this);
}
}
Expand Down

0 comments on commit 256814a

Please sign in to comment.