Move the verbosity option from the global PDFJS object and into getDocument/PDFWorker instead
				
					
				
			Given the purpose of this option, it doesn't seem necessary to make it available through `GlobalWorkerOptions`.
This commit is contained in:
		
							parent
							
								
									fdd2376170
								
							
						
					
					
						commit
						a97901efb6
					
				@ -16,9 +16,10 @@
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
 | 
			
		||||
  isArrayBuffer, isSameOrigin, MessageHandler, MissingPDFException,
 | 
			
		||||
  NativeImageDecoding, PageViewport, PasswordException, stringToBytes,
 | 
			
		||||
  UnexpectedResponseException, UnknownErrorException, unreachable, Util, warn
 | 
			
		||||
  isArrayBuffer, isNum, isSameOrigin, MessageHandler, MissingPDFException,
 | 
			
		||||
  NativeImageDecoding, PageViewport, PasswordException, setVerbosityLevel,
 | 
			
		||||
  stringToBytes, UnexpectedResponseException, UnknownErrorException,
 | 
			
		||||
  unreachable, Util, warn
 | 
			
		||||
} from '../shared/util';
 | 
			
		||||
import {
 | 
			
		||||
  DOMCanvasFactory, DOMCMapReaderFactory, DummyStatTimer, getDefaultSetting,
 | 
			
		||||
@ -128,6 +129,8 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
 | 
			
		||||
 *   the loading and parsing of the PDF data.
 | 
			
		||||
 * @property {boolean} postMessageTransfers - (optional) Enables transfer usage
 | 
			
		||||
 *   in postMessage for ArrayBuffers. The default value is `true`.
 | 
			
		||||
 * @property {number} verbosity - (optional) Controls the logging level; the
 | 
			
		||||
 *   constants from {VerbosityLevel} should be used.
 | 
			
		||||
 * @property {string} docBaseUrl - (optional) The base URL of the document,
 | 
			
		||||
 *   used when attempting to recover valid absolute URLs for annotations, and
 | 
			
		||||
 *   outline items, that (incorrectly) only specify relative URLs.
 | 
			
		||||
@ -240,9 +243,13 @@ function getDocument(src) {
 | 
			
		||||
    params.nativeImageDecoderSupport = NativeImageDecoding.DECODE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Set the main-thread verbosity level.
 | 
			
		||||
  setVerbosityLevel(params.verbosity);
 | 
			
		||||
 | 
			
		||||
  if (!worker) {
 | 
			
		||||
    const workerParams = {
 | 
			
		||||
      postMessageTransfers: params.postMessageTransfers,
 | 
			
		||||
      verbosity: params.verbosity,
 | 
			
		||||
    };
 | 
			
		||||
    // Worker was not provided -- creating and owning our own. If message port
 | 
			
		||||
    // is specified in global worker options, using it.
 | 
			
		||||
@ -1206,6 +1213,8 @@ class LoopbackPort {
 | 
			
		||||
 * @property {Object} port - (optional) The `workerPort`.
 | 
			
		||||
 * @property {boolean} postMessageTransfers - (optional) Enables transfer usage
 | 
			
		||||
 *   in postMessage for ArrayBuffers. The default value is `true`.
 | 
			
		||||
 * @property {number} verbosity - (optional) Controls the logging level; the
 | 
			
		||||
 *   constants from {VerbosityLevel} should be used.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -1300,7 +1309,7 @@ var PDFWorker = (function PDFWorkerClosure() {
 | 
			
		||||
   * @param {PDFWorkerParameters} params - The worker initialization parameters.
 | 
			
		||||
   */
 | 
			
		||||
  function PDFWorker({ name = null, port = null,
 | 
			
		||||
                       postMessageTransfers = true, } = {}) {
 | 
			
		||||
                       postMessageTransfers = true, verbosity = null, } = {}) {
 | 
			
		||||
    if (port && pdfWorkerPorts.has(port)) {
 | 
			
		||||
      throw new Error('Cannot use more than one PDFWorker per port');
 | 
			
		||||
    }
 | 
			
		||||
@ -1308,6 +1317,7 @@ var PDFWorker = (function PDFWorkerClosure() {
 | 
			
		||||
    this.name = name;
 | 
			
		||||
    this.destroyed = false;
 | 
			
		||||
    this.postMessageTransfers = postMessageTransfers !== false;
 | 
			
		||||
    this.verbosity = (isNum(verbosity) ? verbosity : getVerbosityLevel());
 | 
			
		||||
 | 
			
		||||
    this._readyCapability = createPromiseCapability();
 | 
			
		||||
    this._port = null;
 | 
			
		||||
@ -1408,7 +1418,7 @@ var PDFWorker = (function PDFWorkerClosure() {
 | 
			
		||||
              this._readyCapability.resolve();
 | 
			
		||||
              // Send global setting, e.g. verbosity level.
 | 
			
		||||
              messageHandler.send('configure', {
 | 
			
		||||
                verbosity: getVerbosityLevel(),
 | 
			
		||||
                verbosity: this.verbosity,
 | 
			
		||||
              });
 | 
			
		||||
            } else {
 | 
			
		||||
              this._setupFakeWorker();
 | 
			
		||||
 | 
			
		||||
@ -14,11 +14,10 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import {
 | 
			
		||||
  createBlob, createObjectURL, createPromiseCapability, getVerbosityLevel,
 | 
			
		||||
  InvalidPDFException, isLittleEndian, MissingPDFException, OPS, PageViewport,
 | 
			
		||||
  PasswordException, PasswordResponses, removeNullCharacters, setVerbosityLevel,
 | 
			
		||||
  shadow, UnexpectedResponseException, UnknownErrorException,
 | 
			
		||||
  UNSUPPORTED_FEATURES, Util, VERBOSITY_LEVELS
 | 
			
		||||
  createBlob, createObjectURL, createPromiseCapability, InvalidPDFException,
 | 
			
		||||
  isLittleEndian, MissingPDFException, OPS, PageViewport, PasswordException,
 | 
			
		||||
  PasswordResponses, removeNullCharacters, shadow, UnexpectedResponseException,
 | 
			
		||||
  UnknownErrorException, UNSUPPORTED_FEATURES, Util
 | 
			
		||||
} from '../shared/util';
 | 
			
		||||
import { DEFAULT_LINK_REL, getFilenameFromUrl, LinkTarget } from './dom_utils';
 | 
			
		||||
import {
 | 
			
		||||
@ -42,22 +41,6 @@ var PDFJS = globalScope.PDFJS;
 | 
			
		||||
 | 
			
		||||
PDFJS.pdfBug = false;
 | 
			
		||||
 | 
			
		||||
if (PDFJS.verbosity !== undefined) {
 | 
			
		||||
  setVerbosityLevel(PDFJS.verbosity);
 | 
			
		||||
}
 | 
			
		||||
delete PDFJS.verbosity;
 | 
			
		||||
Object.defineProperty(PDFJS, 'verbosity', {
 | 
			
		||||
  get() {
 | 
			
		||||
    return getVerbosityLevel();
 | 
			
		||||
  },
 | 
			
		||||
  set(level) {
 | 
			
		||||
    setVerbosityLevel(level);
 | 
			
		||||
  },
 | 
			
		||||
  enumerable: true,
 | 
			
		||||
  configurable: true,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
PDFJS.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
 | 
			
		||||
PDFJS.OPS = OPS;
 | 
			
		||||
PDFJS.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
 | 
			
		||||
PDFJS.shadow = shadow;
 | 
			
		||||
 | 
			
		||||
@ -23,20 +23,10 @@
 | 
			
		||||
 * to the PDF.js.
 | 
			
		||||
 * @constructor
 | 
			
		||||
 */
 | 
			
		||||
function PDFJS() {
 | 
			
		||||
function PDFJS() { // eslint-disable-line no-unused-vars
 | 
			
		||||
  // Mock class constructor. See src/display/api.js.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Controls the logging level.
 | 
			
		||||
 * The constants from PDFJS.VERBOSITY_LEVELS should be used:
 | 
			
		||||
 * - errors
 | 
			
		||||
 * - warnings [default]
 | 
			
		||||
 * - infos
 | 
			
		||||
 * @var {number}
 | 
			
		||||
 */
 | 
			
		||||
PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.warnings;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Represents the eventual result of an asynchronous operation.
 | 
			
		||||
 * @external Promise
 | 
			
		||||
 | 
			
		||||
@ -83,6 +83,7 @@ exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
 | 
			
		||||
exports.UnexpectedResponseException =
 | 
			
		||||
  pdfjsSharedUtil.UnexpectedResponseException;
 | 
			
		||||
exports.OPS = pdfjsSharedUtil.OPS;
 | 
			
		||||
exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel;
 | 
			
		||||
exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
 | 
			
		||||
exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
 | 
			
		||||
exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
 | 
			
		||||
 | 
			
		||||
@ -142,10 +142,10 @@ var FontType = {
 | 
			
		||||
  MMTYPE1: 10,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var VERBOSITY_LEVELS = {
 | 
			
		||||
  errors: 0,
 | 
			
		||||
  warnings: 1,
 | 
			
		||||
  infos: 5,
 | 
			
		||||
const VerbosityLevel = {
 | 
			
		||||
  ERRORS: 0,
 | 
			
		||||
  WARNINGS: 1,
 | 
			
		||||
  INFOS: 5,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var CMapCompressionType = {
 | 
			
		||||
@ -251,10 +251,12 @@ var OPS = {
 | 
			
		||||
  constructPath: 91,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
var verbosity = VERBOSITY_LEVELS.warnings;
 | 
			
		||||
let verbosity = VerbosityLevel.WARNINGS;
 | 
			
		||||
 | 
			
		||||
function setVerbosityLevel(level) {
 | 
			
		||||
  verbosity = level;
 | 
			
		||||
  if (Number.isInteger(level)) {
 | 
			
		||||
    verbosity = level;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getVerbosityLevel() {
 | 
			
		||||
@ -265,19 +267,19 @@ function getVerbosityLevel() {
 | 
			
		||||
// as warning that Workers were disabled, which is important to devs but not
 | 
			
		||||
// end users.
 | 
			
		||||
function info(msg) {
 | 
			
		||||
  if (verbosity >= VERBOSITY_LEVELS.infos) {
 | 
			
		||||
  if (verbosity >= VerbosityLevel.INFOS) {
 | 
			
		||||
    console.log('Info: ' + msg);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Non-fatal warnings.
 | 
			
		||||
function warn(msg) {
 | 
			
		||||
  if (verbosity >= VERBOSITY_LEVELS.warnings) {
 | 
			
		||||
  if (verbosity >= VerbosityLevel.WARNINGS) {
 | 
			
		||||
    console.log('Warning: ' + msg);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Deprecated API function -- display regardless of the PDFJS.verbosity setting.
 | 
			
		||||
// Deprecated API function -- display regardless of the `verbosity` setting.
 | 
			
		||||
function deprecated(details) {
 | 
			
		||||
  console.log('Deprecated API usage: ' + details);
 | 
			
		||||
}
 | 
			
		||||
@ -1573,7 +1575,7 @@ export {
 | 
			
		||||
  FONT_IDENTITY_MATRIX,
 | 
			
		||||
  IDENTITY_MATRIX,
 | 
			
		||||
  OPS,
 | 
			
		||||
  VERBOSITY_LEVELS,
 | 
			
		||||
  VerbosityLevel,
 | 
			
		||||
  UNSUPPORTED_FEATURES,
 | 
			
		||||
  AnnotationBorderStyleType,
 | 
			
		||||
  AnnotationFieldFlag,
 | 
			
		||||
 | 
			
		||||
@ -740,6 +740,8 @@ let PDFViewerApplication = {
 | 
			
		||||
               PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
 | 
			
		||||
      parameters.docBaseUrl = this.baseUrl;
 | 
			
		||||
    }
 | 
			
		||||
    // TODO: Remove this once all options are moved from the `PDFJS` object.
 | 
			
		||||
    parameters.verbosity = PDFJS.verbosity;
 | 
			
		||||
 | 
			
		||||
    if (args) {
 | 
			
		||||
      for (let prop in args) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user