From 449c7763d54da2be33b7935409edd394144e8e84 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 6 Sep 2020 13:33:31 +0200 Subject: [PATCH] [api-minor] Only support browsers/environments that have *basic* support for `Promise` natively Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#Browser_compatibility and https://caniuse.com/#feat=promises, all even remotely modern browsers already support *basic* `Promise` functionality natively. The only reason for keeping the `Promise` polyfill (at all) is to be able to support recent additions to the specification, such as e.g. `finally` and `allSettled`. Note that this patch will, on its own, remove support for IE 11/Edge (non-Chromium based) in both the general PDF.js library and the default viewer. --- README.md | 2 +- external/dist/README.md | 3 +-- src/shared/compatibility.js | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c1f89f526..c0d9b0e19 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Feel free to stop by our [Matrix room](https://chat.mozilla.org/#/room/#pdfjs:mo ### Online demo Please note that the "Modern browsers" version assumes native support for -features such as e.g. `async`/`await`, `Promise`, and `ReadableStream`. +features such as e.g. `async`/`await`, and `ReadableStream`. + Modern browsers: https://mozilla.github.io/pdf.js/web/viewer.html diff --git a/external/dist/README.md b/external/dist/README.md index 66c1ef1ff..6baa2e580 100644 --- a/external/dist/README.md +++ b/external/dist/README.md @@ -8,7 +8,6 @@ This is a pre-built version of the PDF.js source code. It is automatically generated by the build scripts. For usage with older browsers/environments, without support for modern features -such as e.g. `async`/`await`, `Promise`, and `ReadableStream`, -please refer to the `es5` folder. +such as e.g. `async`/`await`, and `ReadableStream`, please see the `es5` folder. See https://github.com/mozilla/pdf.js for learning and contributing. diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 8e3d11a0e..05bec1e95 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -242,14 +242,16 @@ if ( require("core-js/es/typed-array/slice"); })(); - // Support: IE, Safari<11, Chrome<63 + // Provides support for *recent* additions to the Promise specification, + // however basic Promise support is assumed to be available natively. + // Support: Firefox<71, Safari<13, Chrome<76 (function checkPromise() { if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) { // The current image decoders are synchronous, hence `Promise` shouldn't // need to be polyfilled for the IMAGE_DECODERS build target. return; } - if (globalThis.Promise && globalThis.Promise.allSettled) { + if (globalThis.Promise.allSettled) { return; } globalThis.Promise = require("core-js/es/promise/index.js");