mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
Merge pull request #10470 from Snuffleupagus/mozcentral-streams
Try to, completely, avoid loading the `ReadableStream` polyfill in MOZCENTRAL builds
This commit is contained in:
commit
66acc7397f
6 changed files with 94 additions and 46 deletions
12
src/pdf.worker.js
vendored
12
src/pdf.worker.js
vendored
|
@ -12,13 +12,17 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-unused-vars */
|
||||
/* eslint-disable no-restricted-globals, no-unused-vars */
|
||||
|
||||
'use strict';
|
||||
|
||||
var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
|
||||
var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
|
||||
if (PDFJSDev.test('MOZCENTRAL') && typeof ReadableStream === 'undefined') {
|
||||
importScripts('./streams_polyfill.js');
|
||||
}
|
||||
|
||||
var pdfjsCoreWorker = require('./core/worker.js');
|
||||
const pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
|
||||
const pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
|
||||
|
||||
const pdfjsCoreWorker = require('./core/worker.js');
|
||||
|
||||
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
|
||||
|
|
|
@ -14,25 +14,32 @@
|
|||
*/
|
||||
/* eslint-disable no-restricted-globals */
|
||||
|
||||
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 (isReadableStreamSupported) {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) {
|
||||
// On the main-thread the `streams_polyfill.js` file is loaded using a
|
||||
// <script> tag; see `web/viewer-snippet-firefox-extension.html`.
|
||||
// On the worker-thread the `streams_polyfill.js` file is (conditionally)
|
||||
// loaded using `importScripts`; see `src/pdf.worker.js`.
|
||||
exports.ReadableStream = ReadableStream;
|
||||
} else {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
||||
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 (isReadableStreamSupported) {
|
||||
exports.ReadableStream = ReadableStream;
|
||||
} else if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('IMAGE_DECODERS')) {
|
||||
class DummyReadableStream {
|
||||
constructor() {
|
||||
throw new Error('The current image decoders are synchronous, ' +
|
||||
|
|
|
@ -32,32 +32,31 @@ if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
|||
|
||||
if (isURLSupported) {
|
||||
exports.URL = URL;
|
||||
} else {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
||||
class DummyURL {
|
||||
constructor() {
|
||||
throw new Error('The current image decoders doesn\'t utilize the ' +
|
||||
'`URL` constructor, hence it shouldn\'t need to be ' +
|
||||
'polyfilled for the IMAGE_DECODERS build target.');
|
||||
}
|
||||
} else if (typeof PDFJSDev !== 'undefined' &&
|
||||
PDFJSDev.test('IMAGE_DECODERS')) {
|
||||
class DummyURL {
|
||||
constructor() {
|
||||
throw new Error('The current image decoders doesn\'t utilize the ' +
|
||||
'`URL` constructor, hence it shouldn\'t need to be ' +
|
||||
'polyfilled for the IMAGE_DECODERS build target.');
|
||||
}
|
||||
exports.URL = DummyURL;
|
||||
} else {
|
||||
const PolyfillURL = require('../../external/url/url-lib').URL;
|
||||
|
||||
// Attempt to copy over the static methods.
|
||||
const OriginalURL = require('./global_scope').URL;
|
||||
if (OriginalURL) {
|
||||
PolyfillURL.createObjectURL = function(blob) {
|
||||
// IE extension allows a second optional options argument, see
|
||||
// http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
|
||||
return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
|
||||
};
|
||||
PolyfillURL.revokeObjectURL = function(url) {
|
||||
OriginalURL.revokeObjectURL(url);
|
||||
};
|
||||
}
|
||||
exports.URL = PolyfillURL;
|
||||
}
|
||||
exports.URL = DummyURL;
|
||||
} else {
|
||||
const PolyfillURL = require('../../external/url/url-lib').URL;
|
||||
|
||||
// Attempt to copy over the static methods.
|
||||
const OriginalURL = require('./global_scope').URL;
|
||||
if (OriginalURL) {
|
||||
PolyfillURL.createObjectURL = function(blob) {
|
||||
// IE extension allows a second optional options argument, see
|
||||
// http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
|
||||
return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
|
||||
};
|
||||
PolyfillURL.revokeObjectURL = function(url) {
|
||||
OriginalURL.revokeObjectURL(url);
|
||||
};
|
||||
}
|
||||
exports.URL = PolyfillURL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue