| OLD | NEW |
| 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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 alreadyGenerated.add(invocationName); | 472 alreadyGenerated.add(invocationName); |
| 473 | 473 |
| 474 JavaScriptBackend backend = compiler.backend; | 474 JavaScriptBackend backend = compiler.backend; |
| 475 bool isInterceptorClass = | 475 bool isInterceptorClass = |
| 476 backend.isInterceptorClass(member.getEnclosingClass()); | 476 backend.isInterceptorClass(member.getEnclosingClass()); |
| 477 | 477 |
| 478 // If the method is in an interceptor class, we need to also pass | 478 // If the method is in an interceptor class, we need to also pass |
| 479 // the actual receiver. | 479 // the actual receiver. |
| 480 int extraArgumentCount = isInterceptorClass ? 1 : 0; | 480 int extraArgumentCount = isInterceptorClass ? 1 : 0; |
| 481 // Use '$receiver' to avoid clashes with other parameter names. Using | 481 // Use '$receiver' to avoid clashes with other parameter names. Using |
| 482 // '$receiver' works because [JsNames.getValid] used for getting parameter | 482 // '$receiver' works because [:namer.safeName:] used for getting parameter |
| 483 // names never returns a name beginning with a single '$'. | 483 // names never returns a name beginning with a single '$'. |
| 484 String receiverArgumentName = r'$receiver'; | 484 String receiverArgumentName = r'$receiver'; |
| 485 | 485 |
| 486 // The parameters that this stub takes. | 486 // The parameters that this stub takes. |
| 487 List<js.Parameter> parametersBuffer = | 487 List<js.Parameter> parametersBuffer = |
| 488 new List<js.Parameter>.fixedLength( | 488 new List<js.Parameter>.fixedLength( |
| 489 selector.argumentCount + extraArgumentCount); | 489 selector.argumentCount + extraArgumentCount); |
| 490 // The arguments that will be passed to the real method. | 490 // The arguments that will be passed to the real method. |
| 491 List<js.Expression> argumentsBuffer = | 491 List<js.Expression> argumentsBuffer = |
| 492 new List<js.Expression>.fixedLength( | 492 new List<js.Expression>.fixedLength( |
| 493 parameters.parameterCount + extraArgumentCount); | 493 parameters.parameterCount + extraArgumentCount); |
| 494 | 494 |
| 495 int count = 0; | 495 int count = 0; |
| 496 if (isInterceptorClass) { | 496 if (isInterceptorClass) { |
| 497 count++; | 497 count++; |
| 498 parametersBuffer[0] = new js.Parameter(receiverArgumentName); | 498 parametersBuffer[0] = new js.Parameter(receiverArgumentName); |
| 499 argumentsBuffer[0] = new js.VariableUse(receiverArgumentName); | 499 argumentsBuffer[0] = new js.VariableUse(receiverArgumentName); |
| 500 } | 500 } |
| 501 | 501 |
| 502 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; | 502 int indexOfLastOptionalArgumentInParameters = positionalArgumentCount - 1; |
| 503 TreeElements elements = | 503 TreeElements elements = |
| 504 compiler.enqueuer.resolution.getCachedElements(member); | 504 compiler.enqueuer.resolution.getCachedElements(member); |
| 505 | 505 |
| 506 parameters.orderedForEachParameter((Element element) { | 506 parameters.orderedForEachParameter((Element element) { |
| 507 String jsName = JsNames.getValid(element.name.slowToString()); | 507 String jsName = backend.namer.safeName(element.name.slowToString()); |
| 508 assert(jsName != receiverArgumentName); | 508 assert(jsName != receiverArgumentName); |
| 509 int optionalParameterStart = positionalArgumentCount + extraArgumentCount; | 509 int optionalParameterStart = positionalArgumentCount + extraArgumentCount; |
| 510 if (count < optionalParameterStart) { | 510 if (count < optionalParameterStart) { |
| 511 parametersBuffer[count] = new js.Parameter(jsName); | 511 parametersBuffer[count] = new js.Parameter(jsName); |
| 512 argumentsBuffer[count] = new js.VariableUse(jsName); | 512 argumentsBuffer[count] = new js.VariableUse(jsName); |
| 513 } else { | 513 } else { |
| 514 int index = names.indexOf(element.name); | 514 int index = names.indexOf(element.name); |
| 515 if (index != -1) { | 515 if (index != -1) { |
| 516 indexOfLastOptionalArgumentInParameters = count; | 516 indexOfLastOptionalArgumentInParameters = count; |
| 517 // The order of the named arguments is not the same as the | 517 // The order of the named arguments is not the same as the |
| (...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 """; | 2178 """; |
| 2179 const String HOOKS_API_USAGE = """ | 2179 const String HOOKS_API_USAGE = """ |
| 2180 // The code supports the following hooks: | 2180 // The code supports the following hooks: |
| 2181 // dartPrint(message) - if this function is defined it is called | 2181 // dartPrint(message) - if this function is defined it is called |
| 2182 // instead of the Dart [print] method. | 2182 // instead of the Dart [print] method. |
| 2183 // dartMainRunner(main) - if this function is defined, the Dart [main] | 2183 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 2184 // method will not be invoked directly. | 2184 // method will not be invoked directly. |
| 2185 // Instead, a closure that will invoke [main] is | 2185 // Instead, a closure that will invoke [main] is |
| 2186 // passed to [dartMainRunner]. | 2186 // passed to [dartMainRunner]. |
| 2187 """; | 2187 """; |
| OLD | NEW |