| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Lazy implementation of the child nodes of an element that does not request | 8 * Lazy implementation of the child nodes of an element that does not request |
| 9 * the actual child nodes of an element until strictly necessary greatly | 9 * the actual child nodes of an element until strictly necessary greatly |
| 10 * improving performance for the typical cases where it is not required. | 10 * improving performance for the typical cases where it is not required. |
| 11 */ | 11 */ |
| 12 class _ChildNodeListLazy extends ListBase<Node> { | 12 class _ChildNodeListLazy extends ListBase<Node> implements NodeListWrapper { |
| 13 final Node _this; | 13 final Node _this; |
| 14 | 14 |
| 15 _ChildNodeListLazy(this._this); | 15 _ChildNodeListLazy(this._this); |
| 16 | 16 |
| 17 | 17 |
| 18 $if DART2JS | 18 $if DART2JS |
| 19 Node get first { | 19 Node get first { |
| 20 Node result = JS('Node|Null', '#.firstChild', _this); | 20 Node result = JS('Node|Null', '#.firstChild', _this); |
| 21 if (result == null) throw new StateError("No elements"); | 21 if (result == null) throw new StateError("No elements"); |
| 22 return result; | 22 return result; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // TODO(jacobr): benchmark whether this is more efficient or whether caching | 173 // TODO(jacobr): benchmark whether this is more efficient or whether caching |
| 174 // a local copy of childNodes is more efficient. | 174 // a local copy of childNodes is more efficient. |
| 175 int get length => _this.childNodes.length; | 175 int get length => _this.childNodes.length; |
| 176 | 176 |
| 177 void set length(int value) { | 177 void set length(int value) { |
| 178 throw new UnsupportedError( | 178 throw new UnsupportedError( |
| 179 "Cannot set length on immutable List."); | 179 "Cannot set length on immutable List."); |
| 180 } | 180 } |
| 181 | 181 |
| 182 Node operator[](int index) => _this.childNodes[index]; | 182 Node operator[](int index) => _this.childNodes[index]; |
| 183 |
| 184 List<Node> get rawList => _this.childNodes; |
| 183 } | 185 } |
| 184 | 186 |
| 185 | 187 |
| 186 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 188 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 187 | 189 |
| 188 // Custom element created callback. | 190 // Custom element created callback. |
| 189 Node._created() : super._created(); | 191 Node._created() : super._created(); |
| 190 | 192 |
| 191 List<Node> get nodes { | 193 List<Node> get nodes { |
| 192 return new _ChildNodeListLazy(this); | 194 return new _ChildNodeListLazy(this); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } | 255 } |
| 254 } | 256 } |
| 255 } | 257 } |
| 256 | 258 |
| 257 /** | 259 /** |
| 258 * Print out a String representation of this Node. | 260 * Print out a String representation of this Node. |
| 259 */ | 261 */ |
| 260 String toString() => nodeValue == null ? super.toString() : nodeValue; | 262 String toString() => nodeValue == null ? super.toString() : nodeValue; |
| 261 $!MEMBERS | 263 $!MEMBERS |
| 262 } | 264 } |
| OLD | NEW |