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

Unified Diff: dart/frog/leg/emitter.dart

Issue 9429047: Implement operator-is for interfaces' supertypes and String's supertypes. Also, improve stack trace… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/emitter.dart
diff --git a/dart/frog/leg/emitter.dart b/dart/frog/leg/emitter.dart
index 960fb8a133e53aaa437eb2c1a59eaafa762b75ed..e91aa7098e7dc2a107cd31362251d041c8f475ec 100644
--- a/dart/frog/leg/emitter.dart
+++ b/dart/frog/leg/emitter.dart
@@ -134,7 +134,7 @@ function(child, parent) {
member, invocationName, arguments, buffer);
} else {
buffer.add(' return this.${namer.getName(member)}($arguments)');
- }
+ }
buffer.add('\n}\n');
}
@@ -262,19 +262,29 @@ function(child, parent) {
}
}
buffer.add('$prototype.${namer.operatorIs(classElement)} = true;\n');
- for (Type ifc in classElement.interfaces) {
- buffer.add('$prototype.${namer.operatorIs(ifc.element)} = true;\n');
- }
+ generateInterfacesIsTests(buffer, prototype, classElement);
if (superclass === null) {
- // JS "toString" wrapper. This gives better exceptions.
- buffer.add('$prototype.toString = function() {\n');
- buffer.add(' try {');
- buffer.add(' return ${namer.CURRENT_ISOLATE}');
- buffer.add('.builtin\$toString\$0\$1(this);');
- buffer.add(' } catch (ex) {');
- buffer.add(' return "uncaught exception in toString";');
- buffer.add(' }');
- buffer.add('};\n');
+ // JS "toString" wrapper. This gives better exceptions. The
+ // function must handle the situation where builtin$toString$0
+ // is not generated.
+ buffer.add('''
+$prototype.toString = function() {
+ try {
+ if (typeof ${namer.CURRENT_ISOLATE}.builtin\$toString\$0\$1 == 'function') {
+ return ${namer.CURRENT_ISOLATE}.builtin\$toString\$0\$1(this);
+ } else {
+ var name = this.constructor.name;
+ if (typeof name != 'string') {
+ name = this.constructor.toString();
+ name = name.match(/^\s*function\s*(\S*)\s*\(/)[1];
+ }
+ return "Instance of '" + name +"'";
+ }
+ } catch (ex) {
+ return "uncaught exception in toString";
+ }
+};
+''');
// Emit the noSuchMethods on the Object prototype now, so that
// the code in the dynamicMethod can find them. Note that the
@@ -284,6 +294,14 @@ function(child, parent) {
}
}
+ void generateInterfacesIsTests(StringBuffer buffer, String prototype,
+ ClassElement cls) {
+ for (Type ifc in cls.interfaces) {
+ buffer.add('$prototype.${namer.operatorIs(ifc.element)} = true;\n');
+ generateInterfacesIsTests(buffer, prototype, ifc.element);
+ }
+ }
+
void emitClasses(StringBuffer buffer) {
Set seenClasses = new Set<ClassElement>();
for (ClassElement element in compiler.universe.instantiatedClasses) {
@@ -473,7 +491,7 @@ function(child, parent) {
}
}
}
- }
+ }
}
void emitStaticNonFinalFieldInitializations(StringBuffer buffer) {
« no previous file with comments | « no previous file | dart/frog/leg/lib/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698