Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2194)

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 15979020: Implement InstanceMirror.invoke (minified). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/lib/js_mirrors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..33e311c6c4c40974c54d4d864246c5abc0060a84 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,25 @@ 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);
+ String suffix = '$name:$requiredParameterCount:$optionalParameterCount';
+ return (function.isConstructor()) ? 'new $suffix' : suffix;
+ }
+ if (element.isGenerativeConstructorBody()) {
+ return null;
+ }
+ throw compiler.internalErrorOnElement(
+ element, 'Do not know how to reflect on this');
+ }
+
/**
* Documentation wanted -- johnniwinther
*
@@ -3273,7 +3296,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 +3319,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;
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/lib/js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698