| 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 /** | 5 /** |
| 6 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 String staticName = namer.getName(element); | 643 String staticName = namer.getName(element); |
| 644 int parameterCount = element.parameterCount(compiler); | 644 int parameterCount = element.parameterCount(compiler); |
| 645 String invocationName = | 645 String invocationName = |
| 646 namer.instanceMethodName(element.getLibrary(), callElement.name, | 646 namer.instanceMethodName(element.getLibrary(), callElement.name, |
| 647 parameterCount); | 647 parameterCount); |
| 648 String fieldAccess = '$isolateProperties.$staticName'; | 648 String fieldAccess = '$isolateProperties.$staticName'; |
| 649 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n"); | 649 buffer.add("$fieldAccess.$invocationName = $fieldAccess;\n"); |
| 650 addParameterStubs(callElement, (String name, String value) { | 650 addParameterStubs(callElement, (String name, String value) { |
| 651 buffer.add('$fieldAccess.$name = $value;\n'); | 651 buffer.add('$fieldAccess.$name = $value;\n'); |
| 652 }); | 652 }); |
| 653 // If a static function is used as a closure we need to add its name |
| 654 // in case it is used in spawnFunction. |
| 655 String fieldName = Namer.STATIC_CLOSURE_NAME_NAME; |
| 656 buffer.add('$fieldAccess.$fieldName = "$staticName";\n'); |
| 653 } | 657 } |
| 654 } | 658 } |
| 655 | 659 |
| 656 void emitDynamicFunctionGetter(FunctionElement member, | 660 void emitDynamicFunctionGetter(FunctionElement member, |
| 657 defineInstanceMember(String invocationName, | 661 defineInstanceMember(String invocationName, |
| 658 String definition)) { | 662 String definition)) { |
| 659 // For every method that has the same name as a property-get we create a | 663 // For every method that has the same name as a property-get we create a |
| 660 // getter that returns a bound closure. Say we have a class 'A' with method | 664 // getter that returns a bound closure. Say we have a class 'A' with method |
| 661 // 'foo' and somewhere in the code there is a dynamic property get of | 665 // 'foo' and somewhere in the code there is a dynamic property get of |
| 662 // 'foo'. Then we generate the following code (in pseudo Dart/JavaScript): | 666 // 'foo'. Then we generate the following code (in pseudo Dart/JavaScript): |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 mainBuffer.add('function init() {\n'); | 1029 mainBuffer.add('function init() {\n'); |
| 1026 mainBuffer.add(' $isolateProperties = {};\n'); | 1030 mainBuffer.add(' $isolateProperties = {};\n'); |
| 1027 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); | 1031 addDefineClassAndFinishClassFunctionsIfNecessary(mainBuffer); |
| 1028 emitFinishIsolateConstructor(mainBuffer); | 1032 emitFinishIsolateConstructor(mainBuffer); |
| 1029 mainBuffer.add('}\n'); | 1033 mainBuffer.add('}\n'); |
| 1030 compiler.assembledCode = mainBuffer.toString(); | 1034 compiler.assembledCode = mainBuffer.toString(); |
| 1031 }); | 1035 }); |
| 1032 return compiler.assembledCode; | 1036 return compiler.assembledCode; |
| 1033 } | 1037 } |
| 1034 } | 1038 } |
| OLD | NEW |