mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything. Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite. Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle. For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly. Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
76 lines
3.5 KiB
JavaScript
76 lines
3.5 KiB
JavaScript
/* Copyright 2012 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.
|
|
*/
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
'use strict';
|
|
|
|
var pdfjsVersion =
|
|
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_VERSION') : void 0;
|
|
var pdfjsBuild =
|
|
typeof PDFJSDev !== 'undefined' ? PDFJSDev.eval('BUNDLE_BUILD') : void 0;
|
|
|
|
var pdfjsSharedUtil = require('./shared/util.js');
|
|
var pdfjsDisplayGlobal = require('./display/global.js');
|
|
var pdfjsDisplayAPI = require('./display/api.js');
|
|
var pdfjsDisplayTextLayer = require('./display/text_layer.js');
|
|
var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
|
|
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
|
|
var pdfjsDisplaySVG = require('./display/svg.js');
|
|
|
|
if (typeof PDFJSDev === 'undefined' ||
|
|
!PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
|
if (pdfjsSharedUtil.isNodeJS()) {
|
|
var PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
|
|
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNodeStream);
|
|
} else if (typeof Response !== 'undefined' && 'body' in Response.prototype &&
|
|
typeof ReadableStream !== 'undefined') {
|
|
var PDFFetchStream = require('./display/fetch_stream.js').PDFFetchStream;
|
|
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFFetchStream);
|
|
} else {
|
|
var PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
|
|
pdfjsDisplayAPI.setPDFNetworkStreamClass(PDFNetworkStream);
|
|
}
|
|
}
|
|
|
|
exports.PDFJS = pdfjsDisplayGlobal.PDFJS;
|
|
exports.build = pdfjsDisplayAPI.build;
|
|
exports.version = pdfjsDisplayAPI.version;
|
|
exports.getDocument = pdfjsDisplayAPI.getDocument;
|
|
exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort;
|
|
exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
|
|
exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
|
|
exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
|
|
exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
|
|
exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle;
|
|
exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
|
|
exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
|
|
exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
|
|
exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
|
|
exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
|
|
exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
|
|
exports.UnexpectedResponseException =
|
|
pdfjsSharedUtil.UnexpectedResponseException;
|
|
exports.OPS = pdfjsSharedUtil.OPS;
|
|
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
|
|
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
|
|
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
|
|
exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
|
|
exports.shadow = pdfjsSharedUtil.shadow;
|
|
exports.createBlob = pdfjsSharedUtil.createBlob;
|
|
exports.RenderingCancelledException =
|
|
pdfjsDisplayDOMUtils.RenderingCancelledException;
|
|
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
|
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|