Merge pull request #11391 from Snuffleupagus/globalThis
Replace `globalScope` with the standard `globalThis` property instead
This commit is contained in:
commit
16778118f6
@ -19,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"globals": {
|
"globals": {
|
||||||
|
"globalThis": false,
|
||||||
"PDFJSDev": false,
|
"PDFJSDev": false,
|
||||||
"exports": false,
|
"exports": false,
|
||||||
"SystemJS": false,
|
"SystemJS": false,
|
||||||
|
@ -33,7 +33,6 @@ import {
|
|||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
import { apiCompatibilityParams } from './api_compatibility';
|
import { apiCompatibilityParams } from './api_compatibility';
|
||||||
import { CanvasGraphics } from './canvas';
|
import { CanvasGraphics } from './canvas';
|
||||||
import { globalScope } from '../shared/global_scope';
|
|
||||||
import { GlobalWorkerOptions } from './worker_options';
|
import { GlobalWorkerOptions } from './worker_options';
|
||||||
import { MessageHandler } from '../shared/message_handler';
|
import { MessageHandler } from '../shared/message_handler';
|
||||||
import { Metadata } from './metadata';
|
import { Metadata } from './metadata';
|
||||||
@ -1541,12 +1540,12 @@ const PDFWorker = (function PDFWorkerClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMainThreadWorkerMessageHandler() {
|
function getMainThreadWorkerMessageHandler() {
|
||||||
|
let mainWorkerMessageHandler;
|
||||||
try {
|
try {
|
||||||
if (typeof window !== 'undefined') {
|
mainWorkerMessageHandler =
|
||||||
return (window.pdfjsWorker && window.pdfjsWorker.WorkerMessageHandler);
|
globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
|
||||||
}
|
} catch (ex) { /* Ignore errors. */ }
|
||||||
} catch (ex) { }
|
return mainWorkerMessageHandler || null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loads worker code into main thread.
|
// Loads worker code into main thread.
|
||||||
@ -2103,11 +2102,11 @@ class WorkerTransport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let fontRegistry = null;
|
let fontRegistry = null;
|
||||||
if (params.pdfBug && globalScope.FontInspector &&
|
if (params.pdfBug && globalThis.FontInspector &&
|
||||||
globalScope.FontInspector.enabled) {
|
globalThis.FontInspector.enabled) {
|
||||||
fontRegistry = {
|
fontRegistry = {
|
||||||
registerFont(font, url) {
|
registerFont(font, url) {
|
||||||
globalScope['FontInspector'].fontAdded(font, url);
|
globalThis.FontInspector.fontAdded(font, url);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -2608,9 +2607,9 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
canvasInRendering.add(this._canvas);
|
canvasInRendering.add(this._canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._pdfBug && globalScope.StepperManager &&
|
if (this._pdfBug && globalThis.StepperManager &&
|
||||||
globalScope.StepperManager.enabled) {
|
globalThis.StepperManager.enabled) {
|
||||||
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
|
this.stepper = globalThis.StepperManager.create(this.pageNumber - 1);
|
||||||
this.stepper.init(this.operatorList);
|
this.stepper.init(this.operatorList);
|
||||||
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
||||||
import { globalScope } from '../shared/global_scope';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text layer render parameters.
|
* Text layer render parameters.
|
||||||
@ -469,8 +468,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
|
|||||||
this._textDivs = textDivs || [];
|
this._textDivs = textDivs || [];
|
||||||
this._textContentItemsStr = textContentItemsStr || [];
|
this._textContentItemsStr = textContentItemsStr || [];
|
||||||
this._enhanceTextSelection = !!enhanceTextSelection;
|
this._enhanceTextSelection = !!enhanceTextSelection;
|
||||||
this._fontInspectorEnabled = !!(globalScope.FontInspector &&
|
this._fontInspectorEnabled = !!(globalThis.FontInspector &&
|
||||||
globalScope.FontInspector.enabled);
|
globalThis.FontInspector.enabled);
|
||||||
|
|
||||||
this._reader = null;
|
this._reader = null;
|
||||||
this._layoutTextLastFontSize = null;
|
this._layoutTextLastFontSize = null;
|
||||||
|
@ -14,13 +14,18 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
const { globalScope, } = require('./global_scope');
|
|
||||||
|
|
||||||
// Skip compatibility checks for modern builds and if we already ran the module.
|
// Skip compatibility checks for modern builds and if we already ran the module.
|
||||||
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SKIP_BABEL')) &&
|
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SKIP_BABEL')) &&
|
||||||
!globalScope._pdfjsCompatibilityChecked) {
|
(typeof globalThis === 'undefined' ||
|
||||||
|
!globalThis._pdfjsCompatibilityChecked)) {
|
||||||
|
|
||||||
globalScope._pdfjsCompatibilityChecked = true;
|
// Provides support for globalThis in legacy browsers.
|
||||||
|
// Support: IE11/Edge, Opera
|
||||||
|
if (typeof globalThis === 'undefined' || globalThis.Math !== Math) {
|
||||||
|
// eslint-disable-next-line no-global-assign
|
||||||
|
globalThis = require('core-js/es/global-this');
|
||||||
|
}
|
||||||
|
globalThis._pdfjsCompatibilityChecked = true;
|
||||||
|
|
||||||
const { isNodeJS, } = require('./is_node');
|
const { isNodeJS, } = require('./is_node');
|
||||||
|
|
||||||
@ -31,10 +36,10 @@ const isIE = /Trident/.test(userAgent);
|
|||||||
|
|
||||||
// Support: Node.js
|
// Support: Node.js
|
||||||
(function checkNodeBtoa() {
|
(function checkNodeBtoa() {
|
||||||
if (globalScope.btoa || !isNodeJS) {
|
if (globalThis.btoa || !isNodeJS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.btoa = function(chars) {
|
globalThis.btoa = function(chars) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
return Buffer.from(chars, 'binary').toString('base64');
|
return Buffer.from(chars, 'binary').toString('base64');
|
||||||
};
|
};
|
||||||
@ -42,10 +47,10 @@ const isIE = /Trident/.test(userAgent);
|
|||||||
|
|
||||||
// Support: Node.js
|
// Support: Node.js
|
||||||
(function checkNodeAtob() {
|
(function checkNodeAtob() {
|
||||||
if (globalScope.atob || !isNodeJS) {
|
if (globalThis.atob || !isNodeJS) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.atob = function(input) {
|
globalThis.atob = function(input) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
return Buffer.from(input, 'base64').toString('binary');
|
return Buffer.from(input, 'base64').toString('binary');
|
||||||
};
|
};
|
||||||
@ -223,11 +228,11 @@ const isIE = /Trident/.test(userAgent);
|
|||||||
// need to be polyfilled for the IMAGE_DECODERS build target.
|
// need to be polyfilled for the IMAGE_DECODERS build target.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (globalScope.Promise && (globalScope.Promise.prototype &&
|
if (globalThis.Promise && (globalThis.Promise.prototype &&
|
||||||
globalScope.Promise.prototype.finally)) {
|
globalThis.Promise.prototype.finally)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.Promise = require('core-js/es/promise/index');
|
globalThis.Promise = require('core-js/es/promise/index');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Support: IE
|
// Support: IE
|
||||||
@ -241,23 +246,23 @@ const isIE = /Trident/.test(userAgent);
|
|||||||
// The `URL` constructor is assumed to be available in the extension builds.
|
// The `URL` constructor is assumed to be available in the extension builds.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.URL = require('core-js/web/url');
|
globalThis.URL = require('core-js/web/url');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Support: IE<11, Safari<8, Chrome<36
|
// Support: IE<11, Safari<8, Chrome<36
|
||||||
(function checkWeakMap() {
|
(function checkWeakMap() {
|
||||||
if (globalScope.WeakMap) {
|
if (globalThis.WeakMap) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.WeakMap = require('core-js/es/weak-map/index');
|
globalThis.WeakMap = require('core-js/es/weak-map/index');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Support: IE11
|
// Support: IE11
|
||||||
(function checkWeakSet() {
|
(function checkWeakSet() {
|
||||||
if (globalScope.WeakSet) {
|
if (globalThis.WeakSet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
globalScope.WeakSet = require('core-js/es/weak-set/index');
|
globalThis.WeakSet = require('core-js/es/weak-set/index');
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Provides support for String.codePointAt in legacy browsers.
|
// Provides support for String.codePointAt in legacy browsers.
|
||||||
@ -280,7 +285,7 @@ const isIE = /Trident/.test(userAgent);
|
|||||||
|
|
||||||
// Support: IE
|
// Support: IE
|
||||||
(function checkSymbol() {
|
(function checkSymbol() {
|
||||||
if (globalScope.Symbol) {
|
if (globalThis.Symbol) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
require('core-js/es/symbol/index');
|
require('core-js/es/symbol/index');
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
/* Copyright 2017 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const globalScope =
|
|
||||||
(typeof window !== 'undefined' && window.Math === Math) ? window :
|
|
||||||
// eslint-disable-next-line no-undef
|
|
||||||
(typeof global !== 'undefined' && global.Math === Math) ? global :
|
|
||||||
(typeof self !== 'undefined' && self.Math === Math) ? self : {};
|
|
||||||
|
|
||||||
export {
|
|
||||||
globalScope,
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user