[Pkg-javascript-commits] [pdf.js] 272/414: Better errors capturing at the core and stop rendering on error.
David Prévot
taffit at moszumanska.debian.org
Tue Jun 28 17:12:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit 8ba413e761e252475911e14cd921126e05a187ab
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Fri Mar 11 07:59:09 2016 -0600
Better errors capturing at the core and stop rendering on error.
---
src/core/evaluator.js | 90 ++++++++++++++++++++++++++++-----------------------
src/display/api.js | 9 ++++++
2 files changed, 58 insertions(+), 41 deletions(-)
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index df4fa09..e7ba016 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -755,7 +755,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
var timeSlotManager = new TimeSlotManager();
- return new Promise(function next(resolve, reject) {
+ return new Promise(function promiseBody(resolve, reject) {
+ var next = function (promise) {
+ promise.then(function () {
+ try {
+ promiseBody(resolve, reject);
+ } catch (ex) {
+ reject(ex);
+ }
+ }, reject);
+ };
task.ensureNotTerminated();
timeSlotManager.reset();
var stop, operation = {}, i, ii, cs;
@@ -798,13 +807,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
if (type.name === 'Form') {
stateManager.save();
- return self.buildFormXObject(resources, xobj, null,
- operatorList, task,
- stateManager.state.clone()).
+ next(self.buildFormXObject(resources, xobj, null,
+ operatorList, task,
+ stateManager.state.clone()).
then(function () {
stateManager.restore();
- next(resolve, reject);
- }, reject);
+ }));
+ return;
} else if (type.name === 'Image') {
self.buildPaintImageXObject(resources, xobj, false,
operatorList, name, imageCache);
@@ -823,13 +832,13 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.setFont:
var fontSize = args[1];
// eagerly collect all fonts
- return self.handleSetFont(resources, args, null, operatorList,
- task, stateManager.state).
+ next(self.handleSetFont(resources, args, null, operatorList,
+ task, stateManager.state).
then(function (loadedName) {
operatorList.addDependency(loadedName);
operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
- next(resolve, reject);
- }, reject);
+ }));
+ return;
case OPS.endInlineImage:
var cacheKey = args[0].cacheKey;
if (cacheKey) {
@@ -929,10 +938,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.setFillColorN:
cs = stateManager.state.fillColorSpace;
if (cs.name === 'Pattern') {
- return self.handleColorN(operatorList, OPS.setFillColorN,
- args, cs, patterns, resources, task, xref).then(function() {
- next(resolve, reject);
- }, reject);
+ next(self.handleColorN(operatorList, OPS.setFillColorN, args,
+ cs, patterns, resources, task, xref));
+ return;
}
args = cs.getRgb(args, 0);
fn = OPS.setFillRGBColor;
@@ -940,10 +948,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.setStrokeColorN:
cs = stateManager.state.strokeColorSpace;
if (cs.name === 'Pattern') {
- return self.handleColorN(operatorList, OPS.setStrokeColorN,
- args, cs, patterns, resources, task, xref).then(function() {
- next(resolve, reject);
- }, reject);
+ next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
+ cs, patterns, resources, task, xref));
+ return;
}
args = cs.getRgb(args, 0);
fn = OPS.setStrokeRGBColor;
@@ -975,10 +982,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
var gState = extGState.get(dictName.name);
- return self.setGState(resources, gState, operatorList, task,
- xref, stateManager).then(function() {
- next(resolve, reject);
- }, reject);
+ next(self.setGState(resources, gState, operatorList, task, xref,
+ stateManager));
+ return;
case OPS.moveTo:
case OPS.lineTo:
case OPS.curveTo:
@@ -1023,9 +1029,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
operatorList.addOp(fn, args);
}
if (stop) {
- deferred.then(function () {
- next(resolve, reject);
- }, reject);
+ next(deferred);
return;
}
// Some PDFs don't close all restores inside object/form.
@@ -1301,7 +1305,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var timeSlotManager = new TimeSlotManager();
- return new Promise(function next(resolve, reject) {
+ return new Promise(function promiseBody(resolve, reject) {
+ var next = function (promise) {
+ promise.then(function () {
+ try {
+ promiseBody(resolve, reject);
+ } catch (ex) {
+ reject(ex);
+ }
+ }, reject);
+ };
task.ensureNotTerminated();
timeSlotManager.reset();
var stop, operation = {}, args = [];
@@ -1323,9 +1336,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
case OPS.setFont:
flushTextContentItem();
textState.fontSize = args[1];
- return handleSetFont(args[0].name).then(function() {
- next(resolve, reject);
- }, reject);
+ next(handleSetFont(args[0].name));
+ return;
case OPS.setTextRise:
flushTextContentItem();
textState.textRise = args[0];
@@ -1496,18 +1508,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
stateManager.transform(matrix);
}
- return self.getTextContent(xobj, task,
- xobj.dict.get('Resources') || resources, stateManager,
- normalizeWhitespace).then(function (formTextContent) {
+ next(self.getTextContent(xobj, task,
+ xobj.dict.get('Resources') || resources, stateManager,
+ normalizeWhitespace).then(function (formTextContent) {
Util.appendToArray(textContent.items, formTextContent.items);
Util.extendObj(textContent.styles, formTextContent.styles);
stateManager.restore();
xobjsCache.key = name;
xobjsCache.texts = formTextContent;
-
- next(resolve, reject);
- }, reject);
+ }));
+ return;
case OPS.setGState:
flushTextContentItem();
var dictName = args[0];
@@ -1527,17 +1538,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
if (gsStateFont) {
textState.fontSize = gsStateFont[1];
- return handleSetFont(gsStateFont[0]).then(function() {
- next(resolve, reject);
- }, reject);
+ next(handleSetFont(gsStateFont[0]));
+ return;
}
break;
} // switch
} // while
if (stop) {
- deferred.then(function () {
- next(resolve, reject);
- }, reject);
+ next(deferred);
return;
}
flushTextContentItem();
diff --git a/src/display/api.js b/src/display/api.js
index a9b2432..8d6bc79 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -1716,11 +1716,20 @@ var WorkerTransport = (function WorkerTransportClosure() {
var page = this.pageCache[data.pageNum - 1];
var intentState = page.intentStates[data.intent];
+
if (intentState.displayReadyCapability) {
intentState.displayReadyCapability.reject(data.error);
} else {
error(data.error);
}
+
+ if (intentState.operatorList) {
+ // Mark operator list as complete.
+ intentState.operatorList.lastChunk = true;
+ for (var i = 0; i < intentState.renderTasks.length; i++) {
+ intentState.renderTasks[i].operatorListChanged();
+ }
+ }
}, this);
messageHandler.on('UnsupportedFeature',
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list