Merge pull request #11391 from Snuffleupagus/globalThis

Replace `globalScope` with the standard `globalThis` property instead
This commit is contained in:
Tim van der Meij 2019-12-08 20:23:19 +01:00 committed by GitHub
commit 16778118f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 56 deletions

View File

@ -19,6 +19,7 @@
},
"globals": {
"globalThis": false,
"PDFJSDev": false,
"exports": false,
"SystemJS": false,

View File

@ -33,7 +33,6 @@ import {
import { FontFaceObject, FontLoader } from './font_loader';
import { apiCompatibilityParams } from './api_compatibility';
import { CanvasGraphics } from './canvas';
import { globalScope } from '../shared/global_scope';
import { GlobalWorkerOptions } from './worker_options';
import { MessageHandler } from '../shared/message_handler';
import { Metadata } from './metadata';
@ -1541,12 +1540,12 @@ const PDFWorker = (function PDFWorkerClosure() {
}
function getMainThreadWorkerMessageHandler() {
let mainWorkerMessageHandler;
try {
if (typeof window !== 'undefined') {
return (window.pdfjsWorker && window.pdfjsWorker.WorkerMessageHandler);
}
} catch (ex) { }
return null;
mainWorkerMessageHandler =
globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
} catch (ex) { /* Ignore errors. */ }
return mainWorkerMessageHandler || null;
}
// Loads worker code into main thread.
@ -2103,11 +2102,11 @@ class WorkerTransport {
}
let fontRegistry = null;
if (params.pdfBug && globalScope.FontInspector &&
globalScope.FontInspector.enabled) {
if (params.pdfBug && globalThis.FontInspector &&
globalThis.FontInspector.enabled) {
fontRegistry = {
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);
}
if (this._pdfBug && globalScope.StepperManager &&
globalScope.StepperManager.enabled) {
this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
if (this._pdfBug && globalThis.StepperManager &&
globalThis.StepperManager.enabled) {
this.stepper = globalThis.StepperManager.create(this.pageNumber - 1);
this.stepper.init(this.operatorList);
this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
}

View File

@ -14,7 +14,6 @@
*/
import { AbortException, createPromiseCapability, Util } from '../shared/util';
import { globalScope } from '../shared/global_scope';
/**
* Text layer render parameters.
@ -469,8 +468,8 @@ var renderTextLayer = (function renderTextLayerClosure() {
this._textDivs = textDivs || [];
this._textContentItemsStr = textContentItemsStr || [];
this._enhanceTextSelection = !!enhanceTextSelection;
this._fontInspectorEnabled = !!(globalScope.FontInspector &&
globalScope.FontInspector.enabled);
this._fontInspectorEnabled = !!(globalThis.FontInspector &&
globalThis.FontInspector.enabled);
this._reader = null;
this._layoutTextLastFontSize = null;

View File

@ -14,13 +14,18 @@
*/
/* eslint no-var: error */
const { globalScope, } = require('./global_scope');
// Skip compatibility checks for modern builds and if we already ran the module.
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');
@ -31,10 +36,10 @@ const isIE = /Trident/.test(userAgent);
// Support: Node.js
(function checkNodeBtoa() {
if (globalScope.btoa || !isNodeJS) {
if (globalThis.btoa || !isNodeJS) {
return;
}
globalScope.btoa = function(chars) {
globalThis.btoa = function(chars) {
// eslint-disable-next-line no-undef
return Buffer.from(chars, 'binary').toString('base64');
};
@ -42,10 +47,10 @@ const isIE = /Trident/.test(userAgent);
// Support: Node.js
(function checkNodeAtob() {
if (globalScope.atob || !isNodeJS) {
if (globalThis.atob || !isNodeJS) {
return;
}
globalScope.atob = function(input) {
globalThis.atob = function(input) {
// eslint-disable-next-line no-undef
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.
return;
}
if (globalScope.Promise && (globalScope.Promise.prototype &&
globalScope.Promise.prototype.finally)) {
if (globalThis.Promise && (globalThis.Promise.prototype &&
globalThis.Promise.prototype.finally)) {
return;
}
globalScope.Promise = require('core-js/es/promise/index');
globalThis.Promise = require('core-js/es/promise/index');
})();
// Support: IE
@ -241,23 +246,23 @@ const isIE = /Trident/.test(userAgent);
// The `URL` constructor is assumed to be available in the extension builds.
return;
}
globalScope.URL = require('core-js/web/url');
globalThis.URL = require('core-js/web/url');
})();
// Support: IE<11, Safari<8, Chrome<36
(function checkWeakMap() {
if (globalScope.WeakMap) {
if (globalThis.WeakMap) {
return;
}
globalScope.WeakMap = require('core-js/es/weak-map/index');
globalThis.WeakMap = require('core-js/es/weak-map/index');
})();
// Support: IE11
(function checkWeakSet() {
if (globalScope.WeakSet) {
if (globalThis.WeakSet) {
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.
@ -280,7 +285,7 @@ const isIE = /Trident/.test(userAgent);
// Support: IE
(function checkSymbol() {
if (globalScope.Symbol) {
if (globalThis.Symbol) {
return;
}
require('core-js/es/symbol/index');

View File

@ -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,
};