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

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: rebased 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/leg/ssa/nodes.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 b10a1104d0de27bd84c12af3fa28739189fb243a..5247b1bfb01e9d65769ed9d534702a01547d6108 100644
--- a/dart/frog/leg/lib/core.dart
+++ b/dart/frog/leg/lib/core.dart
@@ -48,22 +48,7 @@ add(var a, var b) {
if (checkNumbers(a, b, "num+ expects a number as second operand.")) {
return JS("num", @"$0 + $1", a, b);
} else if (JS("bool", @"typeof $0 === 'string'", a)) {
- if (JS("bool", @"typeof $0 === 'string'", b) ||
- JS("bool", @"typeof $0 === 'boolean'", b)) {
- return JS("String", @"$0 + $1", a, b);
- }
- if (JS("bool", @"typeof $0 === 'number'", b)) {
- if (JS("bool", @"$0 === 0 && (1/$0) < 0", b)) {
- return JS("String", @"$0 + '-0.0'", a);
- }
- 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 +268,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());
}
@@ -321,8 +306,18 @@ 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> /* implements Iterable<T> */ {
+
static void _checkConstructorInput(n) {
// TODO(ngeoffray): Inline once we support optional parameters or
// bailout.
« no previous file with comments | « dart/frog/leg/emitter.dart ('k') | dart/frog/leg/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698