Merge pull request #4125 from yurydelendik/issue4111
Fixes and refactors log functionality
This commit is contained in:
		
						commit
						c57fdcceed
					
				@ -27,12 +27,14 @@
 | 
				
			|||||||
//
 | 
					//
 | 
				
			||||||
//var EXPORTED_SYMBOLS = ['NetworkManager'];
 | 
					//var EXPORTED_SYMBOLS = ['NetworkManager'];
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
//function log(aMsg) {
 | 
					//var console = {
 | 
				
			||||||
 | 
					//  log: function console_log(aMsg) {
 | 
				
			||||||
//    var msg = 'network.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
 | 
					//    var msg = 'network.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
 | 
				
			||||||
//    Services.console.logStringMessage(msg);
 | 
					//    Services.console.logStringMessage(msg);
 | 
				
			||||||
//    // TODO(mack): dump() doesn't seem to work here...
 | 
					//    // TODO(mack): dump() doesn't seem to work here...
 | 
				
			||||||
//    dump(msg + '\n');
 | 
					//    dump(msg + '\n');
 | 
				
			||||||
//  }
 | 
					//  }
 | 
				
			||||||
 | 
					//}
 | 
				
			||||||
//#endif
 | 
					//#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var NetworkManager = (function NetworkManagerClosure() {
 | 
					var NetworkManager = (function NetworkManagerClosure() {
 | 
				
			||||||
 | 
				
			|||||||
@ -16,7 +16,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
/* globals assertWellFormed, bytesToString, CipherTransformFactory, error, info,
 | 
					/* globals assertWellFormed, bytesToString, CipherTransformFactory, error, info,
 | 
				
			||||||
           InvalidPDFException, isArray, isCmd, isDict, isInt, isName, isRef,
 | 
					           InvalidPDFException, isArray, isCmd, isDict, isInt, isName, isRef,
 | 
				
			||||||
           isStream, Lexer, log, Page, Parser, Promise, shadow,
 | 
					           isStream, Lexer, Page, Parser, Promise, shadow,
 | 
				
			||||||
           stringToPDFString, stringToUTF8String, warn, isString, assert,
 | 
					           stringToPDFString, stringToUTF8String, warn, isString, assert,
 | 
				
			||||||
           Promise, MissingDataException, XRefParseException, Stream,
 | 
					           Promise, MissingDataException, XRefParseException, Stream,
 | 
				
			||||||
           ChunkedStream, LegacyPromise */
 | 
					           ChunkedStream, LegacyPromise */
 | 
				
			||||||
@ -999,7 +999,7 @@ var XRef = (function XRefClosure() {
 | 
				
			|||||||
        if (e instanceof MissingDataException) {
 | 
					        if (e instanceof MissingDataException) {
 | 
				
			||||||
          throw e;
 | 
					          throw e;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        log('(while reading XRef): ' + e);
 | 
					        info('(while reading XRef): ' + e);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (recoveryMode)
 | 
					      if (recoveryMode)
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@
 | 
				
			|||||||
 * 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 error, globalScope, InvalidPDFException, log,
 | 
					/* globals error, globalScope, InvalidPDFException, info,
 | 
				
			||||||
           MissingPDFException, PasswordException, PDFJS, Promise,
 | 
					           MissingPDFException, PasswordException, PDFJS, Promise,
 | 
				
			||||||
           UnknownErrorException, NetworkManager, LocalPdfManager,
 | 
					           UnknownErrorException, NetworkManager, LocalPdfManager,
 | 
				
			||||||
           NetworkPdfManager, XRefParseException, LegacyPromise,
 | 
					           NetworkPdfManager, XRefParseException, LegacyPromise,
 | 
				
			||||||
@ -332,7 +332,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
 | 
				
			|||||||
        // Pre compile the pdf page and fetch the fonts/images.
 | 
					        // Pre compile the pdf page and fetch the fonts/images.
 | 
				
			||||||
        page.getOperatorList(handler).then(function(operatorList) {
 | 
					        page.getOperatorList(handler).then(function(operatorList) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          log('page=%d - getOperatorList: time=%dms, len=%d', pageNum,
 | 
					          info('page=%d - getOperatorList: time=%dms, len=%d', pageNum,
 | 
				
			||||||
              Date.now() - start, operatorList.fnArray.length);
 | 
					              Date.now() - start, operatorList.fnArray.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }, function(e) {
 | 
					        }, function(e) {
 | 
				
			||||||
@ -374,7 +374,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
 | 
				
			|||||||
        var start = Date.now();
 | 
					        var start = Date.now();
 | 
				
			||||||
        page.extractTextContent().then(function(textContent) {
 | 
					        page.extractTextContent().then(function(textContent) {
 | 
				
			||||||
          deferred.resolve(textContent);
 | 
					          deferred.resolve(textContent);
 | 
				
			||||||
          log('text indexing: page=%d - time=%dms', pageNum,
 | 
					          info('text indexing: page=%d - time=%dms', pageNum,
 | 
				
			||||||
              Date.now() - start);
 | 
					              Date.now() - start);
 | 
				
			||||||
        }, function (e) {
 | 
					        }, function (e) {
 | 
				
			||||||
          // Skip errored pages
 | 
					          // Skip errored pages
 | 
				
			||||||
@ -422,15 +422,18 @@ var workerConsole = {
 | 
				
			|||||||
  timeEnd: function timeEnd(name) {
 | 
					  timeEnd: function timeEnd(name) {
 | 
				
			||||||
    var time = consoleTimer[name];
 | 
					    var time = consoleTimer[name];
 | 
				
			||||||
    if (!time) {
 | 
					    if (!time) {
 | 
				
			||||||
      error('Unkown timer name ' + name);
 | 
					      error('Unknown timer name ' + name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    this.log('Timer:', name, Date.now() - time);
 | 
					    this.log('Timer:', name, Date.now() - time);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Worker thread?
 | 
					// Worker thread?
 | 
				
			||||||
if (typeof window === 'undefined') {
 | 
					if (typeof window === 'undefined') {
 | 
				
			||||||
 | 
					  if (!('console' in globalScope)) {
 | 
				
			||||||
    globalScope.console = workerConsole;
 | 
					    globalScope.console = workerConsole;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Listen for unsupported features so we can pass them on to the main thread.
 | 
					  // Listen for unsupported features so we can pass them on to the main thread.
 | 
				
			||||||
  PDFJS.UnsupportedManager.listen(function (msg) {
 | 
					  PDFJS.UnsupportedManager.listen(function (msg) {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@
 | 
				
			|||||||
 * limitations under the License.
 | 
					 * limitations under the License.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
/* globals CFFDictDataMap, CFFDictPrivateDataMap, CFFEncodingMap, CFFStrings,
 | 
					/* globals CFFDictDataMap, CFFDictPrivateDataMap, CFFEncodingMap, CFFStrings,
 | 
				
			||||||
           Components, Dict, dump, error, isNum, log, netscape, Stream */
 | 
					           Components, Dict, dump, error, isNum, netscape, Stream */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'use strict';
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,7 +43,6 @@ function readCharset(aStream, aCharstrings) {
 | 
				
			|||||||
    for (var i = 1; i < count + 1; i++) {
 | 
					    for (var i = 1; i < count + 1; i++) {
 | 
				
			||||||
      var sid = aStream.getByte() << 8 | aStream.getByte();
 | 
					      var sid = aStream.getByte() << 8 | aStream.getByte();
 | 
				
			||||||
      charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
 | 
					      charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
 | 
				
			||||||
      //log(CFFStrings[sid] + "::" + charset[CFFStrings[sid]]);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } else if (format == 1) {
 | 
					  } else if (format == 1) {
 | 
				
			||||||
    for (var i = 1; i < count + 1; i++) {
 | 
					    for (var i = 1; i < count + 1; i++) {
 | 
				
			||||||
@ -52,8 +51,6 @@ function readCharset(aStream, aCharstrings) {
 | 
				
			|||||||
      var numLeft = aStream.getByte();
 | 
					      var numLeft = aStream.getByte();
 | 
				
			||||||
      for (var j = 0; j <= numLeft; j++) {
 | 
					      for (var j = 0; j <= numLeft; j++) {
 | 
				
			||||||
        var sid = first++;
 | 
					        var sid = first++;
 | 
				
			||||||
        if (CFFStrings[sid] == 'three')
 | 
					 | 
				
			||||||
          log(aCharstrings[j]);
 | 
					 | 
				
			||||||
        charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
 | 
					        charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -263,8 +260,9 @@ var Type2Parser = function type2Parser(aFilePath) {
 | 
				
			|||||||
  var debug = false;
 | 
					  var debug = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function dump(aStr) {
 | 
					  function dump(aStr) {
 | 
				
			||||||
    if (debug)
 | 
					    if (debug) {
 | 
				
			||||||
      log(aStr);
 | 
					      console.log(aStr);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function parseAsToken(aString, aMap) {
 | 
					  function parseAsToken(aString, aMap) {
 | 
				
			||||||
 | 
				
			|||||||
@ -146,30 +146,19 @@ var OPS = PDFJS.OPS = {
 | 
				
			|||||||
  paintInlineImageXObjectGroup: 87
 | 
					  paintInlineImageXObjectGroup: 87
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Use only for debugging purposes. This should not be used in any code that is
 | 
					 | 
				
			||||||
// in mozilla master.
 | 
					 | 
				
			||||||
var log = (function() {
 | 
					 | 
				
			||||||
  if ('console' in globalScope && 'log' in globalScope['console']) {
 | 
					 | 
				
			||||||
    return globalScope['console']['log'].bind(globalScope['console']);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    return function nop() {
 | 
					 | 
				
			||||||
    };
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
})();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// A notice for devs. These are good for things that are helpful to devs, such
 | 
					// A notice for devs. These are good for things that are helpful to devs, such
 | 
				
			||||||
// as warning that Workers were disabled, which is important to devs but not
 | 
					// as warning that Workers were disabled, which is important to devs but not
 | 
				
			||||||
// end users.
 | 
					// end users.
 | 
				
			||||||
function info(msg) {
 | 
					function info(msg) {
 | 
				
			||||||
  if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
 | 
					  if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
 | 
				
			||||||
    log('Info: ' + msg);
 | 
					    console.log('Info: ' + msg);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Non-fatal warnings.
 | 
					// Non-fatal warnings.
 | 
				
			||||||
function warn(msg) {
 | 
					function warn(msg) {
 | 
				
			||||||
  if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
 | 
					  if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
 | 
				
			||||||
    log('Warning: ' + msg);
 | 
					    console.log('Warning: ' + msg);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -180,13 +169,13 @@ function error(msg) {
 | 
				
			|||||||
  if (arguments.length > 1) {
 | 
					  if (arguments.length > 1) {
 | 
				
			||||||
    var logArguments = ['Error:'];
 | 
					    var logArguments = ['Error:'];
 | 
				
			||||||
    logArguments.push.apply(logArguments, arguments);
 | 
					    logArguments.push.apply(logArguments, arguments);
 | 
				
			||||||
    log.apply(null, logArguments);
 | 
					    console.log.apply(console, logArguments);
 | 
				
			||||||
    // Join the arguments into a single string for the lines below.
 | 
					    // Join the arguments into a single string for the lines below.
 | 
				
			||||||
    msg = [].join.call(arguments, ' ');
 | 
					    msg = [].join.call(arguments, ' ');
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    log('Error: ' + msg);
 | 
					    console.log('Error: ' + msg);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  log(backtrace());
 | 
					  console.log(backtrace());
 | 
				
			||||||
  UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
 | 
					  UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
 | 
				
			||||||
  throw new Error(msg);
 | 
					  throw new Error(msg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1213,19 +1202,11 @@ function MessageHandler(name, comObj) {
 | 
				
			|||||||
  var ah = this.actionHandler = {};
 | 
					  var ah = this.actionHandler = {};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ah['console_log'] = [function ahConsoleLog(data) {
 | 
					  ah['console_log'] = [function ahConsoleLog(data) {
 | 
				
			||||||
    log.apply(null, data);
 | 
					    console.log.apply(console, data);
 | 
				
			||||||
  }];
 | 
					  }];
 | 
				
			||||||
  // If there's no console available, console_error in the
 | 
					 | 
				
			||||||
  // action handler will do nothing.
 | 
					 | 
				
			||||||
  if ('console' in globalScope) {
 | 
					 | 
				
			||||||
  ah['console_error'] = [function ahConsoleError(data) {
 | 
					  ah['console_error'] = [function ahConsoleError(data) {
 | 
				
			||||||
      globalScope['console'].error.apply(null, data);
 | 
					    console.error.apply(console, data);
 | 
				
			||||||
  }];
 | 
					  }];
 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    ah['console_error'] = [function ahConsoleError(data) {
 | 
					 | 
				
			||||||
      log.apply(null, data);
 | 
					 | 
				
			||||||
    }];
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
 | 
					  ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
 | 
				
			||||||
    UnsupportedManager.notify(data);
 | 
					    UnsupportedManager.notify(data);
 | 
				
			||||||
  }];
 | 
					  }];
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user