Browse Source

Merge pull request #2058 from Pimm/master

Small fixes for normal and potential post-compilation bugs
Yury Delendik 13 years ago
parent
commit
75e928c102
  1. 7
      external/jpgjs/jpg.js
  2. 5
      src/api.js
  3. 2
      src/colorspace.js
  4. 2
      src/core.js
  5. 7
      src/fonts.js
  6. 2
      src/function.js
  7. 3
      src/jpx.js
  8. 25
      src/util.js
  9. 21
      src/worker.js

7
external/jpgjs/jpg.js vendored

@ -516,6 +516,10 @@ var JpegImage = (function jpegImage() {
return lines; return lines;
} }
function clampTo8bit(a) {
return a < 0 ? 0 : a > 255 ? 255 : a;
}
constructor.prototype = { constructor.prototype = {
load: function load(path) { load: function load(path) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@ -766,9 +770,6 @@ var JpegImage = (function jpegImage() {
} }
}, },
getData: function getData(width, height) { getData: function getData(width, height) {
function clampTo8bit(a) {
return a < 0 ? 0 : a > 255 ? 255 : a;
}
var scaleX = this.width / width, scaleY = this.height / height; var scaleX = this.width / width, scaleY = this.height / height;
var component1, component2, component3, component4; var component1, component2, component3, component4;

5
src/api.js

@ -361,8 +361,9 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
var length = this.operatorList.fnArray.length; var length = this.operatorList.fnArray.length;
var operatorList = this.operatorList; var operatorList = this.operatorList;
var stepper = null; var stepper = null;
if (PDFJS.pdfBug && StepperManager.enabled) { if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
stepper = StepperManager.create(this.pageNumber - 1); globalScope['StepperManager'].enabled) {
stepper = globalScope['StepperManager'].create(this.pageNumber - 1);
stepper.init(operatorList); stepper.init(operatorList);
stepper.nextBreakPoint = stepper.getNextBreakPoint(); stepper.nextBreakPoint = stepper.getNextBreakPoint();
} }

2
src/colorspace.js

@ -193,7 +193,7 @@ var ColorSpace = (function ColorSpaceClosure() {
return true; return true;
if (n * 2 !== decode.length) { if (n * 2 !== decode.length) {
warning('The decode map is not the correct length'); warn('The decode map is not the correct length');
return true; return true;
} }
for (var i = 0, ii = decode.length; i < ii; i += 2) { for (var i = 0, ii = decode.length; i < ii; i += 2) {

2
src/core.js

@ -236,7 +236,7 @@ var Page = (function PageClosure() {
}, },
getLinks: function Page_getLinks() { getLinks: function Page_getLinks() {
var links = []; var links = [];
var annotations = pageGetAnnotations(); var annotations = this.getAnnotations();
var i, n = annotations.length; var i, n = annotations.length;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
if (annotations[i].type != 'Link') if (annotations[i].type != 'Link')

7
src/fonts.js

@ -3174,8 +3174,9 @@ var Font = (function FontClosure() {
var styleSheet = styleElement.sheet; var styleSheet = styleElement.sheet;
styleSheet.insertRule(rule, styleSheet.cssRules.length); styleSheet.insertRule(rule, styleSheet.cssRules.length);
if (PDFJS.pdfBug && FontInspector.enabled) if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
FontInspector.fontAdded(this, url); globalScope['FontInspector'].enabled)
globalScope['FontInspector'].fontAdded(this, url);
return rule; return rule;
}, },
@ -4704,7 +4705,7 @@ var CFFParser = (function CFFParserClosure() {
var data = charstring; var data = charstring;
var length = data.length; var length = data.length;
for (var j = 0; j <= length; j) { for (var j = 0; j <= length;) {
var value = data[j++]; var value = data[j++];
if (value == 12 && data[j++] == 0) { if (value == 12 && data[j++] == 0) {
data[j - 2] = 139; data[j - 2] = 139;

2
src/function.js

@ -167,7 +167,7 @@ var PDFFunction = (function PDFFunctionClosure() {
var range = IR[9]; var range = IR[9];
if (m != args.length) if (m != args.length)
error('Incorrect number of arguments: ' + inputSize + ' != ' + error('Incorrect number of arguments: ' + m + ' != ' +
args.length); args.length);
var x = args; var x = args;

3
src/jpx.js

@ -269,7 +269,8 @@ var JpxImage = (function JpxImageClosure() {
cod.resetContextProbabilities || cod.resetContextProbabilities ||
cod.terminationOnEachCodingPass || cod.terminationOnEachCodingPass ||
cod.verticalyStripe || cod.predictableTermination) cod.verticalyStripe || cod.predictableTermination)
throw 'Unsupported COD options: ' + uneval(cod); throw 'Unsupported COD options: ' +
globalScope.JSON.stringify(cod);
if (context.mainHeader) if (context.mainHeader)
context.COD = cod; context.COD = cod;

25
src/util.js

@ -19,12 +19,16 @@
// Use only for debugging purposes. This should not be used in any code that is // Use only for debugging purposes. This should not be used in any code that is
// in mozilla master. // in mozilla master.
function log(msg) { var log = (function() {
if (console && console.log) if ('console' in globalScope && 'log' in globalScope['console']) {
console.log(msg); return globalScope['console']['log'].bind(globalScope['console']);
else if (print) } else if ('print' in globalScope) {
print(msg); return globalScope['print'].bind(globalScope);
} } else {
return function nop() {
};
}
})();
// A notice for devs that will not trigger the fallback UI. These are good // 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 // for things that are helpful to devs, such as warning that Workers were
@ -47,7 +51,16 @@ function warn(msg) {
// Fatal errors that should trigger the fallback UI and halt execution by // Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception. // throwing an exception.
function error(msg) { function error(msg) {
// If multiple arguments were passed, pass them all to the log function.
if (arguments.length > 1) {
var logArguments = ['Error:'];
logArguments.push.apply(logArguments, arguments);
log.apply(null, logArguments);
// Join the arguments into a single string for the lines below.
msg = [].join.call(arguments, ' ');
} else {
log('Error: ' + msg); log('Error: ' + msg);
}
log(backtrace()); log(backtrace());
PDFJS.LogManager.notify('error', msg); PDFJS.LogManager.notify('error', msg);
throw new Error(msg); throw new Error(msg);

21
src/worker.js

@ -25,11 +25,18 @@ function MessageHandler(name, comObj) {
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function ahConsoleLog(data) { ah['console_log'] = [function ahConsoleLog(data) {
console.log.apply(console, data); log.apply(null, 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) {
console.error.apply(console, data); globalScope['console'].error.apply(null, data);
}]; }];
} else {
ah['console_error'] = [function ahConsoleError(data) {
}];
}
ah['_warn'] = [function ah_Warn(data) { ah['_warn'] = [function ah_Warn(data) {
warn(data); warn(data);
}]; }];
@ -234,7 +241,7 @@ var WorkerMessageHandler = {
return; return;
} }
console.log('page=%d - getOperatorList: time=%dms, len=%d', pageNum, log('page=%d - getOperatorList: time=%dms, len=%d', pageNum,
Date.now() - start, operatorList.fnArray.length); Date.now() - start, operatorList.fnArray.length);
// Filter the dependecies for fonts. // Filter the dependecies for fonts.
@ -266,7 +273,7 @@ var WorkerMessageHandler = {
promise.reject(e); promise.reject(e);
} }
console.log('text indexing: page=%d - time=%dms', log('text indexing: page=%d - time=%dms',
pageNum, Date.now() - start); pageNum, Date.now() - start);
}); });
} }
@ -277,7 +284,7 @@ var consoleTimer = {};
var workerConsole = { var workerConsole = {
log: function log() { log: function log() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
postMessage({ globalScope.postMessage({
action: 'console_log', action: 'console_log',
data: args data: args
}); });
@ -285,7 +292,7 @@ var workerConsole = {
error: function error() { error: function error() {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
postMessage({ globalScope.postMessage({
action: 'console_error', action: 'console_error',
data: args data: args
}); });
@ -313,7 +320,7 @@ if (typeof window === 'undefined') {
// throw an exception which will be forwarded on automatically. // throw an exception which will be forwarded on automatically.
PDFJS.LogManager.addLogger({ PDFJS.LogManager.addLogger({
warn: function(msg) { warn: function(msg) {
postMessage({ globalScope.postMessage({
action: '_warn', action: '_warn',
data: msg data: msg
}); });

Loading…
Cancel
Save