Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: client/html/src/NodeWrappingImplementation.dart

Issue 9148015: Example showing alternate async measurement solution (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reply to code review comments Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/html/src/NodeWrappingImplementation.dart
diff --git a/client/html/src/NodeWrappingImplementation.dart b/client/html/src/NodeWrappingImplementation.dart
index 5a89e5e8c4e28ae87415e4d7d679b510a5ae198c..9ae383a4f456a41df0342497eee15bfc948ea7a4 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;
@@ -84,12 +93,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;
}
@@ -98,7 +111,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));
}
}
@@ -179,10 +194,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));
@@ -201,6 +218,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();
@@ -224,10 +242,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) {
@@ -237,6 +259,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);
@@ -257,6 +280,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)));
}
@@ -264,4 +288,6 @@ class NodeWrappingImplementation extends EventTargetWrappingImplementation imple
Node clone(bool deep) {
return LevelDom.wrapNode(_ptr.cloneNode(deep));
}
+
+ bool get _inDocument() => document.contains(this);
}

Powered by Google App Engine
This is Rietveld 408576698