OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.js_emitter.startup_emitter.model_emitter; | 5 part of dart2js.js_emitter.startup_emitter.model_emitter; |
6 | 6 |
7 /// The name of the property that stores the tear-off getter on a static | 7 /// The name of the property that stores the tear-off getter on a static |
8 /// function. | 8 /// function. |
9 /// | 9 /// |
10 /// This property is only used when isolates are used. | 10 /// This property is only used when isolates are used. |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 }); | 622 }); |
623 jsMethods[method.name] = method.code; | 623 jsMethods[method.name] = method.code; |
624 | 624 |
625 return jsMethods; | 625 return jsMethods; |
626 } | 626 } |
627 | 627 |
628 /// Emits a constructor for the given class [cls]. | 628 /// Emits a constructor for the given class [cls]. |
629 /// | 629 /// |
630 /// The constructor is statically built. | 630 /// The constructor is statically built. |
631 js.Expression emitConstructor(Class cls) { | 631 js.Expression emitConstructor(Class cls) { |
632 List<js.Name> fieldNames = const <js.Name>[]; | 632 js.Name name = cls.name; |
633 | |
634 // If the class is not directly instantiated we only need it for inheritance | 633 // If the class is not directly instantiated we only need it for inheritance |
635 // or RTI. In either case we don't need its fields. | 634 // or RTI. In either case we don't need its fields. |
636 if (cls.isDirectlyInstantiated && !cls.isNative) { | 635 if (cls.isNative || !cls.isDirectlyInstantiated) { |
637 fieldNames = cls.fields.map((Field field) => field.name).toList(); | 636 return js.js('function #() { }', name); |
638 } | 637 } |
639 js.Name name = cls.name; | 638 |
| 639 List<js.Name> fieldNames = |
| 640 cls.fields.map((Field field) => field.name).toList(); |
| 641 if (cls.hasRtiField) { |
| 642 fieldNames.add(namer.rtiFieldName); |
| 643 } |
640 | 644 |
641 Iterable<js.Name> assignments = fieldNames.map((js.Name field) { | 645 Iterable<js.Name> assignments = fieldNames.map((js.Name field) { |
642 return js.js("this.#field = #field", {"field": field}); | 646 return js.js("this.#field = #field", {"field": field}); |
643 }); | 647 }); |
644 | 648 |
| 649 // TODO(sra): Cache 'this' in a one-character local for 4 or more uses of |
| 650 // 'this'. i.e. "var _=this;_.a=a;_.b=b;..." |
| 651 |
| 652 // TODO(sra): Separate field and field initializer parameter names so the |
| 653 // latter may be fully minified. |
| 654 |
645 return js.js('function #(#) { # }', [name, fieldNames, assignments]); | 655 return js.js('function #(#) { # }', [name, fieldNames, assignments]); |
646 } | 656 } |
647 | 657 |
648 /// Emits the prototype-section of the fragment. | 658 /// Emits the prototype-section of the fragment. |
649 /// | 659 /// |
650 /// This section updates the prototype-property of all constructors in the | 660 /// This section updates the prototype-property of all constructors in the |
651 /// global holders. | 661 /// global holders. |
652 js.Statement emitPrototypes(Fragment fragment) { | 662 js.Statement emitPrototypes(Fragment fragment) { |
653 List<js.Statement> assignments = fragment.libraries | 663 List<js.Statement> assignments = fragment.libraries |
654 .expand((Library library) => library.classes) | 664 .expand((Library library) => library.classes) |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 } | 1359 } |
1350 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1360 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
1351 js.objectLiteral(interceptorsByTag))); | 1361 js.objectLiteral(interceptorsByTag))); |
1352 statements.add( | 1362 statements.add( |
1353 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1363 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
1354 statements.add(subclassAssignment); | 1364 statements.add(subclassAssignment); |
1355 | 1365 |
1356 return new js.Block(statements); | 1366 return new js.Block(statements); |
1357 } | 1367 } |
1358 } | 1368 } |
OLD | NEW |