Add new severity log info(). Change severity of some log messages. Trigger fallback on errors and warnings for extension.

This commit is contained in:
Brendan Dahl 2012-05-14 17:19:09 -07:00
parent fca6f352e4
commit 034583e1a1
11 changed files with 128 additions and 62 deletions

View file

@ -3,6 +3,8 @@
'use strict';
// Use only for debugging purposes. This should not be used in any code that is
// in mozilla master.
function log(msg) {
if (console && console.log)
console.log(msg);
@ -10,9 +12,36 @@ function log(msg) {
print(msg);
}
// A notice for devs that will not trigger the fallback UI. 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 (verbosity >= INFOS) {
log('Info: ' + msg);
PDFJS.LogManager.notify('info', msg);
}
}
// Non-fatal warnings that should trigger the fallback UI.
function warn(msg) {
if (verbosity >= WARNINGS)
if (verbosity >= WARNINGS) {
log('Warning: ' + msg);
PDFJS.LogManager.notify('warn', msg);
}
}
// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
log('Error: ' + msg);
log(backtrace());
PDFJS.LogManager.notify('error', msg);
throw new Error(msg);
}
// Missing features that should trigger the fallback UI.
function TODO(what) {
warn('TODO: ' + what);
}
function backtrace() {
@ -23,21 +52,6 @@ function backtrace() {
}
}
function error(msg) {
log('Error: ' + msg);
log(backtrace());
throw new Error(msg);
}
function TODO(what) {
if (verbosity >= TODOS)
log('TODO: ' + what);
}
function malformed(msg) {
error('Malformed PDF: ' + msg);
}
function assert(cond, msg) {
if (!cond)
error(msg);
@ -47,9 +61,25 @@ function assert(cond, msg) {
// behavior is undefined.
function assertWellFormed(cond, msg) {
if (!cond)
malformed(msg);
error(msg);
}
var LogManager = PDFJS.LogManager = (function LogManagerClosure() {
var loggers = [];
return {
addLogger: function logManager_addLogger(logger) {
loggers.push(logger);
},
notify: function(type, message) {
for (var i = 0, ii = loggers.length; i < ii; i++) {
var logger = loggers[i];
if (logger[type])
logger[type](message);
}
}
};
})();
function shadow(obj, prop, value) {
Object.defineProperty(obj, prop, { value: value,
enumerable: true,