| Index: sdk/lib/js/dartium/js_dartium.dart
|
| diff --git a/sdk/lib/js/dartium/js_dartium.dart b/sdk/lib/js/dartium/js_dartium.dart
|
| index af3df6cd0fe6033a677e73a9610619fd11de1893..ce6705edc7e3457da927afc334330cacd11647e1 100644
|
| --- a/sdk/lib/js/dartium/js_dartium.dart
|
| +++ b/sdk/lib/js/dartium/js_dartium.dart
|
| @@ -83,6 +83,7 @@
|
| */
|
| library dart.js;
|
|
|
| +import 'dart:collection' show ListMixin;
|
| import 'dart:nativewrappers';
|
|
|
| JsObject _cachedContext;
|
| @@ -260,6 +261,97 @@ class JsFunction extends JsObject {
|
| }
|
|
|
| /**
|
| + * A [List] proxying a JavaScript Array.
|
| + */
|
| +class JsArray<E> extends JsObject with ListMixin<E> {
|
| +
|
| + factory JsArray() => _newJsArray();
|
| +
|
| + static JsArray _newJsArray() native "JsArray_newJsArray";
|
| +
|
| + factory JsArray.from(Iterable<E> other) => _newJsArrayFromSafeList(new List.from(other));
|
| +
|
| + static JsArray _newJsArrayFromSafeList(List list) native "JsArray_newJsArrayFromSafeList";
|
| +
|
| + _checkIndex(int index, {bool insert: false}) {
|
| + int length = insert ? this.length + 1 : this.length;
|
| + if (index is int && (index < 0 || index >= length)) {
|
| + throw new RangeError.range(index, 0, length);
|
| + }
|
| + }
|
| +
|
| + _checkRange(int start, int end) {
|
| + int cachedLength = this.length;
|
| + if (start < 0 || start > cachedLength) {
|
| + throw new RangeError.range(start, 0, cachedLength);
|
| + }
|
| + if (end < start || end > cachedLength) {
|
| + throw new RangeError.range(end, start, cachedLength);
|
| + }
|
| + }
|
| +
|
| + // Methods required by ListMixin
|
| +
|
| + E operator [](int index) {
|
| + _checkIndex(index);
|
| + return super[index];
|
| + }
|
| +
|
| + void operator []=(int index, E value) {
|
| + _checkIndex(index);
|
| + super[index] = value;
|
| + }
|
| +
|
| + int get length native "JsArray_length";
|
| +
|
| + void set length(int length) { super['length'] = length; }
|
| +
|
| + // Methods overriden for better performance
|
| +
|
| + void add(E value) {
|
| + callMethod('push', [value]);
|
| + }
|
| +
|
| + void addAll(Iterable<E> iterable) {
|
| + // TODO(jacobr): this can be optimized slightly.
|
| + callMethod('push', new List.from(iterable));
|
| + }
|
| +
|
| + void insert(int index, E element) {
|
| + _checkIndex(index, insert:true);
|
| + callMethod('splice', [index, 0, element]);
|
| + }
|
| +
|
| + E removeAt(int index) {
|
| + _checkIndex(index);
|
| + return callMethod('splice', [index, 1])[0];
|
| + }
|
| +
|
| + E removeLast() {
|
| + if (length == 0) throw new RangeError(-1);
|
| + return callMethod('pop');
|
| + }
|
| +
|
| + void removeRange(int start, int end) {
|
| + _checkRange(start, end);
|
| + callMethod('splice', [start, end - start]);
|
| + }
|
| +
|
| + void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) {
|
| + _checkRange(start, end);
|
| + int length = end - start;
|
| + if (length == 0) return;
|
| + if (skipCount < 0) throw new ArgumentError(skipCount);
|
| + var args = [start, length]..addAll(iterable.skip(skipCount).take(length));
|
| + callMethod('splice', args);
|
| + }
|
| +
|
| + void sort([int compare(E a, E b)]) {
|
| + callMethod('sort', [compare]);
|
| + }
|
| +}
|
| +
|
| +/**
|
| * Placeholder object for cases where we need to determine exactly how many
|
| * args were passed to a function.
|
| */
|
|
|