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

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

Issue 9114053: Record names of constructors and use that to implement Object.toString. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 11 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) 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 obj = obj.toString(); 6 obj = obj.toString();
7 var hasConsole = JS("bool", @"typeof console == 'object'"); 7 var hasConsole = JS("bool", @"typeof console == 'object'");
8 if (hasConsole) { 8 if (hasConsole) {
9 JS("void", @"console.log($0)", obj); 9 JS("void", @"console.log($0)", obj);
10 } else { 10 } else {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 297
298 bool isInt(var v) { 298 bool isInt(var v) {
299 return JS("bool", @"($0 | 0) === $1", v, v); 299 return JS("bool", @"($0 | 0) === $1", v, v);
300 } 300 }
301 301
302 class int {} 302 class int {}
303 class double {} 303 class double {}
304 class String {} 304 class String {}
305 class bool {} 305 class bool {}
306 class Object {} 306 class Object {
307 toString() => "[Instance of '${JS('String', @'this.constructor.name')}']";
Lasse Reichstein 2012/01/11 09:49:16 and @'this.constructor.$name' here.
308 }
307 class List<T> { 309 class List<T> {
308 static void _checkConstructorInput(n) { 310 static void _checkConstructorInput(n) {
309 // TODO(ngeoffray): Inline once we support optional parameters or 311 // TODO(ngeoffray): Inline once we support optional parameters or
310 // bailout. 312 // bailout.
311 if (!isInt(n)) throw "Invalid argument"; 313 if (!isInt(n)) throw "Invalid argument";
312 if (n < 0) throw "Negative size"; 314 if (n < 0) throw "Negative size";
313 } 315 }
314 316
315 factory List(n) { 317 factory List(n) {
316 // TODO(ngeoffray): Adjust to optional parameters. 318 // TODO(ngeoffray): Adjust to optional parameters.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } else { 382 } else {
381 return 383 return
382 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs); 384 JS("num", @"Math.floor($0 + (Date.now() - $1))", elapsedMs, startMs);
383 } 385 }
384 } 386 }
385 387
386 int frequency() { 388 int frequency() {
387 return 1000; 389 return 1000;
388 } 390 }
389 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698