Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| index e081a178fa18f3a691edac9ed597760bf54c732e..bc8672a6997b23cf1a23b2ca53156cdc3f26b492 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| @@ -135,12 +135,12 @@ class CodeEmitterTask extends CompilerTask { |
| } |
| String get defineClassFunction { |
| - // First the class name, then the super class name, followed by the fields |
| - // (in an array) and the members (inside an Object literal). |
| + // First the class name, then the field names in an array and the members |
| + // (inside an Object literal). |
| // The caller can also pass in the constructor as a function if needed. |
| // |
| // Example: |
| - // defineClass("A", "B", ["x", "y"], { |
| + // defineClass("A", ["x", "y"], { |
|
karlklose
2012/11/30 11:43:34
Shouldn't this be
defineClass("A":"B@x.y", {
?
erikcorry
2012/11/30 12:05:57
No, this is called from finishClassesFunction, whe
ngeoffray
2012/11/30 12:11:46
So where is B in defineClass now?
erikcorry
2012/11/30 12:20:02
We don't need the superclass here, so it's nowhere
|
| // foo$1: function(y) { |
| // print(this.x + y); |
| // }, |
| @@ -214,10 +214,12 @@ function(collectedClasses) { |
| for (var cls in collectedClasses) { |
| if (hasOwnProperty.call(collectedClasses, cls)) { |
| var desc = collectedClasses[cls]; |
| -'''/* 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']; |
| +'''/* Get the superclass and the fields in the format Super@field1.field2 from |
| + the null-string property on the descriptor. */''' |
| + var s = desc[''].split('@'), supr = s[0]; |
| + var fields = s[1] == '' ? [] : s[1].split('.'); |
| + $isolatePropertiesName[cls] = $defineClassName(cls, fields, desc); |
| + if (supr) $pendingClassesName[cls] = supr; |
| } |
| } |
| var pendingClasses = $pendingClassesName; |
| @@ -248,7 +250,7 @@ function(collectedClasses) { |
| constructor.prototype = newPrototype; |
| newPrototype.constructor = constructor; |
| for (var member in prototype) { |
| - if (member == '' || member == 'super') continue; |
| + if (!member) continue; '''/* if (member == '') */''' |
|
ngeoffray
2012/11/30 12:11:46
What is this comment about?
erikcorry
2012/11/30 12:20:02
The comment shows the intent, the actual code does
|
| if (hasOwnProperty.call(prototype, member)) { |
| newPrototype[member] = prototype[member]; |
| } |
| @@ -826,38 +828,47 @@ $lazyInitializerLogic |
| void emitClassFields(ClassElement classElement, |
| CodeBuffer buffer, |
| - bool emitEndingComma) { |
| + { String superClass: "", |
| + bool isNative: false, |
| + bool emitEndingComma: false}) { |
|
ngeoffray
2012/11/30 12:11:46
Please don't put emitEndingComma optional. Other m
erikcorry
2012/11/30 12:20:02
I'll revert this in a later CL.
|
| + assert(!isNative || superClass != ""); |
| bool isFirstField = true; |
| + bool isAnythingOutput = false; |
| + if (!isNative) { |
| + buffer.add('"":"$superClass@'); |
| + isAnythingOutput = true; |
| + } |
| visitClassFields(classElement, (Element member, |
| String name, |
| bool needsGetter, |
| bool needsSetter, |
| bool needsCheckedSetter) { |
| - |
| if (!getterAndSetterCanBeImplementedByFieldSpec( |
| member, name, needsGetter, needsSetter)) { |
| return; |
| } |
| - |
| - if (isFirstField) { |
| - buffer.add('"": ['); |
| - isFirstField = false; |
| - } else { |
| - buffer.add(", "); |
| - } |
| - buffer.add('"$name'); |
| - if (needsGetter && needsSetter) { |
| - buffer.add(GETTER_SETTER_SUFFIX); |
| - } else if (needsGetter) { |
| - buffer.add(GETTER_SUFFIX); |
| - } else if (needsSetter) { |
| - buffer.add(SETTER_SUFFIX); |
| + if (!isNative || needsCheckedSetter || needsGetter || needsSetter) { |
| + if (isFirstField) { |
| + isFirstField = false; |
| + if (!isAnythingOutput) { |
| + buffer.add('"":"'); |
| + isAnythingOutput = true; |
| + } |
| + } else { |
| + buffer.add("."); |
| + } |
| + buffer.add('$name'); |
| + if (needsGetter && needsSetter) { |
| + buffer.add(GETTER_SETTER_SUFFIX); |
| + } else if (needsGetter) { |
| + buffer.add(GETTER_SUFFIX); |
| + } else if (needsSetter) { |
| + buffer.add(SETTER_SUFFIX); |
| + } |
| } |
| - buffer.add('"'); |
| }); |
| - if (!isFirstField) { |
| - // There was at least one field. |
| - buffer.add(']'); |
| + if (isAnythingOutput) { |
| + buffer.add('"'); |
| if (emitEndingComma) { |
| buffer.add(','); |
| } |
| @@ -947,12 +958,12 @@ $lazyInitializerLogic |
| buffer.add('$classesCollector.$className = {'); |
| emitClassConstructor(classElement, buffer); |
| - emitClassFields(classElement, buffer, true); |
| + emitClassFields(classElement, buffer, superClass: superName, |
| + isNative: false, emitEndingComma: false); |
| // 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, true); |
| + emitClassGettersSetters(classElement, buffer, false); |
| emitInstanceMembers(classElement, buffer, true); |
| buffer.add('\n};\n\n'); |
| } |
| @@ -1160,11 +1171,10 @@ $lazyInitializerLogic |
| String superName, |
| String extraArgument, |
| CodeBuffer buffer) { |
| - extraArgument = extraArgument.isEmpty ? '' : ", '$extraArgument'"; |
| + extraArgument = extraArgument.isEmpty ? '' : ".$extraArgument"; |
| buffer.add(""" |
| $classesCollector.$mangledName = {'': |
| -['self'$extraArgument, 'target'], |
| -'super': '$superName', |
| +\"$superName@self$extraArgument.target\", |
| """); |
| } |