MCPcopy Create free account
hub / github.com/ampproject/amphtml / evaluateExpression_

Method evaluateExpression_

extensions/amp-bind/0.1/bind-impl.js:1024–1043  ·  view source on GitHub ↗

* Evaluates a single expression and returns its result. * @param {string} expression * @param {!JsonObject} scope * @return {!Promise<!JsonObject>}

(expression, scope)

Source from the content-addressed store, hash-verified

1022 * @return {!Promise<!JsonObject>}
1023 */
1024 evaluateExpression_(expression, scope) {
1025 return this.initializePromise_
1026 .then(() => {
1027 // Allow expression to reference current state in addition to event state.
1028 Object.assign(scope, this.state_);
1029 return this.ww_('bind.evaluateExpression', [expression, scope]);
1030 })
1031 .then((returnValue) => {
1032 const {error, result} = returnValue;
1033 if (error) {
1034 // Throw to reject promise.
1035 throw this.reportWorkerError_(
1036 error,
1037 `${TAG}: Expression eval failed.`
1038 );
1039 } else {
1040 return result;
1041 }
1042 });
1043 }
1044
1045 /**
1046 * Reevaluates all expressions and returns a map of expressions to results.

Callers 4

debugPrintElement_Method · 0.95
debugEvaluate_Method · 0.95

Calls 4

ww_Method · 0.95
reportWorkerError_Method · 0.95
assignMethod · 0.80
thenMethod · 0.45

Tested by

no test coverage detected