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

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

Issue 11366224: Move some string methods in the interceptor, and support for optional parameters in intercepted met… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 List<SourceString> names = selector.getOrderedNamedArguments(); 387 List<SourceString> names = selector.getOrderedNamedArguments();
388 388
389 String invocationName = 389 String invocationName =
390 namer.instanceMethodInvocationName(member.getLibrary(), member.name, 390 namer.instanceMethodInvocationName(member.getLibrary(), member.name,
391 selector); 391 selector);
392 if (alreadyGenerated.contains(invocationName)) return; 392 if (alreadyGenerated.contains(invocationName)) return;
393 alreadyGenerated.add(invocationName); 393 alreadyGenerated.add(invocationName);
394 CodeBuffer buffer = new CodeBuffer(); 394 CodeBuffer buffer = new CodeBuffer();
395 buffer.add('function('); 395 buffer.add('function(');
396 396
397 JavaScriptBackend backend = compiler.backend;
ahe 2012/11/13 18:41:26 Looks like this variable is only used once.
ngeoffray 2012/11/14 09:24:44 Yes, but I need the 'cast' to JavaScriptBackend.
398 bool isInterceptorClass =
399 backend.isInterceptorClass(member.getEnclosingClass());
400
401 // If the method is in an interceptor class, we need to also pass
402 // the actual receiver.
403 int extraArgumentCount = isInterceptorClass ? 1 : 0;
404
397 // The parameters that this stub takes. 405 // The parameters that this stub takes.
398 List<String> parametersBuffer = new List<String>(selector.argumentCount); 406 List<String> parametersBuffer =
407 new List<String>(selector.argumentCount + extraArgumentCount);
399 // The arguments that will be passed to the real method. 408 // The arguments that will be passed to the real method.
400 List<String> argumentsBuffer = new List<String>(parameters.parameterCount); 409 List<String> argumentsBuffer =
410 new List<String>(parameters.parameterCount + extraArgumentCount);
401 411
402 int count = 0; 412 int count = 0;
413 if (isInterceptorClass) {
414 count++;
415 // Use $ to avoid clashes with other parameter names.
floitsch 2012/11/13 18:20:01 Too brittle. Discuss with Erik how this should be
ngeoffray 2012/11/14 09:18:43 Note that this is not touched by the minifier. I c
floitsch 2012/11/14 10:06:33 1. It should go through the minifier (eventually).
ngeoffray 2012/11/14 10:10:58 It doesn't have to be an accident, just an interna
floitsch 2012/11/14 10:18:45 Yes. there are several possibilities. That's why I
floitsch 2012/11/14 12:01:26 As Erik suggests: this should work for now. Please
416 parametersBuffer[0] = r'$';
417 argumentsBuffer[0] = r'$';
418 }
419
403 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; 420 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1;
404 TreeElements elements = 421 TreeElements elements =
405 compiler.enqueuer.resolution.getCachedElements(member); 422 compiler.enqueuer.resolution.getCachedElements(member);
406 423
407 parameters.orderedForEachParameter((Element element) { 424 parameters.orderedForEachParameter((Element element) {
408 String jsName = JsNames.getValid(element.name.slowToString()); 425 String jsName = JsNames.getValid(element.name.slowToString());
409 if (count < positionalArgumentCount) { 426 if (count < positionalArgumentCount + extraArgumentCount) {
410 parametersBuffer[count] = jsName; 427 parametersBuffer[count] = jsName;
411 argumentsBuffer[count] = jsName; 428 argumentsBuffer[count] = jsName;
412 } else { 429 } else {
413 int index = names.indexOf(element.name); 430 int index = names.indexOf(element.name);
414 if (index != -1) { 431 if (index != -1) {
415 indexOfLastOptionalArgumentInParameters = count; 432 indexOfLastOptionalArgumentInParameters = count;
416 // The order of the named arguments is not the same as the 433 // The order of the named arguments is not the same as the
417 // one in the real method (which is in Dart source order). 434 // one in the real method (which is in Dart source order).
418 argumentsBuffer[count] = jsName; 435 argumentsBuffer[count] = jsName;
419 parametersBuffer[selector.positionalArgumentCount + index] = jsName; 436 parametersBuffer[selector.positionalArgumentCount + index] = jsName;
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 const String HOOKS_API_USAGE = """ 1678 const String HOOKS_API_USAGE = """
1662 // Generated by dart2js, the Dart to JavaScript compiler. 1679 // Generated by dart2js, the Dart to JavaScript compiler.
1663 // The code supports the following hooks: 1680 // The code supports the following hooks:
1664 // dartPrint(message) - if this function is defined it is called 1681 // dartPrint(message) - if this function is defined it is called
1665 // instead of the Dart [print] method. 1682 // instead of the Dart [print] method.
1666 // dartMainRunner(main) - if this function is defined, the Dart [main] 1683 // dartMainRunner(main) - if this function is defined, the Dart [main]
1667 // method will not be invoked directly. 1684 // method will not be invoked directly.
1668 // Instead, a closure that will invoke [main] is 1685 // Instead, a closure that will invoke [main] is
1669 // passed to [dartMainRunner]. 1686 // passed to [dartMainRunner].
1670 """; 1687 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698