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

Side by Side Diff: dart/frog/leg/lib/core.dart

Issue 9359039: Source in most stuff. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: changes 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #library('core'); 5 #library('core');
6 6
7 #import('coreimpl.dart'); 7 #import('coreimpl.dart');
8 8
9 #import('js_helper.dart'); // TODO(ahe): remove this import. 9 #import('js_helper.dart'); // TODO(ahe): remove this import.
10 10
11 #source('../../../corelib/src/bool.dart');
12 #source('../../../corelib/src/collection.dart');
13 #source('../../../corelib/src/comparable.dart');
14 #source('../../../corelib/src/date.dart');
15 #source('../../../corelib/src/double.dart');
16 #source('../../../corelib/src/duration.dart');
17 // #source('../../../corelib/src/exceptions.dart');
18 // #source('../../../corelib/src/expect.dart');
19 #source('../../../corelib/src/function.dart');
20 #source('../../../corelib/src/future.dart');
21 #source('../../../corelib/src/hashable.dart');
22 #source('../../../corelib/src/int.dart');
23 #source('../../../corelib/src/isolate.dart');
24 #source('../../../corelib/src/iterable.dart');
25 #source('../../../corelib/src/iterator.dart');
26 // #source('../../../corelib/src/list.dart');
27 #source('../../../corelib/src/map.dart');
28 #source('../../../corelib/src/math.dart');
29 #source('../../../corelib/src/num.dart');
30 #source('../../../corelib/src/options.dart');
31 #source('../../../corelib/src/pattern.dart');
32 #source('../../../corelib/src/promise.dart');
33 #source('../../../corelib/src/proxy.dart');
34 #source('../../../corelib/src/queue.dart');
35 #source('../../../corelib/src/regexp.dart');
36 #source('../../../corelib/src/set.dart');
37 // #source('../../../corelib/src/stopwatch.dart');
38 #source('../../../corelib/src/string.dart');
39 #source('../../../corelib/src/string_buffer.dart');
40 #source('../../../corelib/src/strings.dart');
41 #source('../../../corelib/src/time_zone.dart');
42
11 void print(var obj) { 43 void print(var obj) {
12 obj = obj.toString(); 44 obj = obj.toString();
13 var hasConsole = JS("bool", @"typeof console == 'object'"); 45 var hasConsole = JS("bool", @"typeof console == 'object'");
14 if (hasConsole) { 46 if (hasConsole) {
15 JS("void", @"console.log($0)", obj); 47 JS("void", @"console.log($0)", obj);
16 } else { 48 } else {
17 JS("void", @"write($0)", obj); 49 JS("void", @"write($0)", obj);
18 JS("void", @"write('\n')"); 50 JS("void", @"write('\n')");
19 } 51 }
20 } 52 }
21 53
22 /* Include when interfaces are implemented
23 interface Iterable<T> {
24 Iterator<T> iterator();
25 }
26
27 interface Iterator<T> {
28 bool hasNext();
29 T next();
30 }
31 */
32 class int {}
33 class double {}
34 class String {}
35 class bool {}
36 class num {}
37 class Object { 54 class Object {
38 String toString() { 55 String toString() {
39 String name = JS('String', @'this.constructor.name'); 56 String name = JS('String', @'this.constructor.name');
40 if (name === null) { 57 if (name === null) {
41 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]', 58 name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]',
42 JS('String', @'this.constructor.toString()')); 59 JS('String', @'this.constructor.toString()'));
43 } 60 }
44 return "Instance of '$name'"; 61 return "Instance of '$name'";
45 } 62 }
46 63
47 void noSuchMethod(String name, List args) { 64 void noSuchMethod(String name, List args) {
48 throw new NoSuchMethodException(this, name, args); 65 throw new NoSuchMethodException(this, name, args);
49 } 66 }
50 } 67 }
51 68
52 class NoSuchMethodException { 69 class NoSuchMethodException {
53 Object receiver; 70 Object receiver;
54 String name; 71 String name;
55 List args; 72 List args;
56 NoSuchMethodException(Object this.receiver, String this.name, List this.args); 73 NoSuchMethodException(Object this.receiver, String this.name, List this.args);
57 String toString() { 74 String toString() {
58 return "NoSuchMethodException - receiver: '$receiver'" + 75 return "NoSuchMethodException - receiver: '$receiver'" +
59 "function name: '$name' arguments: [$args]"; 76 "function name: '$name' arguments: [$args]";
60 } 77 }
61 } 78 }
62 79
63 class List<T> /* implements Iterable<T> */ { 80 class List<T> implements Iterable<T> {
64 81
65 factory List([int length]) { 82 factory List([int length]) {
66 if (length == null) return JS("Object", @"new Array()"); 83 if (length == null) return JS("Object", @"new Array()");
67 if (!(length is int)) throw "Invalid argument"; 84 if (!(length is int)) throw "Invalid argument";
68 if (length < 0) throw "Negative size"; 85 if (length < 0) throw "Negative size";
69 return JS("Object", @"new Array($0)", length); 86 return JS("Object", @"new Array($0)", length);
70 } 87 }
71 } 88 }
72 89
73 class ListIterator<T> /* implements Iterator<T> */ { 90 class ListIterator<T> implements Iterator<T> {
74 int i; 91 int i;
75 List<T> list; 92 List<T> list;
76 ListIterator(List<T> this.list) : i = 0; 93 ListIterator(List<T> this.list) : i = 0;
77 bool hasNext() => i < JS("int", @"$0.length", list); 94 bool hasNext() => i < JS("int", @"$0.length", list);
78 T next() { 95 T next() {
79 var value = JS("Object", @"$0[$1]", list, i); 96 var value = JS("Object", @"$0[$1]", list, i);
80 i += 1; 97 i += 1;
81 return value; 98 return value;
82 } 99 }
83 } 100 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } else { 180 } else {
164 return 181 return
165 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); 182 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs);
166 } 183 }
167 } 184 }
168 185
169 int frequency() { 186 int frequency() {
170 return 1000; 187 return 1000;
171 } 188 }
172 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698