Chromium Code Reviews| 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 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // constructor. | 210 // constructor. |
| 211 // For engines where we have access to the '__proto__' we can manipulate | 211 // For engines where we have access to the '__proto__' we can manipulate |
| 212 // the object literal directly. For other engines we have to create a new | 212 // the object literal directly. For other engines we have to create a new |
| 213 // object and copy over the members. | 213 // object and copy over the members. |
| 214 return ''' | 214 return ''' |
| 215 function(collectedClasses) { | 215 function(collectedClasses) { |
| 216 var hasOwnProperty = Object.prototype.hasOwnProperty; | 216 var hasOwnProperty = Object.prototype.hasOwnProperty; |
| 217 for (var cls in collectedClasses) { | 217 for (var cls in collectedClasses) { |
| 218 if (hasOwnProperty.call(collectedClasses, cls)) { | 218 if (hasOwnProperty.call(collectedClasses, cls)) { |
| 219 var desc = collectedClasses[cls]; | 219 var desc = collectedClasses[cls]; |
| 220 '''/* Get the superclass and the fields in the format Super;field1,field2 from | 220 '''/* Get the superclass and the fields in the format Super;field1,field2 from |
|
ngeoffray
2012/12/09 10:41:50
Update the comment?
| |
| 221 the null-string property on the descriptor. */''' | 221 the null-string property on the descriptor. */''' |
| 222 var s = desc[''].split(';'), supr = s[0]; | 222 var fields = desc[''], supr = desc['super']; |
|
ngeoffray
2012/12/09 10:41:50
why not put "supr = desc['super']" in an else bran
| |
| 223 var fields = s[1] == '' ? [] : s[1].split(','); | 223 if (typeof fields=='string') { |
|
ngeoffray
2012/12/09 10:41:50
spaces between '=='
| |
| 224 var s = fields.split(';'); supr = s[0]; | |
| 225 fields = s[1] == '' ? [] : s[1].split(','); | |
| 226 } | |
| 224 $isolatePropertiesName[cls] = $defineClassName(cls, fields, desc); | 227 $isolatePropertiesName[cls] = $defineClassName(cls, fields, desc); |
| 225 if (supr) $pendingClassesName[cls] = supr; | 228 if (supr) $pendingClassesName[cls] = supr; |
| 226 } | 229 } |
| 227 } | 230 } |
| 228 var pendingClasses = $pendingClassesName; | 231 var pendingClasses = $pendingClassesName; |
| 229 '''/* FinishClasses can be called multiple times. This means that we need to | 232 '''/* FinishClasses can be called multiple times. This means that we need to |
| 230 clear the pendingClasses property. */''' | 233 clear the pendingClasses property. */''' |
| 231 $pendingClassesName = {}; | 234 $pendingClassesName = {}; |
| 232 var finishedClasses = {}; | 235 var finishedClasses = {}; |
| 233 function finishClass(cls) { | 236 function finishClass(cls) { |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 } | 829 } |
| 827 String setterName = namer.setterName(member.getLibrary(), member.name); | 830 String setterName = namer.setterName(member.getLibrary(), member.name); |
| 828 buffer.add("$setterName: function(v) { " | 831 buffer.add("$setterName: function(v) { " |
| 829 "this.$fieldName = $helperName(v$additionalArgument); }"); | 832 "this.$fieldName = $helperName(v$additionalArgument); }"); |
| 830 } | 833 } |
| 831 | 834 |
| 832 void emitClassConstructor(ClassElement classElement, CodeBuffer buffer) { | 835 void emitClassConstructor(ClassElement classElement, CodeBuffer buffer) { |
| 833 /* Do nothing. */ | 836 /* Do nothing. */ |
| 834 } | 837 } |
| 835 | 838 |
| 839 void emitSuper(String superName, CodeBuffer buffer) { | |
| 840 /* Do nothing. */ | |
| 841 } | |
| 842 | |
| 836 void emitClassFields(ClassElement classElement, | 843 void emitClassFields(ClassElement classElement, |
| 837 CodeBuffer buffer, | 844 CodeBuffer buffer, |
| 838 bool emitEndingComma, | 845 bool emitEndingComma, |
| 839 { String superClass: "", | 846 { String superClass: "", |
| 840 bool isNative: false}) { | 847 bool isNative: false}) { |
| 841 bool isFirstField = true; | 848 bool isFirstField = true; |
| 842 bool isAnythingOutput = false; | 849 bool isAnythingOutput = false; |
| 843 if (!isNative) { | 850 if (!isNative) { |
| 844 buffer.add('"":"$superClass;'); | 851 buffer.add('"":"$superClass;'); |
| 845 isAnythingOutput = true; | 852 isAnythingOutput = true; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 needsDefineClass = true; | 964 needsDefineClass = true; |
| 958 String className = namer.getName(classElement); | 965 String className = namer.getName(classElement); |
| 959 ClassElement superclass = classElement.superclass; | 966 ClassElement superclass = classElement.superclass; |
| 960 String superName = ""; | 967 String superName = ""; |
| 961 if (superclass != null) { | 968 if (superclass != null) { |
| 962 superName = namer.getName(superclass); | 969 superName = namer.getName(superclass); |
| 963 } | 970 } |
| 964 | 971 |
| 965 buffer.add('$classesCollector.$className = {'); | 972 buffer.add('$classesCollector.$className = {'); |
| 966 emitClassConstructor(classElement, buffer); | 973 emitClassConstructor(classElement, buffer); |
| 974 emitSuper(superName, buffer); | |
| 967 emitClassFields(classElement, buffer, false, | 975 emitClassFields(classElement, buffer, false, |
| 968 superClass: superName, isNative: false); | 976 superClass: superName, isNative: false); |
| 969 // TODO(floitsch): the emitInstanceMember should simply always emit a ',\n'. | 977 // TODO(floitsch): the emitInstanceMember should simply always emit a ',\n'. |
| 970 // That does currently not work because the native classes have a different | 978 // That does currently not work because the native classes have a different |
| 971 // syntax. | 979 // syntax. |
| 972 emitClassGettersSetters(classElement, buffer, true); | 980 emitClassGettersSetters(classElement, buffer, true); |
| 973 emitInstanceMembers(classElement, buffer, true); | 981 emitInstanceMembers(classElement, buffer, true); |
| 974 buffer.add('\n};\n\n'); | 982 buffer.add('\n};\n\n'); |
| 975 } | 983 } |
| 976 | 984 |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1871 const String HOOKS_API_USAGE = """ | 1879 const String HOOKS_API_USAGE = """ |
| 1872 // Generated by dart2js, the Dart to JavaScript compiler. | 1880 // Generated by dart2js, the Dart to JavaScript compiler. |
| 1873 // The code supports the following hooks: | 1881 // The code supports the following hooks: |
| 1874 // dartPrint(message) - if this function is defined it is called | 1882 // dartPrint(message) - if this function is defined it is called |
| 1875 // instead of the Dart [print] method. | 1883 // instead of the Dart [print] method. |
| 1876 // dartMainRunner(main) - if this function is defined, the Dart [main] | 1884 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 1877 // method will not be invoked directly. | 1885 // method will not be invoked directly. |
| 1878 // Instead, a closure that will invoke [main] is | 1886 // Instead, a closure that will invoke [main] is |
| 1879 // passed to [dartMainRunner]. | 1887 // passed to [dartMainRunner]. |
| 1880 """; | 1888 """; |
| OLD | NEW |