Chromium Code Reviews| Index: client/html/src/NodeWrappingImplementation.dart |
| diff --git a/client/html/src/NodeWrappingImplementation.dart b/client/html/src/NodeWrappingImplementation.dart |
| index 220f877c0a272762bbb8716856d3c03ae5d2785b..4b431ec4cc01ec43e450a1c250465f67b69c363b 100644 |
| --- a/client/html/src/NodeWrappingImplementation.dart |
| +++ b/client/html/src/NodeWrappingImplementation.dart |
| @@ -1,7 +1,17 @@ |
| -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +// TODO(jacobr): we could write this method more efficiently if we wanted to |
| +// however performance isn't crucial as it is only called when a method is |
| +// called from an atypical context (e.g. measurement method called outside of |
| +// requestMeasurementFrame or dom manipulation called within |
| +// requestMeasurementFrame). |
| +bool _nodeInDocument(var node) { |
| +//bool _nodeInDocument(dom.Node node) { |
| + return LevelDom.wrapNode(node).dynamic._inDocument; // XXX remove dynamic |
|
Jennifer Messerly
2012/01/13 02:19:44
make the XXX into a TODO?
Jacob
2012/01/17 19:30:45
Removed dynamic.
Done.
|
| +} |
| + |
| class _ChildrenNodeList implements NodeList { |
| // Raw node. |
| final _node; |
| @@ -76,12 +86,16 @@ class _ChildrenNodeList implements NodeList { |
| /** @domName Node.appendChild */ |
| Node add(Node value) { |
| + assert(!_inMeasurementFrame |
| + || (!_nodeInDocument(_node) && !value._inDocument)); |
| _node.appendChild(LevelDom.unwrap(value)); |
| return value; |
| } |
| Node addLast(Node value) { |
| - _node.appendChild(LevelDom.unwrap(value)); |
| + assert(!_inMeasurementFrame |
| + || (!_nodeInDocument(_node) && !value._inDocument)); |
| + _node.appendChild(LevelDom.unwrap(value)); |
| return value; |
| } |
| @@ -90,7 +104,9 @@ class _ChildrenNodeList implements NodeList { |
| } |
| void addAll(Collection<Node> collection) { |
| + assert(!_inMeasurementFrame || !_nodeInDocument(_node)); |
| for (Node node in collection) { |
| + assert(!_inMeasurementFrame || !node._inDocument); |
| _node.appendChild(LevelDom.unwrap(node)); |
| } |
| } |
| @@ -129,10 +145,12 @@ class _ChildrenNodeList implements NodeList { |
| } |
| void clear() { |
| + assert(!_inMeasurementFrame || !_nodeInDocument(_node)); |
| _node.textContent = ''; |
| } |
| Node removeLast() { |
| + assert(!_inMeasurementFrame || !_nodeInDocument(_node)); |
| final last = this.last(); |
| if (last != null) { |
| _node.removeChild(LevelDom.unwrap(last)); |
| @@ -151,6 +169,7 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple |
| NodeWrappingImplementation._wrap(ptr) : super._wrap(ptr); |
| void set nodes(Collection<Node> value) { |
| + assert(!_inMeasurementFrame || !_inDocument); |
| // Copy list first since we don't want liveness during iteration. |
| List copy = new List.from(value); |
| nodes.clear(); |
| @@ -174,10 +193,14 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple |
| String get text() => _ptr.textContent; |
| - void set text(String value) { _ptr.textContent = value; } |
| + void set text(String value) { |
| + assert(!_inMeasurementFrame || !_inDocument); |
| + _ptr.textContent = value; |
| + } |
| // New methods implemented. |
| Node replaceWith(Node otherNode) { |
| + assert(!_inMeasurementFrame || !_inDocument); |
| try { |
| _ptr.parentNode.replaceChild(LevelDom.unwrap(otherNode), _ptr); |
| } catch(var e) { |
| @@ -187,6 +210,7 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple |
| } |
| Node remove() { |
| + assert(!_inMeasurementFrame || !_inDocument); |
| // TODO(jacobr): should we throw an exception if parent is already null? |
| if (_ptr.parentNode !== null) { |
| _ptr.parentNode.removeChild(_ptr); |
| @@ -207,6 +231,7 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple |
| // insertBefore or we switch NodeList to implement LinkedList rather than |
| // array. |
| Node insertBefore(Node newChild, Node refChild) { |
| + assert(!_inMeasurementFrame || !_inDocument); |
| return LevelDom.wrapNode(_ptr.insertBefore( |
| LevelDom.unwrap(newChild), LevelDom.unwrap(refChild))); |
| } |
| @@ -214,4 +239,8 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple |
| Node clone(bool deep) { |
| return LevelDom.wrapNode(_ptr.cloneNode(deep)); |
| } |
| + |
| + bool get _inDocument() { |
|
Jennifer Messerly
2012/01/13 02:19:44
bool get _inDocument() => document.contains(this);
Jacob
2012/01/17 19:30:45
Done.
|
| + return document.contains(this); |
| + } |
| } |