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

Unified Diff: dart/frog/leg/lib/js_helper.dart

Issue 9453021: Start supporting fixed length and immutable lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update co19-leg.status Created 8 years, 10 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 | « no previous file | dart/frog/leg/ssa/builder.dart » ('j') | dart/frog/leg/ssa/codegen.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/js_helper.dart
diff --git a/dart/frog/leg/lib/js_helper.dart b/dart/frog/leg/lib/js_helper.dart
index 6537d5e95d9884bee49e6b65fffdac33909f8222..6aed9ca3d35af26e8524050349f885e085d0a2d1 100644
--- a/dart/frog/leg/lib/js_helper.dart
+++ b/dart/frog/leg/lib/js_helper.dart
@@ -242,6 +242,7 @@ indexSet(var a, var index, var value) {
if (index < 0 || index >= a.length) {
throw new IndexOutOfRangeException(index);
}
+ checkImmutable(a, 'indexed set');
Lasse Reichstein Nielsen 2012/02/24 11:08:41 Seems it should be named "checkMutable" to match o
ahe 2012/02/27 11:51:12 Done.
return JS("Object", @"$0[$1] = $2", a, index, value);
}
checkNull(a);
@@ -249,9 +250,16 @@ indexSet(var a, var index, var value) {
return value;
}
+checkImmutable(list, reason) {
+ if (JS('bool', @'!!($0.immutable$list)', list)) {
+ throw new UnsupportedOperationException(reason);
+ }
+}
+
builtin$add$1(var receiver, var value) {
checkNull(receiver);
if (isJsArray(receiver)) {
+ checkFixedLength(receiver, 'add');
JS("Object", @"$0.push($1)", receiver, value);
return;
}
@@ -261,6 +269,7 @@ builtin$add$1(var receiver, var value) {
builtin$removeLast$0(var receiver) {
checkNull(receiver);
if (isJsArray(receiver)) {
+ checkFixedLength(receiver, 'removeLast');
if (receiver.length === 0) throw new IndexOutOfRangeException(-1);
return JS("Object", @"$0.pop()", receiver);
}
@@ -291,6 +300,7 @@ builtin$set$length(receiver, newLength) {
checkNull(newLength); // TODO(ahe): This is not specified but co19 tests it.
if (newLength is !int) throw new IllegalArgumentException(newLength);
if (newLength < 0) throw new IndexOutOfRangeException(newLength);
+ checkFixedLength(receiver, 'set length');
JS('void', @"$0.length = $1", receiver, newLength);
} else {
UNINTERCEPTED(receiver.length = newLength);
@@ -298,6 +308,12 @@ builtin$set$length(receiver, newLength) {
return newLength;
}
+checkFixedLength(list, reason) {
Lasse Reichstein Nielsen 2012/02/24 11:08:41 Also the opposite name here - whatever that would
ahe 2012/02/27 11:51:12 Done.
+ if (JS('bool', @'!!($0.fixed$length)', list)) {
+ throw new UnsupportedOperationException(reason);
+ }
+}
+
builtin$toString$0(var value) {
if (JS("bool", @"typeof $0 == 'object'", value)) {
if (isJsArray(value)) {
@@ -378,11 +394,13 @@ class Primitives {
}
static List newList(length) {
- if (length == null) return JS("Object", @"new Array()");
+ if (length === null) return JS("Object", @"new Array()");
if ((length is !int) || (length < 0)) {
throw new IllegalArgumentException(length);
}
- return JS("Object", @"new Array($0)", length);
+ var result = JS("Object", @"new Array($0)", length);
+ JS('bool', @'$0.fixed$length = $1', result, true);
Lasse Reichstein Nielsen 2012/02/24 11:08:41 How about using "void" as type for things where we
ahe 2012/02/27 11:51:12 I'll see if that works.
+ return result;
}
static num dateNow() => JS("num", @"Date.now()");
@@ -561,6 +579,7 @@ builtin$addAll$1(receiver, collection) {
checkNull(receiver);
if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addAll(collection));
+ checkFixedLength(receiver, 'addAll');
floitsch 2012/02/24 10:15:09 No need. receiver add does this check for you. But
ahe 2012/02/27 11:51:12 Done.
// TODO(ahe): Use for-in when it is implemented correctly.
var iterator = collection.iterator();
while (iterator.hasNext()) {
@@ -572,6 +591,7 @@ builtin$addLast$1(receiver, value) {
checkNull(receiver);
if (!isJsArray(receiver)) return UNINTERCEPTED(receiver.addLast(value));
+ checkFixedLength(receiver, 'addLast');
JS("Object", @"$0.push($1)", receiver, value);
}
@@ -727,6 +747,7 @@ builtin$removeRange$2(receiver, start, length) {
if (!isJsArray(receiver)) {
return UNINTERCEPTED(receiver.removeRange(start, length));
}
+ checkFixedLength(receiver, 'removeRange');
if (length == 0) {
return;
}
@@ -764,6 +785,7 @@ builtin$setRange$4(receiver, start, length, from, startFrom) {
return UNINTERCEPTED(receiver.setRange(start, length, from, startFrom));
}
+ checkImmutable(receiver, 'indexed set');
if (length === 0) return;
checkNull(start); // TODO(ahe): This is not specified but co19 tests it.
checkNull(length); // TODO(ahe): This is not specified but co19 tests it.
@@ -1196,3 +1218,9 @@ builtin$charCodes$0(receiver) {
}
return result;
}
+
+makeLiteralListConst(list) {
+ JS('bool', @'$0.immutable$list = $1', list, true);
+ JS('bool', @'$0.fixed$length = $1', list, true);
+ return list;
+}
« no previous file with comments | « no previous file | dart/frog/leg/ssa/builder.dart » ('j') | dart/frog/leg/ssa/codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698