1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge pull request #14560 from Snuffleupagus/Node-ReadableStream-polyfill

[api-minor] Remove the, in `legacy` builds, bundled `ReadableStream` polyfill
This commit is contained in:
Tim van der Meij 2022-02-13 14:08:22 +01:00 committed by GitHub
commit c37d785b2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 25 deletions

View file

@ -133,15 +133,15 @@ class WorkerMessageHandler {
// Ensure that (primarily) Node.js users won't accidentally attempt to use
// a non-translated/non-polyfilled build of the library, since that would
// quickly fail anyway because of missing functionality.
if (
(typeof PDFJSDev === "undefined" || PDFJSDev.test("SKIP_BABEL")) &&
typeof ReadableStream === "undefined"
) {
throw new Error(
if (typeof ReadableStream === "undefined") {
const partialMsg =
"The browser/environment lacks native support for critical " +
"functionality used by the PDF.js library (e.g. `ReadableStream`); " +
"please use a `legacy`-build instead."
);
"functionality used by the PDF.js library (e.g. `ReadableStream`); ";
if (isNodeJS) {
throw new Error(partialMsg + "please use a `legacy`-build instead.");
}
throw new Error(partialMsg + "please update to a supported browser.");
}
}

View file

@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals __non_webpack_require__ */
import { isNodeJS } from "./is_node.js";
@ -69,21 +70,12 @@ if (
// Support: Node.js
(function checkReadableStream() {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
// The current image decoders are synchronous, hence `ReadableStream`
// shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
return;
}
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 (globalThis.ReadableStream || !isNodeJS) {
return;
}
globalThis.ReadableStream =
require("web-streams-polyfill/dist/ponyfill.js").ReadableStream;
globalThis.ReadableStream = __non_webpack_require__(
"web-streams-polyfill/dist/ponyfill.js"
).ReadableStream;
})();
// Support: Firefox<94, Chrome<98, Safari, Node.js<17.0.0