Merge pull request #16733 from Snuffleupagus/node-polyfills-catch
[api-minor] Attempt to prevent Node.js-specific polyfill errors from completely breaking the library
This commit is contained in:
commit
fb3ae82820
@ -20,7 +20,7 @@ import {
|
|||||||
BaseFilterFactory,
|
BaseFilterFactory,
|
||||||
BaseStandardFontDataFactory,
|
BaseStandardFontDataFactory,
|
||||||
} from "./base_factory.js";
|
} from "./base_factory.js";
|
||||||
import { isNodeJS } from "../shared/util.js";
|
import { isNodeJS, warn } from "../shared/util.js";
|
||||||
|
|
||||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@ -33,18 +33,26 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) {
|
|||||||
if (globalThis.DOMMatrix || !isNodeJS) {
|
if (globalThis.DOMMatrix || !isNodeJS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
|
try {
|
||||||
|
globalThis.DOMMatrix = __non_webpack_require__("canvas").DOMMatrix;
|
||||||
|
} catch (ex) {
|
||||||
|
warn(`Cannot polyfill \`DOMMatrix\`, rendering may be broken: "${ex}".`);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function checkPath2D() {
|
(function checkPath2D() {
|
||||||
if (globalThis.Path2D || !isNodeJS) {
|
if (globalThis.Path2D || !isNodeJS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
|
try {
|
||||||
const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
|
const { CanvasRenderingContext2D } = __non_webpack_require__("canvas");
|
||||||
|
const { polyfillPath2D } = __non_webpack_require__("path2d-polyfill");
|
||||||
|
|
||||||
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
|
globalThis.CanvasRenderingContext2D = CanvasRenderingContext2D;
|
||||||
polyfillPath2D(globalThis);
|
polyfillPath2D(globalThis);
|
||||||
|
} catch (ex) {
|
||||||
|
warn(`Cannot polyfill \`Path2D\`, rendering may be broken: "${ex}".`);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user