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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11415114: Do not generate empty native classes. Fixes issue 6872. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 | sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart (revision 15255)
+++ sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart (working copy)
@@ -237,7 +237,9 @@
for (var cls in collectedClasses) {
if (hasOwnProperty.call(collectedClasses, cls)) {
var desc = collectedClasses[cls];
- $isolatePropertiesName[cls] = $defineClassName(cls, desc[''], desc);
+'''/* If the class does not have any declared fields (in the ''
+ property of the description), then provide an empty list of fields. */'''
+ $isolatePropertiesName[cls] = $defineClassName(cls, desc[''] || [], desc);
if (desc['super'] !== "") $pendingClassesName[cls] = desc['super'];
}
}
@@ -678,12 +680,11 @@
*/
void emitInstanceMembers(ClassElement classElement,
CodeBuffer buffer,
- bool needsLeadingComma) {
+ bool emitLeadingComma) {
assert(invariant(classElement, classElement.isDeclaration));
- bool needsComma = needsLeadingComma;
void defineInstanceMember(String name, StringBuffer memberBuffer) {
- if (needsComma) buffer.add(',');
- needsComma = true;
+ if (emitLeadingComma) buffer.add(',');
+ emitLeadingComma = true;
buffer.add('\n');
buffer.add(' $name: ');
buffer.add(memberBuffer);
@@ -853,8 +854,9 @@
/* Do nothing. */
}
- void emitClassFields(ClassElement classElement, CodeBuffer buffer) {
- buffer.add('"": [');
+ void emitClassFields(ClassElement classElement,
+ CodeBuffer buffer,
+ bool emitEndingComma) {
bool isFirstField = true;
visitClassFields(classElement, (Element member,
String name,
@@ -863,6 +865,7 @@
bool needsSetter,
bool needsCheckedSetter) {
if (isFirstField) {
+ buffer.add('"": [');
isFirstField = false;
} else {
buffer.add(", ");
@@ -883,12 +886,19 @@
}
buffer.add('"');
});
- buffer.add(']');
+ if (!isFirstField) {
+ // There was at least one field.
+ buffer.add(']');
+ if (emitEndingComma) {
+ buffer.add(', ');
+ }
+ }
}
/** Each getter/setter must be prefixed with a ",\n ". */
- void emitClassGettersSetters(ClassElement classElement, CodeBuffer buffer,
- {bool omitLeadingComma: false}) {
+ void emitClassGettersSetters(ClassElement classElement,
+ CodeBuffer buffer,
+ bool emitLeadingComma) {
visitClassFields(classElement, (Element member,
String name,
String accessorName,
@@ -897,10 +907,10 @@
bool needsCheckedSetter) {
if (needsCheckedSetter) {
assert(!needsSetter);
- if (!omitLeadingComma) {
+ if (emitLeadingComma) {
buffer.add(",\n ");
} else {
- omitLeadingComma = false;
+ emitLeadingComma = true;
}
generateCheckedSetter(member, name, accessorName, buffer);
}
@@ -934,12 +944,12 @@
buffer.add('$classesCollector.$className = {');
emitClassConstructor(classElement, buffer);
- emitClassFields(classElement, buffer);
+ emitClassFields(classElement, buffer, true);
// TODO(floitsch): the emitInstanceMember should simply always emit a ',\n'.
// That does currently not work because the native classes have a different
// syntax.
- buffer.add(',\n "super": "$superName"');
- emitClassGettersSetters(classElement, buffer);
+ buffer.add('\n "super": "$superName"');
+ emitClassGettersSetters(classElement, buffer, true);
emitInstanceMembers(classElement, buffer, true);
buffer.add('\n};\n\n');
}
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698