| 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 implements List { | 12 class _ChildNodeListLazy implements List { |
| 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', '#.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; |
| 23 } | 23 } |
| 24 Node get last { | 24 Node get last { |
| 25 Node result = JS('Node', '#.lastChild', _this); | 25 Node result = JS('Node|Null', '#.lastChild', _this); |
| 26 if (result == null) throw new StateError("No elements"); | 26 if (result == null) throw new StateError("No elements"); |
| 27 return result; | 27 return result; |
| 28 } | 28 } |
| 29 Node get single { | 29 Node get single { |
| 30 int l = this.length; | 30 int l = this.length; |
| 31 if (l == 0) throw new StateError("No elements"); | 31 if (l == 0) throw new StateError("No elements"); |
| 32 if (l > 1) throw new StateError("More than one element"); | 32 if (l > 1) throw new StateError("More than one element"); |
| 33 return JS('Node', '#.firstChild', _this); | 33 return JS('Node|Null', '#.firstChild', _this); |
| 34 } | 34 } |
| 35 $else | 35 $else |
| 36 Node get first { | 36 Node get first { |
| 37 Node result = _this.$dom_firstChild; | 37 Node result = _this.$dom_firstChild; |
| 38 if (result == null) throw new StateError("No elements"); | 38 if (result == null) throw new StateError("No elements"); |
| 39 return result; | 39 return result; |
| 40 } | 40 } |
| 41 Node get last { | 41 Node get last { |
| 42 Node result = _this.$dom_lastChild; | 42 Node result = _this.$dom_lastChild; |
| 43 if (result == null) throw new StateError("No elements"); | 43 if (result == null) throw new StateError("No elements"); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 } else { | 315 } else { |
| 316 for (var node in newNodes) { | 316 for (var node in newNodes) { |
| 317 this.insertBefore(node, refChild); | 317 this.insertBefore(node, refChild); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 $!MEMBERS | 322 $!MEMBERS |
| 323 } | 323 } |
| OLD | NEW |