Convert globalScope
and isNodeJS
to proper modules
Slightly unrelated to the rest of the patch, but this also removes an out-of-place `globals` definition from the `web/viewer.js` file.
This commit is contained in:
parent
c2bd3a0bfb
commit
2817121bc1
@ -21,7 +21,7 @@ import {
|
|||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { clearPrimitiveCaches, Ref } from './primitives';
|
import { clearPrimitiveCaches, Ref } from './primitives';
|
||||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||||
import isNodeJS from '../shared/is_node';
|
import { isNodeJS } from '../shared/is_node';
|
||||||
import { MessageHandler } from '../shared/message_handler';
|
import { MessageHandler } from '../shared/message_handler';
|
||||||
import { PDFWorkerStream } from './worker_stream';
|
import { PDFWorkerStream } from './worker_stream';
|
||||||
import { XRefParseException } from './core_utils';
|
import { XRefParseException } from './core_utils';
|
||||||
|
@ -33,7 +33,7 @@ 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 { 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';
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
let compatibilityParams = Object.create(null);
|
let compatibilityParams = Object.create(null);
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
const isNodeJS = require('../shared/is_node');
|
const { isNodeJS, } = require('../shared/is_node');
|
||||||
|
|
||||||
const userAgent =
|
const userAgent =
|
||||||
(typeof navigator !== 'undefined' && navigator.userAgent) || '';
|
(typeof navigator !== 'undefined' && navigator.userAgent) || '';
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
TextRenderingMode, Util, warn
|
TextRenderingMode, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { DOMSVGFactory } from './display_utils';
|
import { DOMSVGFactory } from './display_utils';
|
||||||
import isNodeJS from '../shared/is_node';
|
import { isNodeJS } from '../shared/is_node';
|
||||||
|
|
||||||
let SVGGraphics = function() {
|
let SVGGraphics = function() {
|
||||||
throw new Error('Not implemented: SVGGraphics');
|
throw new Error('Not implemented: SVGGraphics');
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
import { AbortException, createPromiseCapability, Util } from '../shared/util';
|
||||||
import globalScope from '../shared/global_scope';
|
import { globalScope } from '../shared/global_scope';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text layer render parameters.
|
* Text layer render parameters.
|
||||||
|
@ -31,7 +31,7 @@ let pdfjsDisplayWorkerOptions = require('./display/worker_options.js');
|
|||||||
let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
let pdfjsDisplayAPICompatibility = require('./display/api_compatibility.js');
|
||||||
|
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
const isNodeJS = require('./shared/is_node.js');
|
const { isNodeJS, } = require('./shared/is_node.js');
|
||||||
if (isNodeJS()) {
|
if (isNodeJS()) {
|
||||||
let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
||||||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint no-var: error */
|
/* eslint no-var: error */
|
||||||
|
|
||||||
const globalScope = require('./global_scope');
|
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')) &&
|
||||||
@ -22,7 +22,7 @@ if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SKIP_BABEL')) &&
|
|||||||
|
|
||||||
globalScope._pdfjsCompatibilityChecked = true;
|
globalScope._pdfjsCompatibilityChecked = true;
|
||||||
|
|
||||||
const isNodeJS = require('./is_node');
|
const { isNodeJS, } = require('./is_node');
|
||||||
|
|
||||||
const hasDOM = typeof window === 'object' && typeof document === 'object';
|
const hasDOM = typeof window === 'object' && typeof document === 'object';
|
||||||
|
|
||||||
|
@ -12,10 +12,13 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals module */
|
|
||||||
|
|
||||||
module.exports =
|
const globalScope =
|
||||||
(typeof window !== 'undefined' && window.Math === Math) ? window :
|
(typeof window !== 'undefined' && window.Math === Math) ? window :
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
(typeof global !== 'undefined' && global.Math === Math) ? global :
|
(typeof global !== 'undefined' && global.Math === Math) ? global :
|
||||||
(typeof self !== 'undefined' && self.Math === Math) ? self : {};
|
(typeof self !== 'undefined' && self.Math === Math) ? self : {};
|
||||||
|
|
||||||
|
export {
|
||||||
|
globalScope,
|
||||||
|
};
|
||||||
|
@ -12,13 +12,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals module, process */
|
/* globals process */
|
||||||
|
|
||||||
module.exports = function isNodeJS() {
|
function isNodeJS() {
|
||||||
// NW.js / Electron is a browser context, but copies some Node.js objects; see
|
// NW.js / Electron is a browser context, but copies some Node.js objects; see
|
||||||
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
|
// http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
|
||||||
// https://electronjs.org/docs/api/process#processversionselectron
|
// https://electronjs.org/docs/api/process#processversionselectron
|
||||||
return typeof process === 'object' &&
|
return typeof process === 'object' &&
|
||||||
process + '' === '[object process]' &&
|
process + '' === '[object process]' &&
|
||||||
!process.versions['nw'] && !process.versions['electron'];
|
!process.versions['nw'] && !process.versions['electron'];
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
isNodeJS,
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
getDocument, PDFDataRangeTransport, PDFDocumentProxy, PDFPageProxy, PDFWorker
|
||||||
} from '../../src/display/api';
|
} from '../../src/display/api';
|
||||||
import { GlobalWorkerOptions } from '../../src/display/worker_options';
|
import { GlobalWorkerOptions } from '../../src/display/worker_options';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { Metadata } from '../../src/display/metadata';
|
import { Metadata } from '../../src/display/metadata';
|
||||||
|
|
||||||
describe('api', function() {
|
describe('api', function() {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { setVerbosityLevel, VerbosityLevel } from '../../src/shared/util';
|
import { setVerbosityLevel, VerbosityLevel } from '../../src/shared/util';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { PDFNodeStream } from '../../src/display/node_stream';
|
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||||
import { setPDFNetworkStreamFactory } from '../../src/display/api';
|
import { setPDFNetworkStreamFactory } from '../../src/display/api';
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
import { CMap, CMapFactory, IdentityCMap } from '../../src/core/cmap';
|
import { CMap, CMapFactory, IdentityCMap } from '../../src/core/cmap';
|
||||||
import { DOMCMapReaderFactory } from '../../src/display/display_utils';
|
import { DOMCMapReaderFactory } from '../../src/display/display_utils';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { Name } from '../../src/core/primitives';
|
import { Name } from '../../src/core/primitives';
|
||||||
import { NodeCMapReaderFactory } from './test_utils';
|
import { NodeCMapReaderFactory } from './test_utils';
|
||||||
import { StringStream } from '../../src/core/stream';
|
import { StringStream } from '../../src/core/stream';
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
import { buildGetDocumentParams, NodeCanvasFactory } from './test_utils';
|
import { buildGetDocumentParams, NodeCanvasFactory } from './test_utils';
|
||||||
import { DOMCanvasFactory } from '../../src/display/display_utils';
|
import { DOMCanvasFactory } from '../../src/display/display_utils';
|
||||||
import { getDocument } from '../../src/display/api';
|
import { getDocument } from '../../src/display/api';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
|
|
||||||
function getTopLeftPixel(canvasContext) {
|
function getTopLeftPixel(canvasContext) {
|
||||||
let imgData = canvasContext.getImageData(0, 0, 1, 1);
|
let imgData = canvasContext.getImageData(0, 0, 1, 1);
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import { setStubs, unsetStubs } from '../../examples/node/domstubs';
|
import { setStubs, unsetStubs } from '../../examples/node/domstubs';
|
||||||
import { buildGetDocumentParams } from './test_utils';
|
import { buildGetDocumentParams } from './test_utils';
|
||||||
import { getDocument } from '../../src/display/api';
|
import { getDocument } from '../../src/display/api';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { NativeImageDecoding } from '../../src/shared/util';
|
import { NativeImageDecoding } from '../../src/shared/util';
|
||||||
import { SVGGraphics } from '../../src/display/svg';
|
import { SVGGraphics } from '../../src/display/svg';
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
DOMCanvasFactory, DOMSVGFactory, getFilenameFromUrl, isValidFetchUrl,
|
DOMCanvasFactory, DOMSVGFactory, getFilenameFromUrl, isValidFetchUrl,
|
||||||
PDFDateString
|
PDFDateString
|
||||||
} from '../../src/display/display_utils';
|
} from '../../src/display/display_utils';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
|
|
||||||
describe('display_utils', function() {
|
describe('display_utils', function() {
|
||||||
describe('DOMCanvasFactory', function() {
|
describe('DOMCanvasFactory', function() {
|
||||||
|
@ -81,11 +81,11 @@ function initializePDFJS(callback) {
|
|||||||
].map(function (moduleName) {
|
].map(function (moduleName) {
|
||||||
return SystemJS.import(moduleName);
|
return SystemJS.import(moduleName);
|
||||||
})).then(function(modules) {
|
})).then(function(modules) {
|
||||||
var displayApi = modules[0];
|
const displayApi = modules[0];
|
||||||
const GlobalWorkerOptions = modules[1].GlobalWorkerOptions;
|
const { GlobalWorkerOptions, } = modules[1];
|
||||||
var PDFNetworkStream = modules[2].PDFNetworkStream;
|
const { PDFNetworkStream, } = modules[2];
|
||||||
var PDFFetchStream = modules[3].PDFFetchStream;
|
const { PDFFetchStream, } = modules[3];
|
||||||
const isNodeJS = modules[4];
|
const { isNodeJS, } = modules[4];
|
||||||
|
|
||||||
if (isNodeJS()) {
|
if (isNodeJS()) {
|
||||||
throw new Error('The `gulp unittest` command cannot be used in ' +
|
throw new Error('The `gulp unittest` command cannot be used in ' +
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
/* globals __non_webpack_require__ */
|
/* globals __non_webpack_require__ */
|
||||||
|
|
||||||
import { AbortException, assert } from '../../src/shared/util';
|
import { AbortException, assert } from '../../src/shared/util';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { PDFNodeStream } from '../../src/display/node_stream';
|
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||||
|
|
||||||
// Make sure that we only running this script is Node.js environments.
|
// Make sure that we only running this script is Node.js environments.
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { assert, CMapCompressionType } from '../../src/shared/util';
|
import { assert, CMapCompressionType } from '../../src/shared/util';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
import { isRef } from '../../src/core/primitives';
|
import { isRef } from '../../src/core/primitives';
|
||||||
import { Page } from '../../src/core/document';
|
import { Page } from '../../src/core/document';
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
waitOnEventOrTimeout, WaitOnType
|
waitOnEventOrTimeout, WaitOnType
|
||||||
} from '../../web/ui_utils';
|
} from '../../web/ui_utils';
|
||||||
import { createObjectURL } from '../../src/shared/util';
|
import { createObjectURL } from '../../src/shared/util';
|
||||||
import isNodeJS from '../../src/shared/is_node';
|
import { isNodeJS } from '../../src/shared/is_node';
|
||||||
|
|
||||||
describe('ui_utils', function() {
|
describe('ui_utils', function() {
|
||||||
describe('binary search', function() {
|
describe('binary search', function() {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals chrome */
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -30,6 +29,7 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
|
|||||||
let humanReadableUrl = '/' + defaultUrl + location.hash;
|
let humanReadableUrl = '/' + defaultUrl + location.hash;
|
||||||
history.replaceState(history.state, '', humanReadableUrl);
|
history.replaceState(history.state, '', humanReadableUrl);
|
||||||
if (top === window) {
|
if (top === window) {
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
chrome.runtime.sendMessage('showPageAction');
|
chrome.runtime.sendMessage('showPageAction');
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user