| 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 * Generates the code for all used classes in the program. Static fields (even | 6 * Generates the code for all used classes in the program. Static fields (even |
| 7 * in classes) are ignored, since they can be treated as non-class elements. | 7 * in classes) are ignored, since they can be treated as non-class elements. |
| 8 * | 8 * |
| 9 * The code for the containing (used) methods must exist in the [:universe:]. | 9 * The code for the containing (used) methods must exist in the [:universe:]. |
| 10 */ | 10 */ |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 // } | 493 // } |
| 494 | 494 |
| 495 // TODO(floitsch): share the closure classes with other classes | 495 // TODO(floitsch): share the closure classes with other classes |
| 496 // if they share methods with the same signature. | 496 // if they share methods with the same signature. |
| 497 | 497 |
| 498 // The closure class. | 498 // The closure class. |
| 499 SourceString name = const SourceString("BoundClosure"); | 499 SourceString name = const SourceString("BoundClosure"); |
| 500 CompilationUnitElement compilationUnit = member.getCompilationUnit(); | 500 CompilationUnitElement compilationUnit = member.getCompilationUnit(); |
| 501 ClassElement closureClassElement = new ClassElement(name, compilationUnit); | 501 ClassElement closureClassElement = new ClassElement(name, compilationUnit); |
| 502 String isolateAccess = namer.isolatePropertyAccess(closureClassElement); | 502 String isolateAccess = namer.isolatePropertyAccess(closureClassElement); |
| 503 buffer.add("$isolateAccess = function(self) { this.self = self; };\n"); | 503 |
| 504 // Define the constructor with a name so that Object.toString can |
| 505 // find the class name of the closure class. |
| 506 buffer.add("$isolateAccess = function $name(self) "); |
| 507 buffer.add("{ this.self = self; };\n"); |
| 508 |
| 509 // Make the closure class extend Object. |
| 510 addInheritFunctionIfNecessary(buffer); |
| 511 ClassElement objectClass = |
| 512 compiler.coreLibrary.find(const SourceString('Object')); |
| 513 String superName = namer.isolatePropertyAccess(objectClass); |
| 514 buffer.add('${inheritsName}($isolateAccess, $superName);\n'); |
| 515 |
| 504 String prototype = "$isolateAccess.prototype"; | 516 String prototype = "$isolateAccess.prototype"; |
| 505 | 517 |
| 506 // Now add the methods on the closure class. The instance method does not | 518 // Now add the methods on the closure class. The instance method does not |
| 507 // have the correct name. Since [addParameterStubs] use the name to create | 519 // have the correct name. Since [addParameterStubs] use the name to create |
| 508 // its stubs we simply create a fake element with the correct name. | 520 // its stubs we simply create a fake element with the correct name. |
| 509 // Note: the callElement will not have the correct modifiers (in case | 521 // Note: the callElement will not have the correct modifiers (in case |
| 510 // of static functions) and will not have any enclosingElement. | 522 // of static functions) and will not have any enclosingElement. |
| 511 FunctionElement callElement = | 523 FunctionElement callElement = |
| 512 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, member, null); | 524 new FunctionElement.from(Namer.CLOSURE_INVOCATION_NAME, member, null); |
| 513 | 525 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 emitCallStubForGetters(buffer); | 712 emitCallStubForGetters(buffer); |
| 701 emitStaticFinalFieldInitializations(buffer); | 713 emitStaticFinalFieldInitializations(buffer); |
| 702 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); | 714 buffer.add('var ${namer.CURRENT_ISOLATE} = new ${namer.ISOLATE}();\n'); |
| 703 Element main = compiler.mainApp.find(Compiler.MAIN); | 715 Element main = compiler.mainApp.find(Compiler.MAIN); |
| 704 buffer.add('${namer.isolateAccess(main)}();\n'); | 716 buffer.add('${namer.isolateAccess(main)}();\n'); |
| 705 compiler.assembledCode = buffer.toString(); | 717 compiler.assembledCode = buffer.toString(); |
| 706 }); | 718 }); |
| 707 return compiler.assembledCode; | 719 return compiler.assembledCode; |
| 708 } | 720 } |
| 709 } | 721 } |
| OLD | NEW |