mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 15:48:06 +02:00
Change isNodeJS
from a function to a constant
Given that this shouldn't change after the `pdf.js`/`pdf.worker.js` files have been loaded, it doesn't seems necessary to keep this as a function.
This commit is contained in:
parent
2817121bc1
commit
74e00ed93c
16 changed files with 49 additions and 50 deletions
|
@ -40,7 +40,7 @@ describe('api', function() {
|
|||
let CanvasFactory;
|
||||
|
||||
beforeAll(function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
CanvasFactory = new NodeCanvasFactory();
|
||||
} else {
|
||||
CanvasFactory = new DOMCanvasFactory();
|
||||
|
@ -111,7 +111,7 @@ describe('api', function() {
|
|||
});
|
||||
it('creates pdf doc from typed array', function(done) {
|
||||
let typedArrayPdfPromise;
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
typedArrayPdfPromise = NodeFileReaderFactory.fetch({
|
||||
path: TEST_PDFS_PATH.node + basicApiFileName,
|
||||
});
|
||||
|
@ -296,7 +296,7 @@ describe('api', function() {
|
|||
|
||||
describe('PDFWorker', function() {
|
||||
it('worker created or destroyed', function (done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Worker is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ describe('api', function() {
|
|||
}).catch(done.fail);
|
||||
});
|
||||
it('worker created or destroyed by getDocument', function (done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Worker is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ describe('api', function() {
|
|||
}).catch(done.fail);
|
||||
});
|
||||
it('worker created and can be used in getDocument', function (done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Worker is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ describe('api', function() {
|
|||
}).catch(done.fail);
|
||||
});
|
||||
it('creates more than one worker', function (done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Worker is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ describe('api', function() {
|
|||
}).catch(done.fail);
|
||||
});
|
||||
it('gets current workerSrc', function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Worker is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -955,7 +955,7 @@ describe('api', function() {
|
|||
describe('Cross-origin', function() {
|
||||
var loadingTask;
|
||||
function _checkCanLoad(expectSuccess, filename, options) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Cannot simulate cross-origin requests in Node.js');
|
||||
}
|
||||
var params = buildGetDocumentParams(filename, options);
|
||||
|
@ -1551,7 +1551,7 @@ describe('api', function() {
|
|||
|
||||
beforeAll(function(done) {
|
||||
const fileName = 'tracemonkey.pdf';
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
dataPromise = NodeFileReaderFactory.fetch({
|
||||
path: TEST_PDFS_PATH.node + fileName,
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ import { PDFNodeStream } from '../../src/display/node_stream';
|
|||
import { setPDFNetworkStreamFactory } from '../../src/display/api';
|
||||
|
||||
// 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 ' +
|
||||
'Node.js environments.');
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ describe('cmap', function() {
|
|||
beforeAll(function (done) {
|
||||
// Allow CMap testing in Node.js, e.g. for Travis.
|
||||
var CMapReaderFactory;
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
CMapReaderFactory = new NodeCMapReaderFactory({
|
||||
baseUrl: cMapUrl.node,
|
||||
isCompressed: cMapPacked,
|
||||
|
@ -265,7 +265,7 @@ describe('cmap', function() {
|
|||
it('attempts to load a built-in CMap without the necessary API parameters',
|
||||
function(done) {
|
||||
function tmpFetchBuiltInCMap(name) {
|
||||
var CMapReaderFactory = isNodeJS() ?
|
||||
var CMapReaderFactory = isNodeJS ?
|
||||
new NodeCMapReaderFactory({ }) : new DOMCMapReaderFactory({ });
|
||||
return CMapReaderFactory.fetch({
|
||||
name,
|
||||
|
@ -292,7 +292,7 @@ describe('cmap', function() {
|
|||
function(done) {
|
||||
function tmpFetchBuiltInCMap(name) {
|
||||
let CMapReaderFactory;
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
CMapReaderFactory = new NodeCMapReaderFactory({
|
||||
baseUrl: cMapUrl.node,
|
||||
isCompressed: false,
|
||||
|
|
|
@ -36,7 +36,7 @@ describe('custom canvas rendering', function() {
|
|||
let page;
|
||||
|
||||
beforeAll(function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
CanvasFactory = new NodeCanvasFactory();
|
||||
} else {
|
||||
CanvasFactory = new DOMCanvasFactory();
|
||||
|
|
|
@ -30,14 +30,14 @@ function withZlib(isZlibRequired, callback) {
|
|||
if (isZlibRequired) {
|
||||
// We could try to polyfill zlib in the browser, e.g. using pako.
|
||||
// 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');
|
||||
}
|
||||
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (!isNodeJS()) {
|
||||
if (!isNodeJS) {
|
||||
// Assume that require('zlib') is unavailable in non-Node.
|
||||
return callback();
|
||||
}
|
||||
|
@ -94,14 +94,14 @@ describe('SVGGraphics', function () {
|
|||
|
||||
// This points to the XObject image in xobject-image.pdf.
|
||||
var xobjectObjId = 'img_p0_1';
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
setStubs(global);
|
||||
}
|
||||
try {
|
||||
var imgData = svgGfx.objs.get(xobjectObjId);
|
||||
svgGfx.paintInlineImageXObject(imgData, elementContainer);
|
||||
} finally {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
unsetStubs(global);
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ describe('SVGGraphics', function () {
|
|||
// Verifies that the script loader replaces __non_webpack_require__ with
|
||||
// require.
|
||||
expect(testFunc.toString()).toMatch(/\srequire\(["']zlib["']\)/);
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
expect(testFunc).not.toThrow();
|
||||
} else {
|
||||
// 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) {
|
||||
if (!isNodeJS()) {
|
||||
if (!isNodeJS) {
|
||||
pending('zlib.deflateSync is not supported in non-Node environments.');
|
||||
}
|
||||
withZlib(true, getSVGImage).then(function(svgImg) {
|
||||
|
|
|
@ -48,7 +48,7 @@ describe('display_utils', function() {
|
|||
|
||||
it('`create` should return a canvas if the dimensions are valid',
|
||||
function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
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',
|
||||
function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ describe('display_utils', function() {
|
|||
});
|
||||
|
||||
it('`destroy` should clear the canvas/context', function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
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',
|
||||
function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
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',
|
||||
function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document is not supported in Node.js.');
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ function initializePDFJS(callback) {
|
|||
const { PDFFetchStream, } = modules[3];
|
||||
const { isNodeJS, } = modules[4];
|
||||
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
throw new Error('The `gulp unittest` command cannot be used in ' +
|
||||
'Node.js environments.');
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import { isNodeJS } from '../../src/shared/is_node';
|
|||
import { PDFNodeStream } from '../../src/display/node_stream';
|
||||
|
||||
// Make sure that we only running this script is Node.js environments.
|
||||
assert(isNodeJS());
|
||||
assert(isNodeJS);
|
||||
|
||||
let path = __non_webpack_require__('path');
|
||||
let url = __non_webpack_require__('url');
|
||||
|
|
|
@ -51,7 +51,7 @@ const TEST_PDFS_PATH = {
|
|||
|
||||
function buildGetDocumentParams(filename, options) {
|
||||
let params = Object.create(null);
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
params.url = TEST_PDFS_PATH.node + filename;
|
||||
} else {
|
||||
params.url = new URL(TEST_PDFS_PATH.dom + filename, window.location).href;
|
||||
|
|
|
@ -156,7 +156,7 @@ describe('ui_utils', function() {
|
|||
|
||||
it('gets PDF filename from query string appended to "blob:" URL',
|
||||
function() {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Blob in not supported in Node.js.');
|
||||
}
|
||||
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) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
const eventBus = new EventBus();
|
||||
|
@ -307,7 +307,7 @@ describe('ui_utils', function() {
|
|||
});
|
||||
});
|
||||
it('should re-dispatch to DOM', function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
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)',
|
||||
function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
const eventBus = new EventBus({ dispatchToDOM: true, });
|
||||
|
@ -447,7 +447,7 @@ describe('ui_utils', function() {
|
|||
});
|
||||
|
||||
it('should resolve on event, using the DOM', function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
let button = document.createElement('button');
|
||||
|
@ -467,7 +467,7 @@ describe('ui_utils', function() {
|
|||
});
|
||||
|
||||
it('should resolve on timeout, using the DOM', function(done) {
|
||||
if (isNodeJS()) {
|
||||
if (isNodeJS) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
let button = document.createElement('button');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue