From 007fab6ab5cb5b0b37537779ad243593c9347d0f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 4 May 2019 12:39:58 +0200 Subject: [PATCH] Change `PartialEvaluator.handleColorN` to throw when no valid pattern is found Currently `handleColorN` will fallback to add a completely unparsed/unvalidated operator when no valid pattern was found. This is unfortunate, since it could very easily lead to a couple of different errors: - `DataCloneError`s when attempting to send the data to the main-thread, e.g. when `args` is `Dict`/`Stream`. - Errors in `getShadingPatternFromIR` on the main-thread, unless `args` just happens to have the expected format. - Errors when actually attempting to render the pattern on the main-thread, since the `args` will most likely not have the expected format. Hence it probably makes sense to error in `PartialEvaluator.handleColorN`, and having invalid patterns fail gracefully via the existing `ignoreErrors` code-paths instead. --- src/core/evaluator.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index dc88db6ca..10cd2a963 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -853,9 +853,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { } }, - handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, - cs, patterns, - resources, task) { + async handleColorN(operatorList, fn, args, cs, patterns, resources, task) { // compile tiling patterns var patternName = args[args.length - 1]; // SCN/scn applies patterns along with normal colors @@ -875,13 +873,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { pattern = Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory); operatorList.addOp(fn, pattern.getIR()); - return Promise.resolve(); + return undefined; } - return Promise.reject(new Error('Unknown PatternType: ' + typeNum)); + throw new FormatError(`Unknown PatternType: ${typeNum}`); } - // TODO shall we fail here? - operatorList.addOp(fn, args); - return Promise.resolve(); + throw new FormatError(`Unknown PatternName: ${patternName}`); }, getOperatorList({ stream, task, resources, operatorList,