Skip to content

Commit f57fc80

Browse files
committed
Polyfill getOrInsertComputed for Firefox 140
1 parent 2ce2453 commit f57fc80

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/shared/util.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,20 @@ const makeArr = () => [];
12371237
const makeMap = () => new Map();
12381238
const makeObj = () => Object.create(null);
12391239

1240+
// TODO: Remove this once Firefox 140 is no longer supported.
1241+
if (
1242+
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
1243+
typeof Map.prototype.getOrInsertComputed !== "function"
1244+
) {
1245+
// eslint-disable-next-line no-extend-native
1246+
Map.prototype.getOrInsertComputed = function (key, callbackFn) {
1247+
if (!this.has(key)) {
1248+
this.set(key, callbackFn(key));
1249+
}
1250+
return this.get(key);
1251+
};
1252+
}
1253+
12401254
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
12411255
if (
12421256
typeof PDFJSDev !== "undefined" &&

0 commit comments

Comments
 (0)