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

Unified Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 889703004: dart2js: emit tear-offs in new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix rename. Created 5 years, 11 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
index d13108a3a767d5860f8f4e4d3794776291687681..a537e5c12b21b002d2730c13b41e2de07bf95f83 100644
--- a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart
@@ -395,19 +395,12 @@ class ModelEmitter {
} else {
elements.add(_generateConstructor(cls));
}
- Iterable<Method> methods = cls.methods.expand((Method method) {
- // TODO(floitsch): can there be anything else than a DartMethod?
- if (method is DartMethod) {
- return [method]..addAll(method.parameterStubs);
- } else {
- return [method];
- }
- });
+ Iterable<Method> methods = cls.methods;
Iterable<Method> isChecks = cls.isChecks;
Iterable<Method> gettersSetters = _generateGettersSetters(cls);
Iterable<Method> allMethods =
[methods, isChecks, gettersSetters].expand((x) => x);
- elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code]));
+ elements.addAll(allMethods.expand(emitInstanceMethod));
return unparse(compiler, new js.ArrayInitializer(elements));
}
@@ -416,6 +409,51 @@ class ModelEmitter {
return unparse(compiler, field.code);
}
+ static final String tearOffBoilerplate = """
+function(prototype, tearOffDescriptor) {
+ prototype[tearOffDescriptor[0]] = tearOffDescriptor[1];
+ for (var i = 3; i < tearOffDescriptor.length; i += 3) {
+ // Copy over the parameter stubs.
+ prototype[tearOffDescriptor[i]] = tearOffDescriptor[i + 2];
+ }
+ // Build the functions map.
+ var funcs = Object.create(null);
+ for (var i = 3; i < tearOffDescriptor.length; i += 3) {
+ // Copy over the parameter stubs.
+ prototype[tearOffDescriptor[i]] = tearOffDescriptor[i + 2];
+ }
+
+}
+""";
+
+ Iterable<js.Expression> emitInstanceMethod(Method method) {
+
+ List<js.Expression> makeNameCodePair(Method method) {
+ return [js.string(method.name), method.code];
+ }
+
+ List<js.Expression> makeNameCallNameCodeTriplet(ParameterStubMethod stub) {
+ js.Expression callName = stub.callName == null
+ ? new js.LiteralNull()
+ : js.string(stub.callName);
+ return [js.string(stub.name), callName, method.code];
+ }
+
+ if (method is DartMethod) {
+ if (method.needsTearOff) {
+ var data = makeNameCodePair(method);
+ data.add(js.string(method.tearOffName));
+ data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet));
+ return [new js.ArrayInitializer(data)];
+ } else {
+ // TODO(floitsch): not the most efficient way...
+ return ([method]..addAll(method.parameterStubs)).expand(makeNameCodePair);
zarah 2015/01/30 14:24:23 long line.
+ }
+ } else {
+ return makeNameCodePair(method);
+ }
+ }
+
Iterable<js.Expression> emitStaticMethod(StaticMethod method) {
js.Expression holderIndex = js.number(method.holder.index);
List<js.Expression> output = <js.Expression>[];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698