Merge pull request #11316 from Snuffleupagus/globalScope-isNodeJS-modules

Convert `globalScope` and `isNodeJS` to proper modules
This commit is contained in:
Tim van der Meij 2019-11-10 19:43:01 +01:00 committed by GitHub
commit 21895aa75a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 81 additions and 75 deletions

View File

@ -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';
@ -581,7 +581,7 @@ function isMessagePort(maybePort) {
} }
// Worker thread (and not node.js)? // Worker thread (and not node.js)?
if (typeof window === 'undefined' && !isNodeJS() && if (typeof window === 'undefined' && !isNodeJS &&
typeof self !== 'undefined' && isMessagePort(self)) { typeof self !== 'undefined' && isMessagePort(self)) {
WorkerMessageHandler.initializeFromPort(self); WorkerMessageHandler.initializeFromPort(self);
} }

View File

@ -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';

View File

@ -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) || '';
@ -35,7 +35,7 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
// Support: Node.js // Support: Node.js
(function checkFontFaceAndImage() { (function checkFontFaceAndImage() {
// Node.js is missing native support for `@font-face` and `Image`. // Node.js is missing native support for `@font-face` and `Image`.
if (isNodeJS()) { if (isNodeJS) {
compatibilityParams.disableFontFace = true; compatibilityParams.disableFontFace = true;
compatibilityParams.nativeImageDecoderSupport = 'none'; compatibilityParams.nativeImageDecoderSupport = 'none';
} }

View File

@ -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');
@ -109,7 +109,7 @@ const convertImgDataToPng = (function() {
* http://www.libpng.org/pub/png/spec/1.2/PNG-Compression.html * http://www.libpng.org/pub/png/spec/1.2/PNG-Compression.html
*/ */
function deflateSync(literals) { function deflateSync(literals) {
if (!isNodeJS()) { if (!isNodeJS) {
// zlib is certainly not available outside of Node.js. We can either use // zlib is certainly not available outside of Node.js. We can either use
// the pako library for client-side DEFLATE compression, or use the canvas // the pako library for client-side DEFLATE compression, or use the canvas
// API of the browser to obtain a more optimal PNG file. // API of the browser to obtain a more optimal PNG file.

View File

@ -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.

View File

@ -31,8 +31,8 @@ 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) => {
return new PDFNodeStream(params); return new PDFNodeStream(params);

View File

@ -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,13 +22,13 @@ 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';
// Support: Node.js // Support: Node.js
(function checkNodeBtoa() { (function checkNodeBtoa() {
if (globalScope.btoa || !isNodeJS()) { if (globalScope.btoa || !isNodeJS) {
return; return;
} }
globalScope.btoa = function(chars) { globalScope.btoa = function(chars) {
@ -39,7 +39,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
// Support: Node.js // Support: Node.js
(function checkNodeAtob() { (function checkNodeAtob() {
if (globalScope.atob || !isNodeJS()) { if (globalScope.atob || !isNodeJS) {
return; return;
} }
globalScope.atob = function(input) { globalScope.atob = function(input) {
@ -69,7 +69,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
// one parameter, in legacy browsers. // one parameter, in legacy browsers.
// Support: IE // Support: IE
(function checkDOMTokenListAddRemove() { (function checkDOMTokenListAddRemove() {
if (!hasDOM || isNodeJS()) { if (!hasDOM || isNodeJS) {
return; return;
} }
const div = document.createElement('div'); const div = document.createElement('div');
@ -98,7 +98,7 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
// "force" parameter, in legacy browsers. // "force" parameter, in legacy browsers.
// Support: IE // Support: IE
(function checkDOMTokenListToggle() { (function checkDOMTokenListToggle() {
if (!hasDOM || isNodeJS()) { if (!hasDOM || isNodeJS) {
return; return;
} }
const div = document.createElement('div'); const div = document.createElement('div');

View File

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

View File

@ -12,13 +12,16 @@
* 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() { // 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 const isNodeJS =
return typeof process === 'object' && typeof process === 'object' &&
process + '' === '[object process]' && process + '' === '[object process]' &&
!process.versions['nw'] && !process.versions['electron']; !process.versions['nw'] && !process.versions['electron'];
export {
isNodeJS,
}; };

View File

@ -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() {
@ -40,7 +40,7 @@ describe('api', function() {
let CanvasFactory; let CanvasFactory;
beforeAll(function(done) { beforeAll(function(done) {
if (isNodeJS()) { if (isNodeJS) {
CanvasFactory = new NodeCanvasFactory(); CanvasFactory = new NodeCanvasFactory();
} else { } else {
CanvasFactory = new DOMCanvasFactory(); CanvasFactory = new DOMCanvasFactory();
@ -111,7 +111,7 @@ describe('api', function() {
}); });
it('creates pdf doc from typed array', function(done) { it('creates pdf doc from typed array', function(done) {
let typedArrayPdfPromise; let typedArrayPdfPromise;
if (isNodeJS()) { if (isNodeJS) {
typedArrayPdfPromise = NodeFileReaderFactory.fetch({ typedArrayPdfPromise = NodeFileReaderFactory.fetch({
path: TEST_PDFS_PATH.node + basicApiFileName, path: TEST_PDFS_PATH.node + basicApiFileName,
}); });
@ -296,7 +296,7 @@ describe('api', function() {
describe('PDFWorker', function() { describe('PDFWorker', function() {
it('worker created or destroyed', function (done) { it('worker created or destroyed', function (done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Worker is not supported in Node.js.'); pending('Worker is not supported in Node.js.');
} }
@ -315,7 +315,7 @@ describe('api', function() {
}).catch(done.fail); }).catch(done.fail);
}); });
it('worker created or destroyed by getDocument', function (done) { it('worker created or destroyed by getDocument', function (done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Worker is not supported in Node.js.'); pending('Worker is not supported in Node.js.');
} }
@ -337,7 +337,7 @@ describe('api', function() {
}).catch(done.fail); }).catch(done.fail);
}); });
it('worker created and can be used in getDocument', function (done) { it('worker created and can be used in getDocument', function (done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Worker is not supported in Node.js.'); pending('Worker is not supported in Node.js.');
} }
@ -364,7 +364,7 @@ describe('api', function() {
}).catch(done.fail); }).catch(done.fail);
}); });
it('creates more than one worker', function (done) { it('creates more than one worker', function (done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Worker is not supported in Node.js.'); pending('Worker is not supported in Node.js.');
} }
@ -384,7 +384,7 @@ describe('api', function() {
}).catch(done.fail); }).catch(done.fail);
}); });
it('gets current workerSrc', function() { it('gets current workerSrc', function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Worker is not supported in Node.js.'); pending('Worker is not supported in Node.js.');
} }
@ -955,7 +955,7 @@ describe('api', function() {
describe('Cross-origin', function() { describe('Cross-origin', function() {
var loadingTask; var loadingTask;
function _checkCanLoad(expectSuccess, filename, options) { function _checkCanLoad(expectSuccess, filename, options) {
if (isNodeJS()) { if (isNodeJS) {
pending('Cannot simulate cross-origin requests in Node.js'); pending('Cannot simulate cross-origin requests in Node.js');
} }
var params = buildGetDocumentParams(filename, options); var params = buildGetDocumentParams(filename, options);
@ -1551,7 +1551,7 @@ describe('api', function() {
beforeAll(function(done) { beforeAll(function(done) {
const fileName = 'tracemonkey.pdf'; const fileName = 'tracemonkey.pdf';
if (isNodeJS()) { if (isNodeJS) {
dataPromise = NodeFileReaderFactory.fetch({ dataPromise = NodeFileReaderFactory.fetch({
path: TEST_PDFS_PATH.node + fileName, path: TEST_PDFS_PATH.node + fileName,
}); });

View File

@ -14,12 +14,12 @@
*/ */
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';
// Ensure that this script only runs in Node.js environments. // Ensure that this script only runs in Node.js environments.
if (!isNodeJS()) { if (!isNodeJS) {
throw new Error('The `gulp unittestcli` command can only be used in ' + throw new Error('The `gulp unittestcli` command can only be used in ' +
'Node.js environments.'); 'Node.js environments.');
} }

View File

@ -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';
@ -32,7 +32,7 @@ describe('cmap', function() {
beforeAll(function (done) { beforeAll(function (done) {
// Allow CMap testing in Node.js, e.g. for Travis. // Allow CMap testing in Node.js, e.g. for Travis.
var CMapReaderFactory; var CMapReaderFactory;
if (isNodeJS()) { if (isNodeJS) {
CMapReaderFactory = new NodeCMapReaderFactory({ CMapReaderFactory = new NodeCMapReaderFactory({
baseUrl: cMapUrl.node, baseUrl: cMapUrl.node,
isCompressed: cMapPacked, isCompressed: cMapPacked,
@ -265,7 +265,7 @@ describe('cmap', function() {
it('attempts to load a built-in CMap without the necessary API parameters', it('attempts to load a built-in CMap without the necessary API parameters',
function(done) { function(done) {
function tmpFetchBuiltInCMap(name) { function tmpFetchBuiltInCMap(name) {
var CMapReaderFactory = isNodeJS() ? var CMapReaderFactory = isNodeJS ?
new NodeCMapReaderFactory({ }) : new DOMCMapReaderFactory({ }); new NodeCMapReaderFactory({ }) : new DOMCMapReaderFactory({ });
return CMapReaderFactory.fetch({ return CMapReaderFactory.fetch({
name, name,
@ -292,7 +292,7 @@ describe('cmap', function() {
function(done) { function(done) {
function tmpFetchBuiltInCMap(name) { function tmpFetchBuiltInCMap(name) {
let CMapReaderFactory; let CMapReaderFactory;
if (isNodeJS()) { if (isNodeJS) {
CMapReaderFactory = new NodeCMapReaderFactory({ CMapReaderFactory = new NodeCMapReaderFactory({
baseUrl: cMapUrl.node, baseUrl: cMapUrl.node,
isCompressed: false, isCompressed: false,

View File

@ -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);
@ -36,7 +36,7 @@ describe('custom canvas rendering', function() {
let page; let page;
beforeAll(function(done) { beforeAll(function(done) {
if (isNodeJS()) { if (isNodeJS) {
CanvasFactory = new NodeCanvasFactory(); CanvasFactory = new NodeCanvasFactory();
} else { } else {
CanvasFactory = new DOMCanvasFactory(); CanvasFactory = new DOMCanvasFactory();

View File

@ -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';
@ -30,14 +30,14 @@ function withZlib(isZlibRequired, callback) {
if (isZlibRequired) { if (isZlibRequired) {
// We could try to polyfill zlib in the browser, e.g. using pako. // We could try to polyfill zlib in the browser, e.g. using pako.
// For now, only support zlib functionality on Node.js // For now, only support zlib functionality on Node.js
if (!isNodeJS()) { if (!isNodeJS) {
throw new Error('zlib test can only be run in Node.js'); throw new Error('zlib test can only be run in Node.js');
} }
return callback(); return callback();
} }
if (!isNodeJS()) { if (!isNodeJS) {
// Assume that require('zlib') is unavailable in non-Node. // Assume that require('zlib') is unavailable in non-Node.
return callback(); return callback();
} }
@ -94,14 +94,14 @@ describe('SVGGraphics', function () {
// This points to the XObject image in xobject-image.pdf. // This points to the XObject image in xobject-image.pdf.
var xobjectObjId = 'img_p0_1'; var xobjectObjId = 'img_p0_1';
if (isNodeJS()) { if (isNodeJS) {
setStubs(global); setStubs(global);
} }
try { try {
var imgData = svgGfx.objs.get(xobjectObjId); var imgData = svgGfx.objs.get(xobjectObjId);
svgGfx.paintInlineImageXObject(imgData, elementContainer); svgGfx.paintInlineImageXObject(imgData, elementContainer);
} finally { } finally {
if (isNodeJS()) { if (isNodeJS) {
unsetStubs(global); unsetStubs(global);
} }
} }
@ -116,7 +116,7 @@ describe('SVGGraphics', function () {
// Verifies that the script loader replaces __non_webpack_require__ with // Verifies that the script loader replaces __non_webpack_require__ with
// require. // require.
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/); expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
if (isNodeJS()) { if (isNodeJS) {
expect(testFunc).not.toThrow(); expect(testFunc).not.toThrow();
} else { } else {
// require not defined, require('zlib') not a module, etc. // require not defined, require('zlib') not a module, etc.
@ -125,7 +125,7 @@ describe('SVGGraphics', function () {
}); });
it('should produce a reasonably small svg:image', function(done) { it('should produce a reasonably small svg:image', function(done) {
if (!isNodeJS()) { if (!isNodeJS) {
pending('zlib.deflateSync is not supported in non-Node environments.'); pending('zlib.deflateSync is not supported in non-Node environments.');
} }
withZlib(true, getSVGImage).then(function(svgImg) { withZlib(true, getSVGImage).then(function(svgImg) {

View File

@ -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() {
@ -48,7 +48,7 @@ describe('display_utils', function() {
it('`create` should return a canvas if the dimensions are valid', it('`create` should return a canvas if the dimensions are valid',
function() { function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Document is not supported in Node.js.'); pending('Document is not supported in Node.js.');
} }
@ -84,7 +84,7 @@ describe('display_utils', function() {
it('`reset` should alter the canvas/context if the dimensions are valid', it('`reset` should alter the canvas/context if the dimensions are valid',
function() { function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Document is not supported in Node.js.'); pending('Document is not supported in Node.js.');
} }
@ -105,7 +105,7 @@ describe('display_utils', function() {
}); });
it('`destroy` should clear the canvas/context', function() { it('`destroy` should clear the canvas/context', function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Document is not supported in Node.js.'); pending('Document is not supported in Node.js.');
} }
@ -145,7 +145,7 @@ describe('display_utils', function() {
it('`create` should return an SVG element if the dimensions are valid', it('`create` should return an SVG element if the dimensions are valid',
function() { function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Document is not supported in Node.js.'); pending('Document is not supported in Node.js.');
} }
@ -167,7 +167,7 @@ describe('display_utils', function() {
it('`createElement` should return an SVG element if the type is valid', it('`createElement` should return an SVG element if the type is valid',
function() { function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Document is not supported in Node.js.'); pending('Document is not supported in Node.js.');
} }

View File

@ -81,13 +81,13 @@ 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 ' +
'Node.js environments.'); 'Node.js environments.');
} }

View File

@ -15,11 +15,11 @@
/* 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.
assert(isNodeJS()); assert(isNodeJS);
let path = __non_webpack_require__('path'); let path = __non_webpack_require__('path');
let url = __non_webpack_require__('url'); let url = __non_webpack_require__('url');

View File

@ -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';
@ -51,7 +51,7 @@ const TEST_PDFS_PATH = {
function buildGetDocumentParams(filename, options) { function buildGetDocumentParams(filename, options) {
let params = Object.create(null); let params = Object.create(null);
if (isNodeJS()) { if (isNodeJS) {
params.url = TEST_PDFS_PATH.node + filename; params.url = TEST_PDFS_PATH.node + filename;
} else { } else {
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href; params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;

View File

@ -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() {
@ -156,7 +156,7 @@ describe('ui_utils', function() {
it('gets PDF filename from query string appended to "blob:" URL', it('gets PDF filename from query string appended to "blob:" URL',
function() { function() {
if (isNodeJS()) { if (isNodeJS) {
pending('Blob in not supported in Node.js.'); pending('Blob in not supported in Node.js.');
} }
var typedArray = new Uint8Array([1, 2, 3, 4, 5]); var typedArray = new Uint8Array([1, 2, 3, 4, 5]);
@ -283,7 +283,7 @@ describe('ui_utils', function() {
}); });
it('should not, by default, re-dispatch to DOM', function(done) { it('should not, by default, re-dispatch to DOM', function(done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Document in not supported in Node.js.'); pending('Document in not supported in Node.js.');
} }
const eventBus = new EventBus(); const eventBus = new EventBus();
@ -307,7 +307,7 @@ describe('ui_utils', function() {
}); });
}); });
it('should re-dispatch to DOM', function(done) { it('should re-dispatch to DOM', function(done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Document in not supported in Node.js.'); pending('Document in not supported in Node.js.');
} }
const eventBus = new EventBus({ dispatchToDOM: true, }); const eventBus = new EventBus({ dispatchToDOM: true, });
@ -333,7 +333,7 @@ describe('ui_utils', function() {
}); });
it('should re-dispatch to DOM, with arguments (without internal listeners)', it('should re-dispatch to DOM, with arguments (without internal listeners)',
function(done) { function(done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Document in not supported in Node.js.'); pending('Document in not supported in Node.js.');
} }
const eventBus = new EventBus({ dispatchToDOM: true, }); const eventBus = new EventBus({ dispatchToDOM: true, });
@ -447,7 +447,7 @@ describe('ui_utils', function() {
}); });
it('should resolve on event, using the DOM', function(done) { it('should resolve on event, using the DOM', function(done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Document in not supported in Node.js.'); pending('Document in not supported in Node.js.');
} }
let button = document.createElement('button'); let button = document.createElement('button');
@ -467,7 +467,7 @@ describe('ui_utils', function() {
}); });
it('should resolve on timeout, using the DOM', function(done) { it('should resolve on timeout, using the DOM', function(done) {
if (isNodeJS()) { if (isNodeJS) {
pending('Document in not supported in Node.js.'); pending('Document in not supported in Node.js.');
} }
let button = document.createElement('button'); let button = document.createElement('button');

View File

@ -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');
} }
})(); })();