| OLD | NEW |
| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 /** | 146 /** |
| 147 * A scope in polymer expressions that can map names to objects. Scopes contain | 147 * 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 | 148 * 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 | 149 * is then used to lookup names using the `[]` operator. The lookup first |
| 150 * searches for the name in local variables, then in global variables, | 150 * 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. | 151 * and then finally looks up the name as a property in the model. |
| 152 */ | 152 */ |
| 153 abstract class Scope { | 153 abstract class Scope implements Indexable<String, Object> { |
| 154 Scope._(); | 154 Scope._(); |
| 155 | 155 |
| 156 /** Create a scope containing a [model] and all of [variables]. */ | 156 /** Create a scope containing a [model] and all of [variables]. */ |
| 157 factory Scope({Object model, Map<String, Object> variables}) { | 157 factory Scope({Object model, Map<String, Object> variables}) { |
| 158 var scope = new _ModelScope(model); | 158 var scope = new _ModelScope(model); |
| 159 return variables == null ? scope | 159 return variables == null ? scope |
| 160 : new _GlobalsScope(new Map<String, Object>.from(variables), scope); | 160 : new _GlobalsScope(new Map<String, Object>.from(variables), scope); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** Return the unique model in this scope. */ | 163 /** Return the unique model in this scope. */ |
| 164 Object get model; | 164 Object get model; |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * Lookup the value of [name] in the current scope. If [name] is 'this', then | 167 * Lookup the value of [name] in the current scope. If [name] is 'this', then |
| 168 * we return the [model]. For any other name, this finds the first variable | 168 * we return the [model]. For any other name, this finds the first variable |
| 169 * matching [name] or, if none exists, the property [name] in the [model]. | 169 * matching [name] or, if none exists, the property [name] in the [model]. |
| 170 */ | 170 */ |
| 171 Object operator[](String name); | 171 Object operator [](String name); |
| 172 |
| 173 operator []=(String name, Object value) { |
| 174 throw new UnsupportedError('[]= is not supported in Scope.'); |
| 175 } |
| 172 | 176 |
| 173 /** | 177 /** |
| 174 * Returns whether [name] is defined in [model], that is, a lookup | 178 * Returns whether [name] is defined in [model], that is, a lookup |
| 175 * would not find a variable with that name, but there is a non-null model | 179 * would not find a variable with that name, but there is a non-null model |
| 176 * where we can look it up as a property. | 180 * where we can look it up as a property. |
| 177 */ | 181 */ |
| 178 bool _isModelProperty(String name); | 182 bool _isModelProperty(String name); |
| 179 | 183 |
| 180 /** Create a new scope extending this scope with an additional variable. */ | 184 /** Create a new scope extending this scope with an additional variable. */ |
| 181 Scope childScope(String name, Object value) => | 185 Scope childScope(String name, Object value) => |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 744 |
| 741 Comprehension(this.identifier, Iterable iterable) | 745 Comprehension(this.identifier, Iterable iterable) |
| 742 : iterable = (iterable != null) ? iterable : const []; | 746 : iterable = (iterable != null) ? iterable : const []; |
| 743 } | 747 } |
| 744 | 748 |
| 745 class EvalException implements Exception { | 749 class EvalException implements Exception { |
| 746 final String message; | 750 final String message; |
| 747 EvalException(this.message); | 751 EvalException(this.message); |
| 748 String toString() => "EvalException: $message"; | 752 String toString() => "EvalException: $message"; |
| 749 } | 753 } |
| OLD | NEW |