| Index: client/html/src/NodeWrappingImplementation.dart
|
| diff --git a/client/html/src/NodeWrappingImplementation.dart b/client/html/src/NodeWrappingImplementation.dart
|
| index 82a568c3d597bc38a7caf612d662bf6e0edf7981..e80b082f132446e10c9392112814efbbbc6adeaa 100644
|
| --- a/client/html/src/NodeWrappingImplementation.dart
|
| +++ b/client/html/src/NodeWrappingImplementation.dart
|
| @@ -1,7 +1,16 @@
|
| -// 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(dom.Node node) {
|
| + return LevelDom.wrapNode(node)._inDocument;
|
| +}
|
| +
|
| class _ChildrenNodeList implements NodeList {
|
| // Raw node.
|
| final _node;
|
| @@ -70,12 +79,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;
|
| }
|
|
|
| @@ -84,7 +97,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));
|
| }
|
| }
|
| @@ -119,10 +134,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));
|
| @@ -141,6 +158,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();
|
| @@ -164,10 +182,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) {
|
| @@ -177,6 +199,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);
|
| @@ -197,6 +220,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)));
|
| }
|
| @@ -204,4 +228,6 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple
|
| Node clone(bool deep) {
|
| return LevelDom.wrapNode(_ptr.cloneNode(deep));
|
| }
|
| +
|
| + bool get _inDocument() => document.contains(this);
|
| }
|
|
|