Chromium Code Reviews| 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 841c0a88fed00aee9a2760345450609dc7b2014a..562dd5837103eeb34da96b8db641a56c32f4bef0 100644 |
| --- a/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| +++ b/dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart |
| @@ -1172,6 +1172,14 @@ class CodeEmitterTask extends CompilerTask { |
| if (code == null) return; |
| String name = namer.getName(member); |
| builder.addProperty(name, code); |
| + var metadata = buildMetadataFunction(member); |
| + if (metadata != null) { |
| + builder.addProperty('@$name', metadata); |
| + } |
| + String reflectionName = reflectionName(member); |
| + if (reflectionName != null) { |
| + builder.addProperty('+$reflectionName', js('0')); |
| + } |
| code = backend.generatedBailoutCode[member]; |
| if (code != null) { |
| builder.addProperty(namer.getBailoutName(member), code); |
| @@ -1181,10 +1189,6 @@ class CodeEmitterTask extends CompilerTask { |
| if (!parameters.optionalParameters.isEmpty) { |
| addParameterStubs(member, builder.addProperty); |
| } |
| - var metadata = buildMetadataFunction(member); |
| - if (metadata != null) { |
| - builder.addProperty('@$name', metadata); |
| - } |
| } else if (!member.isField()) { |
| compiler.internalError('unexpected kind: "${member.kind}"', |
| element: member); |
| @@ -1192,6 +1196,28 @@ class CodeEmitterTask extends CompilerTask { |
| emitExtraAccessors(member, builder); |
| } |
| + String reflectionName(Element element) { |
| + if (!compiler.mirrorsEnabled) return null; |
| + String name = element.name.slowToString(); |
| + if (element.isGetter()) return name; |
| + if (element.isSetter()) return '$name='; |
| + if (element.isFunction()) { |
| + FunctionElement function = element; |
| + int requiredParameterCount = function.requiredParameterCount(compiler); |
| + int optionalParameterCount = function.optionalParameterCount(compiler); |
| + if (function.isConstructor()) { |
| + return 'new $name:$requiredParameterCount:$optionalParameterCount'; |
|
kasperl
2013/06/04 14:05:55
Maybe share the suffix (compute it and stuff it in
ahe
2013/06/04 14:21:01
Done.
|
| + } else { |
| + return '$name:$requiredParameterCount:$optionalParameterCount'; |
| + } |
| + } |
| + if (element.isGenerativeConstructorBody()) { |
| + return null; |
| + } |
| + throw compiler.internalErrorOnElement( |
| + element, 'Do not know how to reflect on this'); |
| + } |
| + |
| /** |
| * Documentation wanted -- johnniwinther |
| * |
| @@ -3273,7 +3299,9 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { |
| return ''' |
| (function (reflectionData) { |
| if (!init.libraries) init.libraries = []; |
| + if (!init.mangledNames) init.mangledNames = {}; |
| var libraries = init.libraries; |
| + var mangledNames = init.mangledNames; |
| var hasOwnProperty = Object.prototype.hasOwnProperty; |
| var length = reflectionData.length; |
| for (var i = 0; i < length; i++) { |
| @@ -3294,14 +3322,18 @@ if (typeof document !== "undefined" && document.readyState !== "complete") { |
| ${namer.CURRENT_ISOLATE}[property] = element; |
| functions.push(property); |
| } else { |
| - var newDesc = {} |
| + var newDesc = {}; |
| + var previousProp; |
| for (var prop in element) { |
| if (!hasOwnProperty.call(element, prop)) continue; |
| - if (prop.substring(0, 1) == "@" && prop != "@") { |
| + var firstChar = prop.substring(0, 1); |
| + if (firstChar == "+") { |
| + mangledNames[previousProp] = prop.substring(1); |
| + } else if (firstChar == "@" && prop != "@") { |
| newDesc[prop.substring(1)]["${namer.metadataField}"] =''' |
| '''element[prop]; |
| } else { |
| - newDesc[prop] = element[prop]; |
| + newDesc[previousProp = prop] = element[prop]; |
| } |
| } |
| $classesCollector[property] = newDesc; |