mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Replace our URL
polyfill with the one from core-js
`core-js` polyfills have proven to be of good quality and using them prevents us from having to maintain them ourselves.
This commit is contained in:
parent
c71a291317
commit
1f5ebfbf0c
16 changed files with 26 additions and 713 deletions
|
@ -20,7 +20,7 @@ import {
|
|||
InvalidPDFException, isArrayBuffer, isSameOrigin, MissingPDFException,
|
||||
NativeImageDecoding, PasswordException, setVerbosityLevel, shadow,
|
||||
stringToBytes, UnexpectedResponseException, UnknownErrorException,
|
||||
unreachable, URL, warn
|
||||
unreachable, warn
|
||||
} from '../shared/util';
|
||||
import {
|
||||
deprecated, DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
import {
|
||||
assert, CMapCompressionType, isString, removeNullCharacters, stringToBytes,
|
||||
unreachable, URL, Util, warn
|
||||
unreachable, Util, warn
|
||||
} from '../shared/util';
|
||||
|
||||
const DEFAULT_LINK_REL = 'noopener noreferrer nofollow';
|
||||
|
|
|
@ -107,7 +107,6 @@ exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
|
|||
exports.shadow = pdfjsSharedUtil.shadow;
|
||||
exports.Util = pdfjsSharedUtil.Util;
|
||||
exports.ReadableStream = pdfjsSharedUtil.ReadableStream;
|
||||
exports.URL = pdfjsSharedUtil.URL;
|
||||
exports.RenderingCancelledException =
|
||||
pdfjsDisplayDisplayUtils.RenderingCancelledException;
|
||||
exports.getFilenameFromUrl = pdfjsDisplayDisplayUtils.getFilenameFromUrl;
|
||||
|
|
|
@ -208,6 +208,20 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||
globalScope.Promise = require('core-js/es/promise/index');
|
||||
})();
|
||||
|
||||
// Support: IE
|
||||
(function checkURL() {
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
||||
// The current image decoders don't use the `URL` constructor, so it
|
||||
// doesn't need to be polyfilled for the IMAGE_DECODERS build target.
|
||||
return;
|
||||
}
|
||||
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
||||
// The `URL` constructor is assumed to be available in the extension builds.
|
||||
return;
|
||||
}
|
||||
globalScope.URL = require('core-js/web/url');
|
||||
})();
|
||||
|
||||
// Support: IE<11, Safari<8, Chrome<36
|
||||
(function checkWeakMap() {
|
||||
if (globalScope.WeakMap) {
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/* Copyright 2018 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable no-restricted-globals */
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
||||
// The `URL` constructor is assumed to be available in the extension builds.
|
||||
exports.URL = URL;
|
||||
} else {
|
||||
let isURLSupported = false;
|
||||
try {
|
||||
if (typeof URL === 'function' && typeof URL.prototype === 'object' &&
|
||||
('origin' in URL.prototype)) {
|
||||
const u = new URL('b', 'http://a');
|
||||
u.pathname = 'c%20d';
|
||||
isURLSupported = (u.href === 'http://a/c%20d');
|
||||
}
|
||||
} catch (ex) {
|
||||
// The `URL` constructor cannot be used.
|
||||
}
|
||||
|
||||
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.');
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import './compatibility';
|
||||
import { ReadableStream } from './streams_polyfill';
|
||||
import { URL } from './url_polyfill';
|
||||
|
||||
const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
|
||||
const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
|
||||
|
@ -970,7 +969,6 @@ export {
|
|||
readUint32,
|
||||
removeNullCharacters,
|
||||
ReadableStream,
|
||||
URL,
|
||||
setVerbosityLevel,
|
||||
shadow,
|
||||
string32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue