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 class _NodeImpl extends _EventTargetImpl implements Node native "*Node" { | 5 class _NodeImpl extends _EventTargetImpl implements Node native "*Node" { |
6 _NodeListImpl get nodes() { | 6 _NodeListImpl get nodes() { |
7 final list = _childNodes; | 7 final list = _childNodes; |
8 list._parent = this; | 8 list._parent = this; |
9 return list; | 9 return list; |
10 } | 10 } |
11 | 11 |
12 void set nodes(Collection<Node> value) { | 12 void set nodes(Collection<Node> value) { |
13 // Copy list first since we don't want liveness during iteration. | 13 // Copy list first since we don't want liveness during iteration. |
14 // TODO(jacobr): there is a better way to do this. | 14 // TODO(jacobr): there is a better way to do this. |
15 List copy = new List.from(value); | 15 List copy = new List.from(value); |
16 text = ''; | 16 text = ''; |
17 for (Node node in copy) { | 17 for (Node node in copy) { |
18 _appendChild(node); | 18 _appendChild(node); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 // TODO(jacobr): should we throw an exception if parent is already null? | 22 // TODO(jacobr): should we throw an exception if parent is already null? |
23 _NodeImpl remove() { | 23 _NodeImpl remove() { |
24 if (this.parent != null) { | 24 if (this.parent != null) { |
25 this.parent._removeChild(this); | 25 final _NodeImpl parent = this.parent; |
| 26 parent._removeChild(this); |
26 } | 27 } |
27 return this; | 28 return this; |
28 } | 29 } |
29 | 30 |
30 _NodeImpl replaceWith(Node otherNode) { | 31 _NodeImpl replaceWith(Node otherNode) { |
31 try { | 32 try { |
32 this.parent._replaceChild(otherNode, this); | 33 final _NodeImpl parent = this.parent; |
| 34 parent._replaceChild(otherNode, this); |
33 } catch(var e) { | 35 } catch(var e) { |
34 | 36 |
35 }; | 37 }; |
36 return this; | 38 return this; |
37 } | 39 } |
38 | 40 |
39 | 41 |
40 static final int ATTRIBUTE_NODE = 2; | 42 static final int ATTRIBUTE_NODE = 2; |
41 | 43 |
42 static final int CDATA_SECTION_NODE = 4; | 44 static final int CDATA_SECTION_NODE = 4; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 101 |
100 bool hasChildNodes() native; | 102 bool hasChildNodes() native; |
101 | 103 |
102 _NodeImpl insertBefore(_NodeImpl newChild, _NodeImpl refChild) native; | 104 _NodeImpl insertBefore(_NodeImpl newChild, _NodeImpl refChild) native; |
103 | 105 |
104 _NodeImpl _removeChild(_NodeImpl oldChild) native "return this.removeChild(old
Child);"; | 106 _NodeImpl _removeChild(_NodeImpl oldChild) native "return this.removeChild(old
Child);"; |
105 | 107 |
106 _NodeImpl _replaceChild(_NodeImpl newChild, _NodeImpl oldChild) native "return
this.replaceChild(newChild, oldChild);"; | 108 _NodeImpl _replaceChild(_NodeImpl newChild, _NodeImpl oldChild) native "return
this.replaceChild(newChild, oldChild);"; |
107 | 109 |
108 } | 110 } |
OLD | NEW |