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

Unified 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: Work on IE 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/frog/leg/emitter.dart ('k') | dart/frog/tests/leg_only/src/ToStringTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/lib/core.dart
diff --git a/dart/frog/leg/lib/core.dart b/dart/frog/leg/lib/core.dart
index 30a517b6174dcbb244ba5c8b5817862c489e20a4..495c2b2c105f47772c0246f5d057faf4b1a02364 100644
--- a/dart/frog/leg/lib/core.dart
+++ b/dart/frog/leg/lib/core.dart
@@ -59,11 +59,8 @@ add(var a, var b) {
return JS("String", @"$0 + $1", a, b);
}
if (b === null) return JS("String", @"$0 + 'null'", a);
- if (isJSArray(b)) {
- return JS("String", @"$0 + 'Instance of \'List\''", a);
- }
// No further native values.
- b = UNINTERCEPTED(b.toString());
+ b = b.toString();
if (JS("bool", @"typeof $0 === 'string'", b)) {
return JS("String", @"$0 + $1", a, b);
}
@@ -283,7 +280,7 @@ builtin$get$length(var receiver) {
builtin$toString$0(var value) {
if (JS("bool", @"typeof $0 == 'object'", value)) {
if (isJSArray(value)) {
- return "Instance of List";
+ return "Instance of 'List'";
}
return UNINTERCEPTED(value.toString());
}
@@ -303,7 +300,16 @@ class int {}
class double {}
class String {}
class bool {}
-class Object {}
+class Object {
+ String toString() {
+ String name = JS('String', @'this.constructor.name');
+ if (name === null) {
+ name = JS('String', @'$0.match(/^\s*function\s*(\S*)\s*\(/)[1]',
+ JS('String', @'this.constructor.toString()'));
+ }
+ return "Instance of '$name'";
+ }
+}
class List<T> {
static void _checkConstructorInput(n) {
// TODO(ngeoffray): Inline once we support optional parameters or
« no previous file with comments | « dart/frog/leg/emitter.dart ('k') | dart/frog/tests/leg_only/src/ToStringTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698