mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Merge pull request #4125 from yurydelendik/issue4111
Fixes and refactors log functionality
This commit is contained in:
commit
c57fdcceed
5 changed files with 30 additions and 46 deletions
|
@ -146,30 +146,19 @@ var OPS = PDFJS.OPS = {
|
|||
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
|
||||
// as warning that Workers were disabled, which is important to devs but not
|
||||
// end users.
|
||||
function info(msg) {
|
||||
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
|
||||
log('Info: ' + msg);
|
||||
console.log('Info: ' + msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Non-fatal warnings.
|
||||
function warn(msg) {
|
||||
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) {
|
||||
var logArguments = ['Error:'];
|
||||
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.
|
||||
msg = [].join.call(arguments, ' ');
|
||||
} else {
|
||||
log('Error: ' + msg);
|
||||
console.log('Error: ' + msg);
|
||||
}
|
||||
log(backtrace());
|
||||
console.log(backtrace());
|
||||
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
@ -1213,19 +1202,11 @@ function MessageHandler(name, comObj) {
|
|||
var ah = this.actionHandler = {};
|
||||
|
||||
ah['console_log'] = [function ahConsoleLog(data) {
|
||||
log.apply(null, data);
|
||||
console.log.apply(console, data);
|
||||
}];
|
||||
ah['console_error'] = [function ahConsoleError(data) {
|
||||
console.error.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) {
|
||||
globalScope['console'].error.apply(null, data);
|
||||
}];
|
||||
} else {
|
||||
ah['console_error'] = [function ahConsoleError(data) {
|
||||
log.apply(null, data);
|
||||
}];
|
||||
}
|
||||
ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
|
||||
UnsupportedManager.notify(data);
|
||||
}];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue