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

Unified Diff: sdk/lib/_internal/compiler/js_lib/js_array.dart

Issue 1056353004: Add List.unmodifiable constructor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove left-over debug coide. Created 5 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
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);
}

Powered by Google App Engine
This is Rietveld 408576698