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 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2933 ..addAll(buildDefineClassAndFinishClassFunctionsIfNecessary()) | 2933 ..addAll(buildDefineClassAndFinishClassFunctionsIfNecessary()) |
2934 ..addAll(buildLazyInitializerFunctionIfNecessary()) | 2934 ..addAll(buildLazyInitializerFunctionIfNecessary()) |
2935 ..addAll(buildFinishIsolateConstructor()) | 2935 ..addAll(buildFinishIsolateConstructor()) |
2936 ); | 2936 ); |
2937 jsAst.FunctionDeclaration decl = new jsAst.FunctionDeclaration( | 2937 jsAst.FunctionDeclaration decl = new jsAst.FunctionDeclaration( |
2938 new jsAst.VariableDeclaration('init'), fun); | 2938 new jsAst.VariableDeclaration('init'), fun); |
2939 buffer.write(jsAst.prettyPrint(decl, compiler).getText()); | 2939 buffer.write(jsAst.prettyPrint(decl, compiler).getText()); |
2940 if (compiler.enableMinification) buffer.write('\n'); | 2940 if (compiler.enableMinification) buffer.write('\n'); |
2941 } | 2941 } |
2942 | 2942 |
2943 jsAst.Fun buildMetadataFunction(Element element) { | |
kasperl
2013/05/29 06:25:06
Add a comment that explains what the metadata func
ahe
2013/05/30 11:41:15
Done.
| |
2944 var metadata = []; | |
2945 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | |
2946 metadata.add(constantReference(link.head.value)); | |
2947 } | |
2948 return js.fun([], [js.return_(new jsAst.ArrayInitializer.from(metadata))]); | |
2949 } | |
2950 | |
2943 String assembleProgram() { | 2951 String assembleProgram() { |
2944 measure(() { | 2952 measure(() { |
2945 // Compute the required type checks to know which classes need a | 2953 // Compute the required type checks to know which classes need a |
2946 // 'is$' method. | 2954 // 'is$' method. |
2947 computeRequiredTypeChecks(); | 2955 computeRequiredTypeChecks(); |
2948 | 2956 |
2949 computeNeededClasses(); | 2957 computeNeededClasses(); |
2950 | 2958 |
2951 mainBuffer.add(GENERATED_BY); | 2959 mainBuffer.add(GENERATED_BY); |
2952 addComment(HOOKS_API_USAGE, mainBuffer); | 2960 addComment(HOOKS_API_USAGE, mainBuffer); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3038 // TODO(ahe): It is a hack to use compiler.sourceMapUri | 3046 // TODO(ahe): It is a hack to use compiler.sourceMapUri |
3039 // here. It should be relative to the main JavaScript | 3047 // here. It should be relative to the main JavaScript |
3040 // output file. | 3048 // output file. |
3041 uri = relativize( | 3049 uri = relativize( |
3042 compiler.sourceMapUri, library.canonicalUri, false); | 3050 compiler.sourceMapUri, library.canonicalUri, false); |
3043 } | 3051 } |
3044 if (buffer != null) { | 3052 if (buffer != null) { |
3045 mainBuffer | 3053 mainBuffer |
3046 ..write('["${library.getLibraryOrScriptName()}",$_') | 3054 ..write('["${library.getLibraryOrScriptName()}",$_') |
3047 ..write('"${uri}",$_') | 3055 ..write('"${uri}",$_') |
3056 ..write( | |
3057 jsAst.prettyPrint(buildMetadataFunction(library), compiler)) | |
3058 ..write(',$_') | |
3048 ..write('{$n') | 3059 ..write('{$n') |
3049 ..addBuffer(buffer) | 3060 ..addBuffer(buffer) |
3050 ..write('}],$n'); | 3061 ..write('}],$n'); |
3051 } | 3062 } |
3052 buffer = buffers[1]; | 3063 buffer = buffers[1]; |
3053 if (buffer != null) { | 3064 if (buffer != null) { |
3054 deferredBuffer | 3065 deferredBuffer |
3055 ..write('["${library.getLibraryOrScriptName()}",$_') | 3066 ..write('["${library.getLibraryOrScriptName()}",$_') |
3056 ..write('"${uri}",$_') | 3067 ..write('"${uri}",$_') |
3068 ..write('[],$_') | |
3057 ..write('{$n') | 3069 ..write('{$n') |
3058 ..addBuffer(buffer) | 3070 ..addBuffer(buffer) |
3059 ..write('}],$n'); | 3071 ..write('}],$n'); |
3060 } | 3072 } |
3061 libraryBuffers[library] = const []; | 3073 libraryBuffers[library] = const []; |
3062 } | 3074 } |
3063 mainBuffer.write('])$N'); | 3075 mainBuffer.write('])$N'); |
3064 | 3076 |
3065 deferredBuffer.write('])$N'); | 3077 deferredBuffer.write('])$N'); |
3066 if (!deferredClasses.isEmpty) { | 3078 if (!deferredClasses.isEmpty) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3233 const String REFLECTION_DATA_PARSER = r''' | 3245 const String REFLECTION_DATA_PARSER = r''' |
3234 (function (reflectionData) { | 3246 (function (reflectionData) { |
3235 if (!init.libraries) init.libraries = []; | 3247 if (!init.libraries) init.libraries = []; |
3236 var libraries = init.libraries; | 3248 var libraries = init.libraries; |
3237 var hasOwnProperty = Object.prototype.hasOwnProperty; | 3249 var hasOwnProperty = Object.prototype.hasOwnProperty; |
3238 var length = reflectionData.length; | 3250 var length = reflectionData.length; |
3239 for (var i = 0; i < length; i++) { | 3251 for (var i = 0; i < length; i++) { |
3240 var data = reflectionData[i]; | 3252 var data = reflectionData[i]; |
3241 var name = data[0]; | 3253 var name = data[0]; |
3242 var uri = data[1]; | 3254 var uri = data[1]; |
3243 var descriptor = data[2]; | 3255 var metadata = data[2]; |
3256 var descriptor = data[3]; | |
3244 var classes = []; | 3257 var classes = []; |
3245 var functions = []; | 3258 var functions = []; |
3246 for (var property in descriptor) { | 3259 for (var property in descriptor) { |
3247 if (!hasOwnProperty.call(descriptor, property)) continue; | 3260 if (!hasOwnProperty.call(descriptor, property)) continue; |
3248 var element = descriptor[property]; | 3261 var element = descriptor[property]; |
3249 if (typeof element === "function") { | 3262 if (typeof element === "function") { |
3250 $[property] = element; | 3263 $[property] = element; |
3251 functions.push(property); | 3264 functions.push(property); |
3252 } else { | 3265 } else { |
3253 $$[property] = element; | 3266 $$[property] = element; |
3254 classes.push(property); | 3267 classes.push(property); |
3255 classes.push(element[""]); | 3268 classes.push(element[""]); |
3256 } | 3269 } |
3257 } | 3270 } |
3258 libraries.push([name, uri, classes, functions]); | 3271 libraries.push([name, uri, classes, functions, metadata]); |
3259 } | 3272 } |
3260 })'''; | 3273 })'''; |
OLD | NEW |