| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; | 
| 6 | 6 | 
| 7 class MetadataEmitter extends CodeEmitterHelper { | 7 class MetadataEmitter extends CodeEmitterHelper { | 
| 8   /// A list of JS expressions that represent metadata, parameter names and | 8   /// A list of JS expressions that represent metadata, parameter names and | 
| 9   /// type, and return types. | 9   /// type, and return types. | 
| 10   final List<String> globalMetadata = []; | 10   final List<String> globalMetadata = []; | 
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96     return addGlobalMetadata('"$name"'); | 96     return addGlobalMetadata('"$name"'); | 
| 97   } | 97   } | 
| 98 | 98 | 
| 99   int addGlobalMetadata(String string) { | 99   int addGlobalMetadata(String string) { | 
| 100     return globalMetadataMap.putIfAbsent(string, () { | 100     return globalMetadataMap.putIfAbsent(string, () { | 
| 101       globalMetadata.add(string); | 101       globalMetadata.add(string); | 
| 102       return globalMetadata.length - 1; | 102       return globalMetadata.length - 1; | 
| 103     }); | 103     }); | 
| 104   } | 104   } | 
| 105 | 105 | 
| 106   void emitMetadata(CodeBuffer buffer) { | 106   void emitMetadata(CodeOutput output) { | 
| 107     String metadataAccess = emitter.generateEmbeddedGlobalAccessString( | 107     String metadataAccess = emitter.generateEmbeddedGlobalAccessString( | 
| 108           embeddedNames.METADATA); | 108           embeddedNames.METADATA); | 
| 109     buffer.write('$metadataAccess$_=$_['); | 109     output.add('$metadataAccess$_=$_['); | 
| 110     for (String metadata in globalMetadata) { | 110     for (String metadata in globalMetadata) { | 
| 111       if (metadata is String) { | 111       if (metadata is String) { | 
| 112         if (metadata != 'null') { | 112         if (metadata != 'null') { | 
| 113           buffer.write(metadata); | 113           output.add(metadata); | 
| 114         } | 114         } | 
| 115       } else { | 115       } else { | 
| 116         throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}'; | 116         throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}'; | 
| 117       } | 117       } | 
| 118       buffer.write(',$n'); | 118       output.add(',$n'); | 
| 119     } | 119     } | 
| 120     buffer.write('];$n'); | 120     output.add('];$n'); | 
| 121   } | 121   } | 
| 122 | 122 | 
| 123   List<int> computeMetadata(FunctionElement element) { | 123   List<int> computeMetadata(FunctionElement element) { | 
| 124     return compiler.withCurrentElement(element, () { | 124     return compiler.withCurrentElement(element, () { | 
| 125       if (!mustEmitMetadataFor(element)) return const <int>[]; | 125       if (!mustEmitMetadataFor(element)) return const <int>[]; | 
| 126       List<int> metadata = <int>[]; | 126       List<int> metadata = <int>[]; | 
| 127       Link link = element.metadata; | 127       Link link = element.metadata; | 
| 128       // TODO(ahe): Why is metadata sometimes null? | 128       // TODO(ahe): Why is metadata sometimes null? | 
| 129       if (link != null) { | 129       if (link != null) { | 
| 130         for (; !link.isEmpty; link = link.tail) { | 130         for (; !link.isEmpty; link = link.tail) { | 
| 131           metadata.add(reifyMetadata(link.head)); | 131           metadata.add(reifyMetadata(link.head)); | 
| 132         } | 132         } | 
| 133       } | 133       } | 
| 134       return metadata; | 134       return metadata; | 
| 135     }); | 135     }); | 
| 136   } | 136   } | 
| 137 } | 137 } | 
| OLD | NEW | 
|---|