Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent BindEvaluator from returning Error objects to web worker #7599

Merged
merged 14 commits into from
Feb 28, 2017
13 changes: 6 additions & 7 deletions extensions/amp-bind/0.1/bind-evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class BindEvaluator {
* Parses and stores given bindings into expression objects and returns map
* of expression string to parse errors.
* @param {!Array<BindingDef>} bindings
* @return {!Object<string,!Error>}
* @return {!Object<string,string>}
*/
addBindings(bindings) {
const errors = Object.create(null);
Expand All @@ -66,7 +66,7 @@ export class BindEvaluator {
try {
expression = new BindExpression(e.expressionString);
} catch (error) {
errors[string] = error;
errors[string] = error.message;
continue;
}

Expand Down Expand Up @@ -101,13 +101,13 @@ export class BindEvaluator {
* @param {!Object} scope
* @return {{
* results: !Object<string, ./bind-expression.BindExpressionResultDef>,
* errors: !Object<string, !Error>,
* errors: !Object<string, !string>,
* }}
*/
evaluate(scope) {
/** @type {!Object<string, ./bind-expression.BindExpressionResultDef>} */
const cache = {};
/** @type {!Object<string, !Error>} */
/** @type {!Object<string, string>} */
const errors = {};

this.parsedBindings_.forEach(binding => {
Expand All @@ -123,16 +123,15 @@ export class BindEvaluator {
try {
result = binding.expression.evaluate(scope);
} catch (error) {
errors[expr] = error;
errors[expr] = error.message;
return;
}

const resultString = this.stringValueOf_(property, result);
if (this.validator_.isResultValid(tagName, property, resultString)) {
cache[expr] = result;
} else {
errors[expr] = new Error(
`"${result}" is not a valid result for [${property}].`);
errors[expr] = `"${result}" is not a valid result for [${property}].`;
}
});
return {results: cache, errors};
Expand Down
2 changes: 2 additions & 0 deletions src/web-worker/web-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ self.addEventListener('message', function(event) {

/** @type {FromWorkerMessageDef} */
const message = {method, returnValue, id};
// `message` may only contain vlaues or objects handled by the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/vlaues/values

// structured clone algorithm.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self./*OK*/postMessage(message);
});