| 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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 /// | 645 /// |
| 646 /// The constructor is statically built. | 646 /// The constructor is statically built. |
| 647 js.Expression emitConstructor(Class cls) { | 647 js.Expression emitConstructor(Class cls) { |
| 648 js.Name name = cls.name; | 648 js.Name name = cls.name; |
| 649 // If the class is not directly instantiated we only need it for inheritance | 649 // If the class is not directly instantiated we only need it for inheritance |
| 650 // or RTI. In either case we don't need its fields. | 650 // or RTI. In either case we don't need its fields. |
| 651 if (cls.isNative || !cls.isDirectlyInstantiated) { | 651 if (cls.isNative || !cls.isDirectlyInstantiated) { |
| 652 return js.js('function #() { }', name); | 652 return js.js('function #() { }', name); |
| 653 } | 653 } |
| 654 | 654 |
| 655 List<js.Name> fieldNames = | 655 var statements = <js.Statement>[]; |
| 656 cls.fields.map((Field field) => field.name).toList(); | 656 var parameters = <js.Name>[]; |
| 657 if (cls.hasRtiField) { | 657 var thisRef; |
| 658 fieldNames.add(namer.rtiFieldJsName); | 658 |
| 659 // If there are many references to `this`, cache it in a local. |
| 660 if (cls.fields.length + (cls.hasRtiField ? 1 : 0) >= 4) { |
| 661 statements.add(js.js.statement('var _ = this;')); |
| 662 thisRef = js.js('_'); |
| 663 } else { |
| 664 thisRef = js.js('this'); |
| 659 } | 665 } |
| 660 | 666 |
| 661 Iterable<js.Name> assignments = fieldNames.map((js.Name field) { | 667 for (Field field in cls.fields) { |
| 662 return js.js("this.#field = #field", {"field": field}); | 668 js.Name paramName = field.name; |
| 663 }); | 669 parameters.add(paramName); |
| 670 statements |
| 671 .add(js.js.statement('#.# = #', [thisRef, field.name, paramName])); |
| 672 } |
| 664 | 673 |
| 665 // TODO(sra): Cache 'this' in a one-character local for 4 or more uses of | 674 if (cls.hasRtiField) { |
| 666 // 'this'. i.e. "var _=this;_.a=a;_.b=b;..." | 675 js.Name paramName = namer.rtiFieldJsName; |
| 676 parameters.add(paramName); |
| 677 statements.add(js.js |
| 678 .statement('#.# = #', [thisRef, namer.rtiFieldJsName, paramName])); |
| 679 } |
| 667 | 680 |
| 668 // TODO(sra): Separate field and field initializer parameter names so the | 681 return js.js('function #(#) { # }', [name, parameters, statements]); |
| 669 // latter may be fully minified. | |
| 670 | |
| 671 return js.js('function #(#) { # }', [name, fieldNames, assignments]); | |
| 672 } | 682 } |
| 673 | 683 |
| 674 /// Emits the prototype-section of the fragment. | 684 /// Emits the prototype-section of the fragment. |
| 675 /// | 685 /// |
| 676 /// This section updates the prototype-property of all constructors in the | 686 /// This section updates the prototype-property of all constructors in the |
| 677 /// global holders. | 687 /// global holders. |
| 678 js.Statement emitPrototypes(Fragment fragment) { | 688 js.Statement emitPrototypes(Fragment fragment) { |
| 679 List<js.Statement> assignments = fragment.libraries | 689 List<js.Statement> assignments = fragment.libraries |
| 680 .expand((Library library) => library.classes) | 690 .expand((Library library) => library.classes) |
| 681 .map((Class cls) { | 691 .map((Class cls) { |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 } | 1443 } |
| 1434 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1444 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
| 1435 js.objectLiteral(interceptorsByTag))); | 1445 js.objectLiteral(interceptorsByTag))); |
| 1436 statements.add( | 1446 statements.add( |
| 1437 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1447 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
| 1438 statements.addAll(subclassAssignments); | 1448 statements.addAll(subclassAssignments); |
| 1439 | 1449 |
| 1440 return wrapPhase('nativeSupport', new js.Block(statements)); | 1450 return wrapPhase('nativeSupport', new js.Block(statements)); |
| 1441 } | 1451 } |
| 1442 } | 1452 } |
| OLD | NEW |