Chromium Code Reviews| Index: sdk/lib/_internal/compiler/js_lib/js_array.dart |
| diff --git a/sdk/lib/_internal/compiler/js_lib/js_array.dart b/sdk/lib/_internal/compiler/js_lib/js_array.dart |
| index 5763242e399206f4ecaa95aec1d96a3499233df7..ef8c0e606653c6ea33d858768c17232a4bee499b 100644 |
| --- a/sdk/lib/_internal/compiler/js_lib/js_array.dart |
| +++ b/sdk/lib/_internal/compiler/js_lib/js_array.dart |
| @@ -77,6 +77,15 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable { |
| return JS('JSFixedArray', '#', list); |
| } |
| + static List markUnmodifiableList(List list) { |
| + // Functions are stored in the hidden class and not as properties in |
| + // the object. We never actually look at the value, but only want |
| + // to know if the property exists. |
| + JS('void', r'#.fixed$length = Array', list); |
| + JS('void', r'#.immutable$list = Array', list); |
| + return JS('List', '#', list); |
|
sra1
2015/04/22 21:17:31
1. Change 'List' to 'JSArray'.
Leaving it as List
|
| + } |
| + |
| checkMutable(reason) { |
| if (this is !JSMutableArray) { |
| throw new UnsupportedError(reason); |
| @@ -95,20 +104,20 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable { |
| } |
| E removeAt(int index) { |
| + checkGrowable('removeAt'); |
| if (index is !int) throw new ArgumentError(index); |
| if (index < 0 || index >= length) { |
| throw new RangeError.value(index); |
| } |
| - checkGrowable('removeAt'); |
| return JS('var', r'#.splice(#, 1)[0]', this, index); |
| } |
| void insert(int index, E value) { |
| + checkGrowable('insert'); |
| if (index is !int) throw new ArgumentError(index); |
| if (index < 0 || index > length) { |
| throw new RangeError.value(index); |
| } |
| - checkGrowable('insert'); |
| JS('void', r'#.splice(#, 0, #)', this, index, value); |
| } |
| @@ -199,8 +208,9 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable { |
| } |
| void addAll(Iterable<E> collection) { |
| + checkGrowable('addAll'); |
| for (E e in collection) { |
| - this.add(e); |
| + JS('void', r'#.push(#)', this, e); |
| } |
| } |
| @@ -564,9 +574,9 @@ class JSArray<E> extends Interceptor implements List<E>, JSIndexable { |
| int get length => JS('JSUInt32', r'#.length', this); |
| void set length(int newLength) { |
| + checkGrowable('set length'); |
| if (newLength is !int) throw new ArgumentError(newLength); |
| if (newLength < 0) throw new RangeError.value(newLength); |
| - checkGrowable('set length'); |
| JS('void', r'#.length = #', this, newLength); |
| } |