Index: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
diff --git a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
index 6ecbfd5099e1e4ab723fd545a494966e5544cb0b..d29e89a9d59d23b382d3a7c82a015a01abcc7dc7 100644 |
--- a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
+++ b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
@@ -2940,6 +2940,24 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { |
if (compiler.enableMinification) buffer.write('\n'); |
} |
+ /// The metadata function returns the metadata associated with |
+ /// [element] in generated code. The metadata needs to be wrapped |
+ /// in a function as it refers to constants that may not have been |
+ /// constructed yet. For example, a class is allowed to be |
+ /// annotated with itself. The metadata function is used by |
+ /// mirrors_patch to implement DeclarationMirror.metadata. |
+ jsAst.Expression buildMetadataFunction(Element element) { |
+ if (compiler.mirrorSystemClass == null) return new jsAst.LiteralString(''); |
kasperl
2013/05/30 13:16:39
Add comment.
ahe
2013/05/30 13:28:45
Done.
|
+ var metadata = []; |
+ for (Link link = element.metadata; |
+ // TODO(ahe): Why is metadata sometimes null? |
kasperl
2013/05/30 13:16:39
Maybe move this check out of the loop so it sticks
ahe
2013/05/30 13:28:45
Done.
|
+ link != null && !link.isEmpty; |
+ link = link.tail) { |
+ metadata.add(constantReference(link.head.value)); |
+ } |
+ return js.fun([], [js.return_(new jsAst.ArrayInitializer.from(metadata))]); |
+ } |
+ |
String assembleProgram() { |
measure(() { |
// Compute the required type checks to know which classes need a |
@@ -3045,6 +3063,9 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { |
mainBuffer |
..write('["${library.getLibraryOrScriptName()}",$_') |
..write('"${uri}",$_') |
+ ..write( |
+ jsAst.prettyPrint(buildMetadataFunction(library), compiler)) |
+ ..write(',$_') |
..write('{$n') |
..addBuffer(buffer) |
..write('}],$n'); |
@@ -3054,6 +3075,7 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { |
deferredBuffer |
..write('["${library.getLibraryOrScriptName()}",$_') |
..write('"${uri}",$_') |
+ ..write('[],$_') |
..write('{$n') |
..addBuffer(buffer) |
..write('}],$n'); |
@@ -3240,7 +3262,8 @@ const String REFLECTION_DATA_PARSER = r''' |
var data = reflectionData[i]; |
var name = data[0]; |
var uri = data[1]; |
- var descriptor = data[2]; |
+ var metadata = data[2]; |
+ var descriptor = data[3]; |
var classes = []; |
var functions = []; |
for (var property in descriptor) { |
@@ -3255,6 +3278,6 @@ const String REFLECTION_DATA_PARSER = r''' |
classes.push(element[""]); |
} |
} |
- libraries.push([name, uri, classes, functions]); |
+ libraries.push([name, uri, classes, functions, metadata]); |
} |
})'''; |