Fixes and refactors log functionality

This commit is contained in:
Yury Delendik 2014-01-15 15:28:31 -06:00
parent ab4f27b272
commit 754e000907
5 changed files with 30 additions and 46 deletions

View file

@ -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);
}
@ -1214,19 +1203,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);
}];