Index: tool/input_sdk/private/js_array.dart |
diff --git a/tool/input_sdk/private/js_array.dart b/tool/input_sdk/private/js_array.dart |
index de54d2f047247b940716c5d341c5fe168b50ef69..8d21950e9afbd5e420966ee979b1b8f46693a3d2 100644 |
--- a/tool/input_sdk/private/js_array.dart |
+++ b/tool/input_sdk/private/js_array.dart |
@@ -36,6 +36,21 @@ class JSArray<E> implements List<E>, JSIndexable { |
return 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('JSUnmodifiableArray', '#', list); |
+ } |
+ |
+ checkMutable(reason) { |
+ if (JS('bool', r'#.immutable$list', this)) { |
+ throw new UnsupportedError(reason); |
+ } |
+ } |
+ |
checkGrowable(reason) { |
if (JS('bool', r'#.fixed$length', this)) { |
throw new UnsupportedError(reason); |
@@ -314,6 +329,7 @@ class JSArray<E> implements List<E>, JSIndexable { |
} |
void operator []=(int index, E value) { |
+ checkMutable('indexed set'); |
if (index is !int) throw new ArgumentError(index); |
if (index >= length || index < 0) throw new RangeError.value(index); |
JS('void', r'#[#] = #', this, index, value); |
@@ -332,3 +348,4 @@ class JSArray<E> implements List<E>, JSIndexable { |
class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} |
class JSFixedArray<E> extends JSMutableArray<E> {} |
class JSExtendableArray<E> extends JSMutableArray<E> {} |
+class JSUnmodifiableArray<E> extends JSArray<E> {} // Already is JSIndexable. |