Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: pkg/polymer_expressions/lib/eval.dart

Issue 24031006: Silently handle handle eval exceptions in PolymerExpressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/polymer_expressions/example/example.dart ('k') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer_expressions/lib/eval.dart
diff --git a/pkg/polymer_expressions/lib/eval.dart b/pkg/polymer_expressions/lib/eval.dart
index b76b3b878c935b2da386a673d299e1c3509e58da..c191bd9cf79311452379d03db3e393432f02109f 100644
--- a/pkg/polymer_expressions/lib/eval.dart
+++ b/pkg/polymer_expressions/lib/eval.dart
@@ -47,16 +47,33 @@ final _BOOLEAN_OPERATORS = ['!', '||', '&&'];
/**
* Evaluation [expr] in the context of [scope].
*/
-Object eval(Expression expr, Scope scope) => observe(expr, scope)._value;
-
+Object eval(Expression expr, Scope scope) {
+ var observer = observe(expr, scope);
+ new Updater(scope).visit(observer);
+ return observer._value;
+}
+/**
+ * Returns an [ExpressionObserver] that evaluates [expr] in the context of
+ * scope] and listens for any changes on [Observable] values that are
+ * returned from sub-expressions. When a value changes the expression is
+ * reevaluated and the new result is sent to the [onUpdate] stream of the
+ * [ExpressionObsserver].
+ */
ExpressionObserver observe(Expression expr, Scope scope) {
var observer = new ObserverBuilder(scope).visit(expr);
- new Updater(scope).visit(observer);
return observer;
}
/**
+ * Causes [expr] to be reevaluated a returns it's value.
+ */
+Object update(ExpressionObserver expr, Scope scope) {
+ new Updater(scope).visit(expr);
+ return expr.currentValue;
+}
+
+/**
* Assign [value] to the variable or field referenced by [expr] in the context
* of [scope].
*
@@ -166,7 +183,7 @@ class Scope extends Object {
if (parent != null) {
return _convert(parent[name]);
} else {
- throw new EvalException("variable not found: $name in $hashCode");
+ throw new EvalException("variable '$name' not found");
}
}
@@ -205,8 +222,6 @@ class Scope extends Object {
}
return false;
}
-
- String toString() => 'Scope($hashCode $parent)';
}
Object _convert(v) {
« no previous file with comments | « pkg/polymer_expressions/example/example.dart ('k') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698