| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 class CodeEmitterNoEvalTask extends CodeEmitterTask { | 7 class CodeEmitterNoEvalTask extends CodeEmitterTask { |
| 8 CodeEmitterNoEvalTask(Compiler compiler, | 8 CodeEmitterNoEvalTask(Compiler compiler, |
| 9 Namer namer, | 9 Namer namer, |
| 10 bool generateSourceMap) | 10 bool generateSourceMap) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 fieldNames.map((fieldName) => | 81 fieldNames.map((fieldName) => |
| 82 new js.ExpressionStatement( | 82 new js.ExpressionStatement( |
| 83 new js.Assignment( | 83 new js.Assignment( |
| 84 new js.This().dot(fieldName), | 84 new js.This().dot(fieldName), |
| 85 new js.VariableUse(fieldName))))))); | 85 new js.VariableUse(fieldName))))))); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void emitBoundClosureClassHeader(String mangledName, | 88 void emitBoundClosureClassHeader(String mangledName, |
| 89 String superName, | 89 String superName, |
| 90 List<String> fieldNames, | 90 List<String> fieldNames, |
| 91 CodeBuffer buffer) { | 91 ClassBuilder builder) { |
| 92 buffer.add("$classesCollector.$mangledName = {'': "); | 92 builder.addProperty('', buildConstructor(mangledName, fieldNames)); |
| 93 buffer.add( | 93 builder.addProperty('super', js.string(superName)); |
| 94 js.prettyPrint(buildConstructor(mangledName, fieldNames), compiler)); | |
| 95 buffer.add(",\n 'super': '$superName',\n"); | |
| 96 } | 94 } |
| 97 | 95 |
| 98 void emitClassConstructor(ClassElement classElement, CodeBuffer buffer) { | 96 void emitClassConstructor(ClassElement classElement, ClassBuilder builder) { |
| 99 // Say we have a class A with fields b, c and d, where c needs a getter and | 97 // Say we have a class A with fields b, c and d, where c needs a getter and |
| 100 // d needs both a getter and a setter. Then we produce: | 98 // d needs both a getter and a setter. Then we produce: |
| 101 // - a constructor (directly into the given [buffer]): | 99 // - a constructor (directly into the given [buffer]): |
| 102 // function A(b, c, d) { this.b = b, this.c = c, this.d = d; } | 100 // function A(b, c, d) { this.b = b, this.c = c, this.d = d; } |
| 103 // - getters and setters (stored in the [explicitGettersSetters] list): | 101 // - getters and setters (stored in the [explicitGettersSetters] list): |
| 104 // get$c : function() { return this.c; } | 102 // get$c : function() { return this.c; } |
| 105 // get$d : function() { return this.d; } | 103 // get$d : function() { return this.d; } |
| 106 // set$d : function(x) { this.d = x; } | 104 // set$d : function(x) { this.d = x; } |
| 107 List<String> fields = <String>[]; | 105 List<String> fields = <String>[]; |
| 108 visitClassFields(classElement, (Element member, | 106 visitClassFields(classElement, (Element member, |
| 109 String name, | 107 String name, |
| 110 String accessorName, | 108 String accessorName, |
| 111 bool needsGetter, | 109 bool needsGetter, |
| 112 bool needsSetter, | 110 bool needsSetter, |
| 113 bool needsCheckedSetter) { | 111 bool needsCheckedSetter) { |
| 114 fields.add(name); | 112 fields.add(name); |
| 115 }); | 113 }); |
| 116 String constructorName = namer.safeName(classElement.name.slowToString()); | 114 String constructorName = namer.safeName(classElement.name.slowToString()); |
| 117 buffer.add("'': "); | 115 |
| 118 buffer.add( | 116 builder.addProperty('', buildConstructor(constructorName, fields)); |
| 119 js.prettyPrint(buildConstructor(constructorName, fields), compiler)); | |
| 120 } | 117 } |
| 121 | 118 |
| 122 void emitSuper(String superName, CodeBuffer buffer) { | 119 void emitSuper(String superName, ClassBuilder builder) { |
| 123 if (superName != '') { | 120 if (superName != '') { |
| 124 buffer.add(",\n 'super': '$superName'"); | 121 builder.addProperty('super', js.string(superName)); |
| 125 } | 122 } |
| 126 } | 123 } |
| 127 | 124 |
| 128 void emitClassFields(ClassElement classElement, | 125 void emitClassFields(ClassElement classElement, |
| 129 CodeBuffer buffer, | 126 ClassBuilder builder, |
| 130 bool emitEndingComma, | |
| 131 { String superClass: "", | 127 { String superClass: "", |
| 132 bool classIsNative: false}) { | 128 bool classIsNative: false}) { |
| 133 if (emitEndingComma) buffer.add(', '); | |
| 134 } | 129 } |
| 135 | 130 |
| 136 bool get getterAndSetterCanBeImplementedByFieldSpec => false; | 131 bool get getterAndSetterCanBeImplementedByFieldSpec => false; |
| 137 } | 132 } |
| OLD | NEW |