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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 void print(var obj) { 5 void print(var obj) {
6 // TODO(ngeoffray): enable when the parser accepts it. 6 // TODO(ngeoffray): enable when the parser accepts it.
7 // obj = obj.toString(); 7 // obj = obj.toString();
8 var hasConsole = JS(@"typeof console == 'object'"); 8 var hasConsole = JS(@"typeof console == 'object'");
9 if (hasConsole) { 9 if (hasConsole) {
10 JS(@"console.log($0)", obj); 10 JS(@"console.log($0)", obj);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 235 }
236 236
237 237
238 builtin$get$length(var receiver) { 238 builtin$get$length(var receiver) {
239 if (JS(@"typeof $0 === 'string'", receiver) || isJSArray(receiver)) { 239 if (JS(@"typeof $0 === 'string'", receiver) || isJSArray(receiver)) {
240 return JS(@"$0.length", receiver); 240 return JS(@"$0.length", receiver);
241 } 241 }
242 throw "Unimplemented user-defined length."; 242 throw "Unimplemented user-defined length.";
243 } 243 }
244 244
245 bool isInt(var v) {
246 return JS(@"($0 | 0) === $1", v, v);
247 }
248
245 class int {} 249 class int {}
246 class double {} 250 class double {}
247 class String {} 251 class String {}
248 class bool {} 252 class bool {}
249 class Object {} 253 class Object {}
250 class List<T> {} 254 class List<T> {
255 factory List(int n) {
256 if (!isInt(n)) throw "Invalid length";
ahe 2011/12/22 13:32:39 What about negative sizes?
ngeoffray 2011/12/22 13:50:23 Done.
257 return JS(@"new Array($0)", n);
258 }
259 }
251 260
252 class Expect { 261 class Expect {
253 static void equals(var expected, var actual) { 262 static void equals(var expected, var actual) {
254 if (expected == actual) return; 263 if (expected == actual) return;
255 print('Expect.equals(expected: <' + expected.toString() + 264 print('Expect.equals(expected: <' + expected.toString() +
256 '>, actual:<' + actual.toString() + '> fails.'); 265 '>, actual:<' + actual.toString() + '> fails.');
257 throw 'Expect.equals failed.'; 266 throw 'Expect.equals failed.';
258 } 267 }
259 } 268 }
260 269
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 return JS(@"Math.floor($0)", elapsedMs); 306 return JS(@"Math.floor($0)", elapsedMs);
298 } else { 307 } else {
299 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); 308 return JS(@"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs);
300 } 309 }
301 } 310 }
302 311
303 int frequency() { 312 int frequency() {
304 return 1000; 313 return 1000;
305 } 314 }
306 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698