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

Side by Side Diff: lib/compiler/implementation/js_backend/emitter.dart

Issue 11231074: Change signature of noSuchMethod to take an InvocationMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix dart2js, update tests, expectations. Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) { 1261 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) {
1262 emitDynamicFunctionGetter(member, defineInstanceMember); 1262 emitDynamicFunctionGetter(member, defineInstanceMember);
1263 } 1263 }
1264 } 1264 }
1265 } 1265 }
1266 1266
1267 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) { 1267 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) {
1268 // Do not generate no such method handlers if there is no class. 1268 // Do not generate no such method handlers if there is no class.
1269 if (compiler.codegenWorld.instantiatedClasses.isEmpty) return; 1269 if (compiler.codegenWorld.instantiatedClasses.isEmpty) return;
1270 1270
1271 String noSuchMethodName = 1271 String noSuchMethodName = namer.publicInstanceMethodNameByArity(
1272 namer.publicInstanceMethodNameByArity(Compiler.NO_SUCH_METHOD, 2); 1272 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT);
1273 1273
1274 // Keep track of the JavaScript names we've already added so we 1274 // Keep track of the JavaScript names we've already added so we
1275 // do not introduce duplicates (bad for code size). 1275 // do not introduce duplicates (bad for code size).
1276 Set<String> addedJsNames = new Set<String>(); 1276 Set<String> addedJsNames = new Set<String>();
1277 1277
1278 // Keep track of the noSuchMethod holders for each possible 1278 // Keep track of the noSuchMethod holders for each possible
1279 // receiver type. 1279 // receiver type.
1280 Map<ClassElement, Set<ClassElement>> noSuchMethodHolders = 1280 Map<ClassElement, Set<ClassElement>> noSuchMethodHolders =
1281 new Map<ClassElement, Set<ClassElement>>(); 1281 new Map<ClassElement, Set<ClassElement>>();
1282 Set<ClassElement> noSuchMethodHoldersFor(DartType type) { 1282 Set<ClassElement> noSuchMethodHoldersFor(DartType type) {
1283 ClassElement element = type.element; 1283 ClassElement element = type.element;
1284 Set<ClassElement> result = noSuchMethodHolders[element]; 1284 Set<ClassElement> result = noSuchMethodHolders[element];
1285 if (result == null) { 1285 if (result == null) {
1286 // For now, we check the entire world to see if an object of 1286 // For now, we check the entire world to see if an object of
1287 // the given type may have a user-defined noSuchMethod 1287 // the given type may have a user-defined noSuchMethod
1288 // implementation. We could do better by only looking at 1288 // implementation. We could do better by only looking at
1289 // instantiated (or otherwise needed) classes. 1289 // instantiated (or otherwise needed) classes.
1290 result = compiler.world.findNoSuchMethodHolders(type); 1290 result = compiler.world.findNoSuchMethodHolders(type);
1291 noSuchMethodHolders[element] = result; 1291 noSuchMethodHolders[element] = result;
1292 } 1292 }
1293 return result; 1293 return result;
1294 } 1294 }
1295 1295
1296 CodeBuffer generateMethod(String methodName, Selector selector) { 1296 CodeBuffer generateMethod(String methodName, Selector selector) {
1297 // Values match JSInvocationMirror in js-helper library.
1298 const int METHOD = 0;
1299 const int GETTER = 1;
1300 const int SETTER = 2;
1301 int type = METHOD;
1302 if (selector.isGetter()) {
1303 type = GETTER;
1304 } else if (selector.isSetter()) {
1305 type = SETTER;
1306 }
1297 CodeBuffer args = new CodeBuffer(); 1307 CodeBuffer args = new CodeBuffer();
1298 for (int i = 0; i < selector.argumentCount; i++) { 1308 for (int i = 0; i < selector.argumentCount; i++) {
1299 if (i != 0) args.add(', '); 1309 if (i != 0) args.add(', ');
1300 args.add('\$$i'); 1310 args.add('\$$i');
1301 } 1311 }
1312 CodeBuffer argNames = new CodeBuffer();
1313 List<SourceString> names = selector.getOrderedNamedArguments();
1314 for (int i = 0; i < names.length; i++) {
1315 if (i != 0) argNames.add(', ');
1316 argNames.add('"');
1317 argNames.add(names[i].slowToString());
1318 argNames.add('"');
1319 }
1320 String internalName = namer.instanceMethodInvocationName(
1321 selector.library, new SourceString(methodName), selector);
1302 CodeBuffer buffer = new CodeBuffer(); 1322 CodeBuffer buffer = new CodeBuffer();
1303 buffer.add('function($args) {\n'); 1323 buffer.add('function($args) {\n');
1304 buffer.add(' return this.$noSuchMethodName("$methodName", [$args]);\n'); 1324 buffer.add(' return this.$noSuchMethodName('
1325 '\$.createInvocationMirror("$methodName", "$internalName",'
1326 ' $type, [$args], [$argNames]));\n');
1305 buffer.add(' }'); 1327 buffer.add(' }');
1306 return buffer; 1328 return buffer;
1307 } 1329 }
1308 1330
1309 void addNoSuchMethodHandlers(SourceString ignore, Set<Selector> selectors) { 1331 void addNoSuchMethodHandlers(SourceString ignore, Set<Selector> selectors) {
1310 // Cache the object class and type. 1332 // Cache the object class and type.
1311 ClassElement objectClass = compiler.objectClass; 1333 ClassElement objectClass = compiler.objectClass;
1312 DartType objectType = objectClass.computeType(compiler); 1334 DartType objectType = objectClass.computeType(compiler);
1313 1335
1314 for (Selector selector in selectors) { 1336 for (Selector selector in selectors) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 const String HOOKS_API_USAGE = """ 1602 const String HOOKS_API_USAGE = """
1581 // Generated by dart2js, the Dart to JavaScript compiler. 1603 // Generated by dart2js, the Dart to JavaScript compiler.
1582 // The code supports the following hooks: 1604 // The code supports the following hooks:
1583 // dartPrint(message) - if this function is defined it is called 1605 // dartPrint(message) - if this function is defined it is called
1584 // instead of the Dart [print] method. 1606 // instead of the Dart [print] method.
1585 // dartMainRunner(main) - if this function is defined, the Dart [main] 1607 // dartMainRunner(main) - if this function is defined, the Dart [main]
1586 // method will not be invoked directly. 1608 // method will not be invoked directly.
1587 // Instead, a closure that will invoke [main] is 1609 // Instead, a closure that will invoke [main] is
1588 // passed to [dartMainRunner]. 1610 // passed to [dartMainRunner].
1589 """; 1611 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698