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

Unified Diff: tool/input_sdk/private/js_array.dart

Issue 1939093003: List.unmodifiable (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: /*<E>*/ Created 4 years, 8 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
« no previous file with comments | « tool/input_sdk/patch/internal_patch.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « tool/input_sdk/patch/internal_patch.dart ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698