Browse Source

Merge pull request #4125 from yurydelendik/issue4111

Fixes and refactors log functionality
Brendan Dahl 11 years ago
parent
commit
c57fdcceed
  1. 4
      src/core/network.js
  2. 4
      src/core/obj.js
  3. 11
      src/core/worker.js
  4. 10
      src/shared/fonts_utils.js
  5. 33
      src/shared/util.js

4
src/core/network.js

@ -27,11 +27,13 @@ @@ -27,11 +27,13 @@
//
//var EXPORTED_SYMBOLS = ['NetworkManager'];
//
//function log(aMsg) {
//var console = {
// log: function console_log(aMsg) {
// var msg = 'network.js: ' + (aMsg.join ? aMsg.join('') : aMsg);
// Services.console.logStringMessage(msg);
// // TODO(mack): dump() doesn't seem to work here...
// dump(msg + '\n');
// }
//}
//#endif

4
src/core/obj.js

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
*/
/* globals assertWellFormed, bytesToString, CipherTransformFactory, error, info,
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,
Promise, MissingDataException, XRefParseException, Stream,
ChunkedStream, LegacyPromise */
@ -999,7 +999,7 @@ var XRef = (function XRefClosure() { @@ -999,7 +999,7 @@ var XRef = (function XRefClosure() {
if (e instanceof MissingDataException) {
throw e;
}
log('(while reading XRef): ' + e);
info('(while reading XRef): ' + e);
}
if (recoveryMode)

11
src/core/worker.js

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals error, globalScope, InvalidPDFException, log,
/* globals error, globalScope, InvalidPDFException, info,
MissingPDFException, PasswordException, PDFJS, Promise,
UnknownErrorException, NetworkManager, LocalPdfManager,
NetworkPdfManager, XRefParseException, LegacyPromise,
@ -332,7 +332,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = { @@ -332,7 +332,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
// Pre compile the pdf page and fetch the fonts/images.
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);
}, function(e) {
@ -374,7 +374,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = { @@ -374,7 +374,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
var start = Date.now();
page.extractTextContent().then(function(textContent) {
deferred.resolve(textContent);
log('text indexing: page=%d - time=%dms', pageNum,
info('text indexing: page=%d - time=%dms', pageNum,
Date.now() - start);
}, function (e) {
// Skip errored pages
@ -422,15 +422,18 @@ var workerConsole = { @@ -422,15 +422,18 @@ var workerConsole = {
timeEnd: function timeEnd(name) {
var time = consoleTimer[name];
if (!time) {
error('Unkown timer name ' + name);
error('Unknown timer name ' + name);
}
this.log('Timer:', name, Date.now() - time);
}
};
// Worker thread?
if (typeof window === 'undefined') {
if (!('console' in globalScope)) {
globalScope.console = workerConsole;
}
// Listen for unsupported features so we can pass them on to the main thread.
PDFJS.UnsupportedManager.listen(function (msg) {

10
src/shared/fonts_utils.js

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
* limitations under the License.
*/
/* globals CFFDictDataMap, CFFDictPrivateDataMap, CFFEncodingMap, CFFStrings,
Components, Dict, dump, error, isNum, log, netscape, Stream */
Components, Dict, dump, error, isNum, netscape, Stream */
'use strict';
@ -43,7 +43,6 @@ function readCharset(aStream, aCharstrings) { @@ -43,7 +43,6 @@ function readCharset(aStream, aCharstrings) {
for (var i = 1; i < count + 1; i++) {
var sid = aStream.getByte() << 8 | aStream.getByte();
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[i]);
//log(CFFStrings[sid] + "::" + charset[CFFStrings[sid]]);
}
} else if (format == 1) {
for (var i = 1; i < count + 1; i++) {
@ -52,8 +51,6 @@ function readCharset(aStream, aCharstrings) { @@ -52,8 +51,6 @@ function readCharset(aStream, aCharstrings) {
var numLeft = aStream.getByte();
for (var j = 0; j <= numLeft; j++) {
var sid = first++;
if (CFFStrings[sid] == 'three')
log(aCharstrings[j]);
charset[CFFStrings[sid]] = readCharstringEncoding(aCharstrings[j]);
}
}
@ -263,8 +260,9 @@ var Type2Parser = function type2Parser(aFilePath) { @@ -263,8 +260,9 @@ var Type2Parser = function type2Parser(aFilePath) {
var debug = false;
function dump(aStr) {
if (debug)
log(aStr);
if (debug) {
console.log(aStr);
}
}
function parseAsToken(aString, aMap) {

33
src/shared/util.js

@ -146,30 +146,19 @@ var OPS = PDFJS.OPS = { @@ -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) { @@ -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) { @@ -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);
}];
// 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);
console.error.apply(console, data);
}];
} else {
ah['console_error'] = [function ahConsoleError(data) {
log.apply(null, data);
}];
}
ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
UnsupportedManager.notify(data);
}];

Loading…
Cancel
Save