Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the ReadableStream polyfill #13896

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions src/shared/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) &&
(typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked)
) {
// Provides support for globalThis in legacy browsers.
// Support: Firefox<65, Chrome<71, Safari<12.1
// Provides support for `globalThis` in legacy browsers.
// Support: Firefox<65, Chrome<71, Safari<12.1, Node.js<12.0.0
if (typeof globalThis === "undefined" || globalThis.Math !== Math) {
// eslint-disable-next-line no-global-assign
globalThis = require("core-js/es/global-this");
Expand Down Expand Up @@ -89,23 +89,12 @@ if (
// shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
return;
}
let isReadableStreamSupported = false;

if (typeof ReadableStream !== "undefined") {
// MS Edge may say it has ReadableStream but they are not up to spec yet.
try {
// eslint-disable-next-line no-new
new ReadableStream({
start(controller) {
controller.close();
},
});
isReadableStreamSupported = true;
} catch (e) {
// The ReadableStream constructor cannot be used.
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
// Slightly reduce the size of the Chromium-extension, given
// that `ReadableStream` has been supported since Chrome 43.
return;
}
if (isReadableStreamSupported) {
if (globalThis.ReadableStream || !isNodeJS) {
return;
}
globalThis.ReadableStream =
Expand Down