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

Side by Side Diff: pkg/polymer_expressions/lib/eval.dart

Issue 263833027: Fix two-way binding in polymer expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library polymer_expressions.eval; 5 library polymer_expressions.eval;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:observe/observe.dart'; 10 import 'package:observe/observe.dart';
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 /** 75 /**
76 * Assign [value] to the variable or field referenced by [expr] in the context 76 * Assign [value] to the variable or field referenced by [expr] in the context
77 * of [scope]. 77 * of [scope].
78 * 78 *
79 * [expr] must be an /assignable/ expression, it must not contain 79 * [expr] must be an /assignable/ expression, it must not contain
80 * operators or function invocations, and any index operations must use a 80 * operators or function invocations, and any index operations must use a
81 * literal index. 81 * literal index.
82 */ 82 */
83 void assign(Expression expr, Object value, Scope scope) { 83 Object assign(Expression expr, Object value, Scope scope) {
84 84
85 notAssignable() => 85 notAssignable() =>
86 throw new EvalException("Expression is not assignable: $expr"); 86 throw new EvalException("Expression is not assignable: $expr");
87 87
88 Expression expression; 88 Expression expression;
89 var property; 89 var property;
90 bool isIndex = false; 90 bool isIndex = false;
91 var filters = <Expression>[]; // reversed order for assignment 91 var filters = <Expression>[]; // reversed order for assignment
92 92
93 while (expr is BinaryOperator) { 93 while (expr is BinaryOperator) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 value = filter.reverse(value); 133 value = filter.reverse(value);
134 } 134 }
135 // make the assignment 135 // make the assignment
136 var o = eval(expression, scope); 136 var o = eval(expression, scope);
137 if (o == null) throw new EvalException("Can't assign to null: $expression"); 137 if (o == null) throw new EvalException("Can't assign to null: $expression");
138 if (isIndex) { 138 if (isIndex) {
139 o[property] = value; 139 o[property] = value;
140 } else { 140 } else {
141 smoke.write(o, smoke.nameToSymbol(property), value); 141 smoke.write(o, smoke.nameToSymbol(property), value);
142 } 142 }
143 return value;
143 } 144 }
144 145
145 146
146 /** 147 /**
147 * A scope in polymer expressions that can map names to objects. Scopes contain 148 * A scope in polymer expressions that can map names to objects. Scopes contain
148 * a set of named variables and a unique model object. The scope structure 149 * a set of named variables and a unique model object. The scope structure
149 * is then used to lookup names using the `[]` operator. The lookup first 150 * is then used to lookup names using the `[]` operator. The lookup first
150 * searches for the name in local variables, then in global variables, 151 * searches for the name in local variables, then in global variables,
151 * and then finally looks up the name as a property in the model. 152 * and then finally looks up the name as a property in the model.
152 */ 153 */
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 745
745 Comprehension(this.identifier, Iterable iterable) 746 Comprehension(this.identifier, Iterable iterable)
746 : iterable = (iterable != null) ? iterable : const []; 747 : iterable = (iterable != null) ? iterable : const [];
747 } 748 }
748 749
749 class EvalException implements Exception { 750 class EvalException implements Exception {
750 final String message; 751 final String message;
751 EvalException(this.message); 752 EvalException(this.message);
752 String toString() => "EvalException: $message"; 753 String toString() => "EvalException: $message";
753 } 754 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/event_handlers_test.dart ('k') | pkg/polymer_expressions/lib/polymer_expressions.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698