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 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 assert(invariant(member, member.isDeclaration)); | 1154 assert(invariant(member, member.isDeclaration)); |
| 1155 // TODO(floitsch): we don't need to deal with members of | 1155 // TODO(floitsch): we don't need to deal with members of |
| 1156 // uninstantiated classes, that have been overwritten by subclasses. | 1156 // uninstantiated classes, that have been overwritten by subclasses. |
| 1157 | 1157 |
| 1158 if (member.isFunction() | 1158 if (member.isFunction() |
| 1159 || member.isGenerativeConstructorBody() | 1159 || member.isGenerativeConstructorBody() |
| 1160 || member.isAccessor()) { | 1160 || member.isAccessor()) { |
| 1161 if (member.isAbstract(compiler)) return; | 1161 if (member.isAbstract(compiler)) return; |
| 1162 jsAst.Expression code = backend.generatedCode[member]; | 1162 jsAst.Expression code = backend.generatedCode[member]; |
| 1163 if (code == null) return; | 1163 if (code == null) return; |
| 1164 builder.addProperty(namer.getName(member), code); | 1164 String name = namer.getName(member); |
| 1165 builder.addProperty(name, code); | |
| 1165 code = backend.generatedBailoutCode[member]; | 1166 code = backend.generatedBailoutCode[member]; |
| 1166 if (code != null) { | 1167 if (code != null) { |
| 1167 builder.addProperty(namer.getBailoutName(member), code); | 1168 builder.addProperty(namer.getBailoutName(member), code); |
| 1168 } | 1169 } |
| 1169 FunctionElement function = member; | 1170 FunctionElement function = member; |
| 1170 FunctionSignature parameters = function.computeSignature(compiler); | 1171 FunctionSignature parameters = function.computeSignature(compiler); |
| 1171 if (!parameters.optionalParameters.isEmpty) { | 1172 if (!parameters.optionalParameters.isEmpty) { |
| 1172 addParameterStubs(member, builder.addProperty); | 1173 addParameterStubs(member, builder.addProperty); |
| 1173 } | 1174 } |
| 1175 var metadata = buildMetadataFunction(member); | |
| 1176 if (metadata != null) { | |
| 1177 builder.addProperty('@$name', metadata); | |
| 1178 } | |
| 1174 } else if (!member.isField()) { | 1179 } else if (!member.isField()) { |
| 1175 compiler.internalError('unexpected kind: "${member.kind}"', | 1180 compiler.internalError('unexpected kind: "${member.kind}"', |
| 1176 element: member); | 1181 element: member); |
| 1177 } | 1182 } |
| 1178 emitExtraAccessors(member, builder); | 1183 emitExtraAccessors(member, builder); |
| 1179 } | 1184 } |
| 1180 | 1185 |
| 1181 /** | 1186 /** |
| 1182 * Documentation wanted -- johnniwinther | 1187 * Documentation wanted -- johnniwinther |
| 1183 * | 1188 * |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1789 Iterable<Element> elements = | 1794 Iterable<Element> elements = |
| 1790 backend.generatedCode.keys.where(isStaticFunction); | 1795 backend.generatedCode.keys.where(isStaticFunction); |
| 1791 Set<Element> pendingElementsWithBailouts = | 1796 Set<Element> pendingElementsWithBailouts = |
| 1792 backend.generatedBailoutCode.keys | 1797 backend.generatedBailoutCode.keys |
| 1793 .where(isStaticFunction) | 1798 .where(isStaticFunction) |
| 1794 .toSet(); | 1799 .toSet(); |
| 1795 | 1800 |
| 1796 for (Element element in Elements.sortedByPosition(elements)) { | 1801 for (Element element in Elements.sortedByPosition(elements)) { |
| 1797 CodeBuffer buffer = bufferForElement(element, eagerBuffer); | 1802 CodeBuffer buffer = bufferForElement(element, eagerBuffer); |
| 1798 jsAst.Expression code = backend.generatedCode[element]; | 1803 jsAst.Expression code = backend.generatedCode[element]; |
| 1799 emitStaticFunction(buffer, namer.getName(element), code); | 1804 String name = namer.getName(element); |
| 1805 emitStaticFunction(buffer, name, code); | |
| 1806 var metadata = buildMetadataFunction(element); | |
| 1807 if (metadata != null) { | |
| 1808 buffer.write(',$n$n"@$name":$_'); | |
| 1809 buffer.write(jsAst.prettyPrint(metadata, compiler)); | |
| 1810 } | |
| 1800 jsAst.Expression bailoutCode = backend.generatedBailoutCode[element]; | 1811 jsAst.Expression bailoutCode = backend.generatedBailoutCode[element]; |
| 1801 if (bailoutCode != null) { | 1812 if (bailoutCode != null) { |
| 1802 pendingElementsWithBailouts.remove(element); | 1813 pendingElementsWithBailouts.remove(element); |
| 1803 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); | 1814 emitStaticFunction(buffer, namer.getBailoutName(element), bailoutCode); |
| 1804 } | 1815 } |
| 1805 } | 1816 } |
| 1806 | 1817 |
| 1807 if (!pendingElementsWithBailouts.isEmpty) { | 1818 if (!pendingElementsWithBailouts.isEmpty) { |
| 1808 addComment('pendingElementsWithBailouts', eagerBuffer); | 1819 addComment('pendingElementsWithBailouts', eagerBuffer); |
| 1809 } | 1820 } |
| (...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3245 var data = reflectionData[i]; | 3256 var data = reflectionData[i]; |
| 3246 var name = data[0]; | 3257 var name = data[0]; |
| 3247 var uri = data[1]; | 3258 var uri = data[1]; |
| 3248 var metadata = data[2]; | 3259 var metadata = data[2]; |
| 3249 var descriptor = data[3]; | 3260 var descriptor = data[3]; |
| 3250 var classes = []; | 3261 var classes = []; |
| 3251 var functions = []; | 3262 var functions = []; |
| 3252 for (var property in descriptor) { | 3263 for (var property in descriptor) { |
| 3253 if (!hasOwnProperty.call(descriptor, property)) continue; | 3264 if (!hasOwnProperty.call(descriptor, property)) continue; |
| 3254 var element = descriptor[property]; | 3265 var element = descriptor[property]; |
| 3255 if (typeof element === "function") { | 3266 if (property.substring(0, 1) == "@") { |
| 3267 property = property.substring(1); | |
| 3268 ${namer.CURRENT_ISOLATE}[property].\$metadata = element; | |
|
ngeoffray
2013/06/03 06:51:55
Move '\$metadata' to a helper getter ?
ahe
2013/06/03 09:13:54
Done.
| |
| 3269 } else if (typeof element === "function") { | |
| 3256 ${namer.CURRENT_ISOLATE}[property] = element; | 3270 ${namer.CURRENT_ISOLATE}[property] = element; |
| 3257 functions.push(property); | 3271 functions.push(property); |
| 3258 } else { | 3272 } else { |
| 3259 $classesCollector[property] = element; | 3273 var newDesc = {} |
| 3274 for (var prop in element) { | |
| 3275 if (!hasOwnProperty.call(element, prop)) continue; | |
| 3276 if (prop.substring(0, 1) == "@" && prop != "@") { | |
| 3277 newDesc[prop.substring(1)].\$metadata = element[prop]; | |
| 3278 } else { | |
| 3279 newDesc[prop] = element[prop]; | |
| 3280 } | |
| 3281 } | |
| 3282 $classesCollector[property] = newDesc; | |
| 3260 classes.push(property); | 3283 classes.push(property); |
| 3261 classes.push(element[""]); | 3284 classes.push(element[""]); |
| 3262 } | 3285 } |
| 3263 } | 3286 } |
| 3264 libraries.push([name, uri, classes, functions, metadata]); | 3287 libraries.push([name, uri, classes, functions, metadata]); |
| 3265 } | 3288 } |
| 3266 })'''; | 3289 })'''; |
| 3267 } | 3290 } |
| 3268 } | 3291 } |
| 3269 | 3292 |
| 3270 const String GENERATED_BY = """ | 3293 const String GENERATED_BY = """ |
| 3271 // Generated by dart2js, the Dart to JavaScript compiler. | 3294 // Generated by dart2js, the Dart to JavaScript compiler. |
| 3272 """; | 3295 """; |
| 3273 | 3296 |
| 3274 const String HOOKS_API_USAGE = """ | 3297 const String HOOKS_API_USAGE = """ |
| 3275 // The code supports the following hooks: | 3298 // The code supports the following hooks: |
| 3276 // dartPrint(message) - if this function is defined it is called | 3299 // dartPrint(message) - if this function is defined it is called |
| 3277 // instead of the Dart [print] method. | 3300 // instead of the Dart [print] method. |
| 3278 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3301 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3279 // method will not be invoked directly. | 3302 // method will not be invoked directly. |
| 3280 // Instead, a closure that will invoke [main] is | 3303 // Instead, a closure that will invoke [main] is |
| 3281 // passed to [dartMainRunner]. | 3304 // passed to [dartMainRunner]. |
| 3282 """; | 3305 """; |
| OLD | NEW |