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

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

Issue 9027002: Support factory methods. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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 | « frog/leg/emitter.dart ('k') | frog/leg/namer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/lib/core.dart
===================================================================
--- frog/leg/lib/core.dart (revision 2754)
+++ frog/leg/lib/core.dart (working copy)
@@ -242,12 +242,22 @@
throw "Unimplemented user-defined length.";
}
+bool isInt(var v) {
+ return JS(@"($0 | 0) === $1", v, v);
+}
+
class int {}
class double {}
class String {}
class bool {}
class Object {}
-class List<T> {}
+class List<T> {
+ factory List(int n) {
+ if (!isInt(n)) throw "Invalid argument";
+ if (n < 0) throw "Negative size";
+ return JS(@"new Array($0)", n);
+ }
+}
class Expect {
static void equals(var expected, var actual) {
« no previous file with comments | « frog/leg/emitter.dart ('k') | frog/leg/namer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698