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

Unified Diff: pkg/compiler/lib/src/js_emitter/class_stub_generator.dart

Issue 897643002: dart2js: move generation of noSuchMethodStubs into ClassStubGenerator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
Index: pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
diff --git a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
index d7e1578c9962a0ecc46ba159681e45a0fd10f593..a9381a49f65faff9080f1c9a1d9eae94bc27189c 100644
--- a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
@@ -111,4 +111,76 @@ class ClassStubGenerator {
return generatedStubs;
}
+
+ void computeSelectorsForNsmHandlers(Map<String, Selector> jsNames) {
+
+ // Do not generate no such method handlers if there is no class.
+ if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) return;
+
+ void addNoSuchMethodHandlers(String ignore, Set<Selector> selectors) {
+ // Cache the object class and type.
+ ClassElement objectClass = compiler.objectClass;
+ DartType objectType = objectClass.rawType;
+
+ for (Selector selector in selectors) {
+ TypeMask mask = selector.mask;
+ if (mask == null) {
+ mask = new TypeMask.subclass(compiler.objectClass,
+ compiler.world);
+ }
+
+ if (!mask.needsNoSuchMethodHandling(selector, compiler.world)) {
+ continue;
+ }
+ String jsName = namer.invocationMirrorInternalName(selector);
+ jsNames[jsName] = selector;
+ }
+ }
+
+ compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers);
+ compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers);
+ compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers);
+ }
+
+ jsAst.Expression generateStubForNoSuchMethod(Selector selector) {
+ // Values match JSInvocationMirror in js-helper library.
+ int type = selector.invocationMirrorKind;
+ List<String> parameterNames =
+ new List.generate(selector.argumentCount, (i) => '\$$i');
+
+ List<jsAst.Expression> argNames =
+ selector.getOrderedNamedArguments().map((String name) =>
+ js.string(name)).toList();
+
+ String methodName = selector.invocationMirrorMemberName;
+ String internalName = namer.invocationMirrorInternalName(selector);
+
+ assert(backend.isInterceptedName(Compiler.NO_SUCH_METHOD));
+ jsAst.Expression expression =
+ js('''this.#noSuchMethodName(this,
+ #createInvocationMirror(#methodName,
+ #internalName,
+ #type,
+ #arguments,
+ #namedArguments))''',
+ {'noSuchMethodName': namer.noSuchMethodName,
+ 'createInvocationMirror':
+ backend.emitter.staticFunctionAccess(
+ backend.getCreateInvocationMirror()),
+ 'methodName':
+ js.string(compiler.enableMinification
+ ? internalName : methodName),
+ 'internalName': js.string(internalName),
+ 'type': js.number(type),
+ 'arguments':
+ new jsAst.ArrayInitializer(parameterNames.map(js).toList()),
+ 'namedArguments': new jsAst.ArrayInitializer(argNames)});
+
+ if (backend.isInterceptedName(selector.name)) {
+ return js(r'function($receiver, #) { return # }',
+ [parameterNames, expression]);
+ } else {
+ return js(r'function(#) { return # }', [parameterNames, expression]);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698