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 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3014 | 3014 |
3015 emitStaticFunctions(mainBuffer); | 3015 emitStaticFunctions(mainBuffer); |
3016 | 3016 |
3017 if (!libraryBuffers.isEmpty) { | 3017 if (!libraryBuffers.isEmpty) { |
3018 var oldClassesCollector = classesCollector; | 3018 var oldClassesCollector = classesCollector; |
3019 classesCollector = r"$$"; | 3019 classesCollector = r"$$"; |
3020 if (compiler.enableMinification) { | 3020 if (compiler.enableMinification) { |
3021 mainBuffer.write(';'); | 3021 mainBuffer.write(';'); |
3022 } | 3022 } |
3023 mainBuffer | 3023 mainBuffer |
3024 ..write(REFLECTION_DATA_PARSER) | 3024 ..write(getReflectionDataParser()) |
3025 ..write('([$n'); | 3025 ..write('([$n'); |
3026 emitDeferredPreambleWhenEmpty(deferredBuffer); | 3026 emitDeferredPreambleWhenEmpty(deferredBuffer); |
3027 deferredBuffer.add('\$\$$_=$_{};$n'); | 3027 deferredBuffer.add('\$\$$_=$_{};$n'); |
3028 | 3028 |
3029 deferredBuffer | 3029 deferredBuffer |
3030 ..write(REFLECTION_DATA_PARSER) | 3030 ..write(getReflectionDataParser()) |
3031 ..write('([$n'); | 3031 ..write('([$n'); |
3032 var sortedLibraries = Elements.sortedByPosition(libraryBuffers.keys); | 3032 var sortedLibraries = Elements.sortedByPosition(libraryBuffers.keys); |
3033 for (LibraryElement library in sortedLibraries) { | 3033 for (LibraryElement library in sortedLibraries) { |
3034 List<CodeBuffer> buffers = libraryBuffers[library]; | 3034 List<CodeBuffer> buffers = libraryBuffers[library]; |
3035 var buffer = buffers[0]; | 3035 var buffer = buffers[0]; |
3036 var uri = library.canonicalUri; | 3036 var uri = library.canonicalUri; |
3037 if (uri.scheme == 'file' && compiler.sourceMapUri != null) { | 3037 if (uri.scheme == 'file' && compiler.sourceMapUri != null) { |
3038 // TODO(ahe): It is a hack to use compiler.sourceMapUri | 3038 // TODO(ahe): It is a hack to use compiler.sourceMapUri |
3039 // here. It should be relative to the main JavaScript | 3039 // here. It should be relative to the main JavaScript |
3040 // output file. | 3040 // output file. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3205 bool isDeferred(Element element) { | 3205 bool isDeferred(Element element) { |
3206 return compiler.deferredLoadTask.isDeferred(element); | 3206 return compiler.deferredLoadTask.isDeferred(element); |
3207 } | 3207 } |
3208 | 3208 |
3209 // TODO(ahe): Remove this when deferred loading is fully implemented. | 3209 // TODO(ahe): Remove this when deferred loading is fully implemented. |
3210 void warnNotImplemented(Element element, String message) { | 3210 void warnNotImplemented(Element element, String message) { |
3211 compiler.reportMessage(compiler.spanFromSpannable(element), | 3211 compiler.reportMessage(compiler.spanFromSpannable(element), |
3212 MessageKind.GENERIC.error({'text': message}), | 3212 MessageKind.GENERIC.error({'text': message}), |
3213 api.Diagnostic.WARNING); | 3213 api.Diagnostic.WARNING); |
3214 } | 3214 } |
3215 } | |
3216 | 3215 |
3217 const String GENERATED_BY = """ | 3216 // TODO(ahe): This code should be integrated in finishClasses. |
3218 // Generated by dart2js, the Dart to JavaScript compiler. | 3217 String getReflectionDataParser() { |
3219 """; | 3218 return ''' |
3220 | |
3221 const String HOOKS_API_USAGE = """ | |
3222 // The code supports the following hooks: | |
3223 // dartPrint(message) - if this function is defined it is called | |
3224 // instead of the Dart [print] method. | |
3225 // dartMainRunner(main) - if this function is defined, the Dart [main] | |
3226 // method will not be invoked directly. | |
3227 // Instead, a closure that will invoke [main] is | |
3228 // passed to [dartMainRunner]. | |
3229 """; | |
3230 | |
3231 // TODO(ahe): This code should be integrated in finishClasses. | |
3232 // TODO(ahe): The uri field below is fake. | |
3233 const String REFLECTION_DATA_PARSER = r''' | |
3234 (function (reflectionData) { | 3219 (function (reflectionData) { |
3235 if (!init.libraries) init.libraries = []; | 3220 if (!init.libraries) init.libraries = []; |
3236 var libraries = init.libraries; | 3221 var libraries = init.libraries; |
3237 var hasOwnProperty = Object.prototype.hasOwnProperty; | 3222 var hasOwnProperty = Object.prototype.hasOwnProperty; |
3238 var length = reflectionData.length; | 3223 var length = reflectionData.length; |
3239 for (var i = 0; i < length; i++) { | 3224 for (var i = 0; i < length; i++) { |
3240 var data = reflectionData[i]; | 3225 var data = reflectionData[i]; |
3241 var name = data[0]; | 3226 var name = data[0]; |
3242 var uri = data[1]; | 3227 var uri = data[1]; |
3243 var descriptor = data[2]; | 3228 var descriptor = data[2]; |
3244 var classes = []; | 3229 var classes = []; |
3245 var functions = []; | 3230 var functions = []; |
3246 for (var property in descriptor) { | 3231 for (var property in descriptor) { |
3247 if (!hasOwnProperty.call(descriptor, property)) continue; | 3232 if (!hasOwnProperty.call(descriptor, property)) continue; |
3248 var element = descriptor[property]; | 3233 var element = descriptor[property]; |
3249 if (typeof element === "function") { | 3234 if (typeof element === "function") { |
3250 $[property] = element; | 3235 ${namer.CURRENT_ISOLATE}[property] = element; |
3251 functions.push(property); | 3236 functions.push(property); |
3252 } else { | 3237 } else { |
3253 $$[property] = element; | 3238 $classesCollector[property] = element; |
3254 classes.push(property); | 3239 classes.push(property); |
3255 classes.push(element[""]); | 3240 classes.push(element[""]); |
3256 } | 3241 } |
3257 } | 3242 } |
3258 libraries.push([name, uri, classes, functions]); | 3243 libraries.push([name, uri, classes, functions]); |
3259 } | 3244 } |
3260 })'''; | 3245 })'''; |
| 3246 } |
| 3247 } |
| 3248 |
| 3249 const String GENERATED_BY = """ |
| 3250 // Generated by dart2js, the Dart to JavaScript compiler. |
| 3251 """; |
| 3252 |
| 3253 const String HOOKS_API_USAGE = """ |
| 3254 // The code supports the following hooks: |
| 3255 // dartPrint(message) - if this function is defined it is called |
| 3256 // instead of the Dart [print] method. |
| 3257 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 3258 // method will not be invoked directly. |
| 3259 // Instead, a closure that will invoke [main] is |
| 3260 // passed to [dartMainRunner]. |
| 3261 """; |
OLD | NEW |