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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 11413053: Remove _NodeListWrapper, make NodeList less special. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | sdk/lib/html/scripts/generator.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 2789d5e74eefdf918ca85b0205514d1d1f75e2a3..875dfd945892ff86bf5a0643708c88f8caf37264 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -13833,7 +13833,7 @@ class _ChildNodeListLazy implements List {
Collection map(f(Node element)) => _Collections.map(this, [], f);
Collection<Node> filter(bool f(Node element)) =>
- new _NodeListWrapper(_Collections.filter(this, <Node>[], f));
+ _Collections.filter(this, <Node>[], f);
bool every(bool f(Node element)) => _Collections.every(this, f);
@@ -13869,7 +13869,7 @@ class _ChildNodeListLazy implements List {
"Cannot insertRange on immutable List.");
}
List<Node> getRange(int start, int rangeLength) =>
- new _NodeListWrapper(_Lists.getRange(this, start, rangeLength, <Node>[]));
+ _Lists.getRange(this, start, rangeLength, <Node>[]);
// -- end List<Node> mixins.
@@ -14108,192 +14108,6 @@ class NodeIterator native "*NodeIterator" {
// BSD-style license that can be found in the LICENSE file.
-// TODO(nweiz): when all implementations we target have the same name for the
-// implementation of List<E>, extend that rather than wrapping.
-class _ListWrapper<E> implements List<E> {
- List _list;
-
- _ListWrapper(List this._list);
-
- Iterator<E> iterator() => _list.iterator();
-
- bool contains(E element) => _list.contains(element);
-
- void forEach(void f(E element)) => _list.forEach(f);
-
- Collection map(f(E element)) => _list.map(f);
-
- List<E> filter(bool f(E element)) => _list.filter(f);
-
- bool every(bool f(E element)) => _list.every(f);
-
- bool some(bool f(E element)) => _list.some(f);
-
- bool get isEmpty => _list.isEmpty;
-
- int get length => _list.length;
-
- E operator [](int index) => _list[index];
-
- void operator []=(int index, E value) { _list[index] = value; }
-
- void set length(int newLength) { _list.length = newLength; }
-
- void add(E value) => _list.add(value);
-
- void addLast(E value) => _list.addLast(value);
-
- void addAll(Collection<E> collection) => _list.addAll(collection);
-
- void sort([Comparator<E> compare = Comparable.compare]) => _list.sort(compare);
-
- int indexOf(E element, [int start = 0]) => _list.indexOf(element, start);
-
- int lastIndexOf(E element, [int start = 0]) =>
- _list.lastIndexOf(element, start);
-
- void clear() => _list.clear();
-
- E removeLast() => _list.removeLast();
-
- E get first => _list.first;
-
- E get last => _list.last;
-
- List<E> getRange(int start, int rangeLength) =>
- _list.getRange(start, rangeLength);
-
- void setRange(int start, int rangeLength, List<E> from, [int startFrom = 0])
- => _list.setRange(start, rangeLength, from, startFrom);
-
- void removeRange(int start, int rangeLength) =>
- _list.removeRange(start, rangeLength);
-
- void insertRange(int start, int rangeLength, [E initialValue = null]) =>
- _list.insertRange(start, rangeLength, initialValue);
-}
-
-/**
- * This class is used to insure the results of list operations are NodeLists
- * instead of lists.
- */
-class _NodeListWrapper extends _ListWrapper<Node> implements List {
- _NodeListWrapper(List list) : super(list);
-
- List<Node> filter(bool f(Node element)) =>
- new _NodeListWrapper(_list.filter(f));
-
- List<Node> getRange(int start, int rangeLength) =>
- new _NodeListWrapper(_list.getRange(start, rangeLength));
-}
-
-class NodeList implements JavaScriptIndexingBehavior, List<Node> native "*NodeList" {
- Node _parent;
-
- // -- start List<Node> mixins.
- // Node is the element type.
-
- // From Iterable<Node>:
-
- Iterator<Node> iterator() {
- // Note: NodeLists are not fixed size. And most probably length shouldn't
- // be cached in both iterator _and_ forEach method. For now caching it
- // for consistency.
- return new FixedSizeListIterator<Node>(this);
- }
-
- // From Collection<Node>:
-
- void add(Node value) {
- _parent.$dom_appendChild(value);
- }
-
- void addLast(Node value) {
- _parent.$dom_appendChild(value);
- }
-
- void addAll(Collection<Node> collection) {
- for (Node node in collection) {
- _parent.$dom_appendChild(node);
- }
- }
-
- Node removeLast() {
- final result = this.last;
- if (result != null) {
- _parent.$dom_removeChild(result);
- }
- return result;
- }
-
- void clear() {
- _parent.text = '';
- }
-
- void operator []=(int index, Node value) {
- _parent.$dom_replaceChild(value, this[index]);
- }
-
- bool contains(Node element) => _Collections.contains(this, element);
-
- void forEach(void f(Node element)) => _Collections.forEach(this, f);
-
- Collection map(f(Node element)) => _Collections.map(this, [], f);
-
- Collection<Node> filter(bool f(Node element)) =>
- new _NodeListWrapper(_Collections.filter(this, <Node>[], f));
-
- bool every(bool f(Node element)) => _Collections.every(this, f);
-
- bool some(bool f(Node element)) => _Collections.some(this, f);
-
- bool get isEmpty => this.length == 0;
-
- // From List<Node>:
-
- void sort([Comparator<Node> compare = Comparable.compare]) {
- throw new UnsupportedError("Cannot sort immutable List.");
- }
-
- int indexOf(Node element, [int start = 0]) =>
- _Lists.indexOf(this, element, start, this.length);
-
- int lastIndexOf(Node element, [int start = 0]) =>
- _Lists.lastIndexOf(this, element, start);
-
- Node get last => this[length - 1];
- Node get first => this[0];
-
- // FIXME: implement thesee.
- void setRange(int start, int rangeLength, List<Node> from, [int startFrom]) {
- throw new UnsupportedError("Cannot setRange on immutable List.");
- }
- void removeRange(int start, int rangeLength) {
- throw new UnsupportedError("Cannot removeRange on immutable List.");
- }
- void insertRange(int start, int rangeLength, [Node initialValue]) {
- throw new UnsupportedError("Cannot insertRange on immutable List.");
- }
- List<Node> getRange(int start, int rangeLength) =>
- new _NodeListWrapper(_Lists.getRange(this, start, rangeLength, <Node>[]));
-
- // -- end List<Node> mixins.
-
-
- /** @domName NodeList.length */
- final int length;
-
- Node operator[](int index) => JS("Node", "#[#]", this, index);
-
- /** @domName NodeList.item */
- Node _item(int index) native "item";
-
-}
-// 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.
-
-
/// @domName Notation
class Notation extends Node native "*Notation" {
@@ -15614,7 +15428,7 @@ class RTCStatsResponse native "*RTCStatsResponse" {
/// @domName RadioNodeList
-class RadioNodeList extends NodeList native "*RadioNodeList" {
+class RadioNodeList extends _NodeList native "*RadioNodeList" {
Emily Fortuna 2012/11/17 02:44:30 is it an issue at all that it's extending a hidden
/** @domName RadioNodeList.value */
String value;
@@ -21638,6 +21452,105 @@ class _MutationObserverFactoryProvider {
// BSD-style license that can be found in the LICENSE file.
+/// @domName NodeList
+class _NodeList implements JavaScriptIndexingBehavior, List<Node> native "*NodeList" {
+
+ /** @domName NodeList.length */
+ final int length;
+
+ Node operator[](int index) => JS("Node", "#[#]", this, index);
+
+ void operator[]=(int index, Node value) {
+ throw new UnsupportedError("Cannot assign element of immutable List.");
+ }
+ // -- start List<Node> mixins.
+ // Node is the element type.
+
+ // From Iterable<Node>:
+
+ Iterator<Node> iterator() {
+ // Note: NodeLists are not fixed size. And most probably length shouldn't
+ // be cached in both iterator _and_ forEach method. For now caching it
+ // for consistency.
+ return new FixedSizeListIterator<Node>(this);
+ }
+
+ // From Collection<Node>:
+
+ void add(Node value) {
+ throw new UnsupportedError("Cannot add to immutable List.");
+ }
+
+ void addLast(Node value) {
+ throw new UnsupportedError("Cannot add to immutable List.");
+ }
+
+ void addAll(Collection<Node> collection) {
+ throw new UnsupportedError("Cannot add to immutable List.");
+ }
+
+ bool contains(Node element) => _Collections.contains(this, element);
+
+ void forEach(void f(Node element)) => _Collections.forEach(this, f);
+
+ Collection map(f(Node element)) => _Collections.map(this, [], f);
+
+ Collection<Node> filter(bool f(Node element)) =>
+ _Collections.filter(this, <Node>[], f);
+
+ bool every(bool f(Node element)) => _Collections.every(this, f);
+
+ bool some(bool f(Node element)) => _Collections.some(this, f);
+
+ bool get isEmpty => this.length == 0;
+
+ // From List<Node>:
+
+ void sort([Comparator<Node> compare = Comparable.compare]) {
+ throw new UnsupportedError("Cannot sort immutable List.");
+ }
+
+ int indexOf(Node element, [int start = 0]) =>
+ _Lists.indexOf(this, element, start, this.length);
+
+ int lastIndexOf(Node element, [int start]) {
+ if (start == null) start = length - 1;
+ return _Lists.lastIndexOf(this, element, start);
+ }
+
+ Node get first => this[0];
+
+ Node get last => this[length - 1];
+
+ Node removeLast() {
+ throw new UnsupportedError("Cannot removeLast on immutable List.");
+ }
+
+ void setRange(int start, int rangeLength, List<Node> from, [int startFrom]) {
+ throw new UnsupportedError("Cannot setRange on immutable List.");
+ }
+
+ void removeRange(int start, int rangeLength) {
+ throw new UnsupportedError("Cannot removeRange on immutable List.");
+ }
+
+ void insertRange(int start, int rangeLength, [Node initialValue]) {
+ throw new UnsupportedError("Cannot insertRange on immutable List.");
+ }
+
+ List<Node> getRange(int start, int rangeLength) =>
+ _Lists.getRange(this, start, rangeLength, <Node>[]);
+
+ // -- end List<Node> mixins.
+
+ /** @domName NodeList.item */
+ Node _item(int index) native "item";
+}
+// 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.
+
+
class _NotificationFactoryProvider {
static Notification createNotification(String title, [Map options]) =>
JS('Notification', 'new Notification(#,#)', title, options);
« no previous file with comments | « no previous file | sdk/lib/html/dartium/html_dartium.dart » ('j') | sdk/lib/html/scripts/generator.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698