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

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: One more test expectation 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 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) { 1246 if (compiler.codegenWorld.hasInvokedGetter(member, compiler)) {
1247 emitDynamicFunctionGetter(member, defineInstanceMember); 1247 emitDynamicFunctionGetter(member, defineInstanceMember);
1248 } 1248 }
1249 } 1249 }
1250 } 1250 }
1251 1251
1252 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) { 1252 void emitNoSuchMethodHandlers(DefineMemberFunction defineInstanceMember) {
1253 // Do not generate no such method handlers if there is no class. 1253 // Do not generate no such method handlers if there is no class.
1254 if (compiler.codegenWorld.instantiatedClasses.isEmpty) return; 1254 if (compiler.codegenWorld.instantiatedClasses.isEmpty) return;
1255 1255
1256 String noSuchMethodName = 1256 String noSuchMethodName = namer.publicInstanceMethodNameByArity(
1257 namer.publicInstanceMethodNameByArity(Compiler.NO_SUCH_METHOD, 2); 1257 Compiler.NO_SUCH_METHOD, Compiler.NO_SUCH_METHOD_ARG_COUNT);
1258 1258
1259 // Keep track of the JavaScript names we've already added so we 1259 // Keep track of the JavaScript names we've already added so we
1260 // do not introduce duplicates (bad for code size). 1260 // do not introduce duplicates (bad for code size).
1261 Set<String> addedJsNames = new Set<String>(); 1261 Set<String> addedJsNames = new Set<String>();
1262 1262
1263 // Keep track of the noSuchMethod holders for each possible 1263 // Keep track of the noSuchMethod holders for each possible
1264 // receiver type. 1264 // receiver type.
1265 Map<ClassElement, Set<ClassElement>> noSuchMethodHolders = 1265 Map<ClassElement, Set<ClassElement>> noSuchMethodHolders =
1266 new Map<ClassElement, Set<ClassElement>>(); 1266 new Map<ClassElement, Set<ClassElement>>();
1267 Set<ClassElement> noSuchMethodHoldersFor(DartType type) { 1267 Set<ClassElement> noSuchMethodHoldersFor(DartType type) {
1268 ClassElement element = type.element; 1268 ClassElement element = type.element;
1269 Set<ClassElement> result = noSuchMethodHolders[element]; 1269 Set<ClassElement> result = noSuchMethodHolders[element];
1270 if (result == null) { 1270 if (result == null) {
1271 // For now, we check the entire world to see if an object of 1271 // For now, we check the entire world to see if an object of
1272 // the given type may have a user-defined noSuchMethod 1272 // the given type may have a user-defined noSuchMethod
1273 // implementation. We could do better by only looking at 1273 // implementation. We could do better by only looking at
1274 // instantiated (or otherwise needed) classes. 1274 // instantiated (or otherwise needed) classes.
1275 result = compiler.world.findNoSuchMethodHolders(type); 1275 result = compiler.world.findNoSuchMethodHolders(type);
1276 noSuchMethodHolders[element] = result; 1276 noSuchMethodHolders[element] = result;
1277 } 1277 }
1278 return result; 1278 return result;
1279 } 1279 }
1280 1280
1281 CodeBuffer generateMethod(String methodName, Selector selector) { 1281 CodeBuffer generateMethod(String methodName, Selector selector) {
1282 // Values match JSInvocationMirror in js-helper library.
1283 const int METHOD = 0;
1284 const int GETTER = 1;
1285 const int SETTER = 2;
1286 int type = METHOD;
1287 if (selector.isGetter()) {
1288 type = GETTER;
1289 } else if (selector.isSetter()) {
1290 type = SETTER;
1291 }
1282 CodeBuffer args = new CodeBuffer(); 1292 CodeBuffer args = new CodeBuffer();
1283 for (int i = 0; i < selector.argumentCount; i++) { 1293 for (int i = 0; i < selector.argumentCount; i++) {
1284 if (i != 0) args.add(', '); 1294 if (i != 0) args.add(', ');
1285 args.add('\$$i'); 1295 args.add('\$$i');
1286 } 1296 }
1297 CodeBuffer argNames = new CodeBuffer();
1298 List<SourceString> names = selector.getOrderedNamedArguments();
1299 for (int i = 0; i < names.length; i++) {
1300 if (i != 0) argNames.add(', ');
1301 argNames.add('"');
1302 argNames.add(names[i].slowToString());
1303 argNames.add('"');
1304 }
1305 String internalName = namer.instanceMethodInvocationName(
1306 selector.library, new SourceString(methodName), selector);
1287 CodeBuffer buffer = new CodeBuffer(); 1307 CodeBuffer buffer = new CodeBuffer();
1288 buffer.add('function($args) {\n'); 1308 buffer.add('function($args) {\n');
1289 buffer.add(' return this.$noSuchMethodName("$methodName", [$args]);\n'); 1309 buffer.add(' return this.$noSuchMethodName('
1310 '\$.createInvocationMirror("$methodName", "$internalName",'
1311 ' $type, [$args], [$argNames]));\n');
1290 buffer.add(' }'); 1312 buffer.add(' }');
1291 return buffer; 1313 return buffer;
1292 } 1314 }
1293 1315
1294 void addNoSuchMethodHandlers(SourceString ignore, Set<Selector> selectors) { 1316 void addNoSuchMethodHandlers(SourceString ignore, Set<Selector> selectors) {
1295 // Cache the object class and type. 1317 // Cache the object class and type.
1296 ClassElement objectClass = compiler.objectClass; 1318 ClassElement objectClass = compiler.objectClass;
1297 DartType objectType = objectClass.computeType(compiler); 1319 DartType objectType = objectClass.computeType(compiler);
1298 1320
1299 for (Selector selector in selectors) { 1321 for (Selector selector in selectors) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 const String HOOKS_API_USAGE = """ 1587 const String HOOKS_API_USAGE = """
1566 // Generated by dart2js, the Dart to JavaScript compiler. 1588 // Generated by dart2js, the Dart to JavaScript compiler.
1567 // The code supports the following hooks: 1589 // The code supports the following hooks:
1568 // dartPrint(message) - if this function is defined it is called 1590 // dartPrint(message) - if this function is defined it is called
1569 // instead of the Dart [print] method. 1591 // instead of the Dart [print] method.
1570 // dartMainRunner(main) - if this function is defined, the Dart [main] 1592 // dartMainRunner(main) - if this function is defined, the Dart [main]
1571 // method will not be invoked directly. 1593 // method will not be invoked directly.
1572 // Instead, a closure that will invoke [main] is 1594 // Instead, a closure that will invoke [main] is
1573 // passed to [dartMainRunner]. 1595 // passed to [dartMainRunner].
1574 """; 1596 """;
OLDNEW
« no previous file with comments | « lib/compiler/implementation/enqueue.dart ('k') | lib/compiler/implementation/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698