Merge pull request #13896 from Snuffleupagus/cleanup-ReadableStream-polyfill

Simplify the `ReadableStream` polyfill
This commit is contained in:
Tim van der Meij 2021-08-14 12:21:55 +02:00 committed by GitHub
commit 0e7df95e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,8 +20,8 @@ if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) && (typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) &&
(typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked) (typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked)
) { ) {
// Provides support for globalThis in legacy browsers. // Provides support for `globalThis` in legacy browsers.
// Support: Firefox<65, Chrome<71, Safari<12.1 // Support: Firefox<65, Chrome<71, Safari<12.1, Node.js<12.0.0
if (typeof globalThis === "undefined" || globalThis.Math !== Math) { if (typeof globalThis === "undefined" || globalThis.Math !== Math) {
// eslint-disable-next-line no-global-assign // eslint-disable-next-line no-global-assign
globalThis = require("core-js/es/global-this"); globalThis = require("core-js/es/global-this");
@ -89,23 +89,12 @@ if (
// shouldn't need to be polyfilled for the IMAGE_DECODERS build target. // shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
return; return;
} }
let isReadableStreamSupported = false; if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
// Slightly reduce the size of the Chromium-extension, given
if (typeof ReadableStream !== "undefined") { // that `ReadableStream` has been supported since Chrome 43.
// MS Edge may say it has ReadableStream but they are not up to spec yet. return;
try {
// eslint-disable-next-line no-new
new ReadableStream({
start(controller) {
controller.close();
},
});
isReadableStreamSupported = true;
} catch (e) {
// The ReadableStream constructor cannot be used.
}
} }
if (isReadableStreamSupported) { if (globalThis.ReadableStream || !isNodeJS) {
return; return;
} }
globalThis.ReadableStream = globalThis.ReadableStream =