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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 for (ParameterStubMethod stubMethod in method.parameterStubs) { | 693 for (ParameterStubMethod stubMethod in method.parameterStubs) { |
694 properties[stubMethod.name] = stubMethod.code; | 694 properties[stubMethod.name] = stubMethod.code; |
695 } | 695 } |
696 | 696 |
697 if (method.isClosureCallMethod && method.canBeApplied) { | 697 if (method.isClosureCallMethod && method.canBeApplied) { |
698 properties[js.string(namer.callCatchAllName)] = | 698 properties[js.string(namer.callCatchAllName)] = |
699 js.quoteName(method.name); | 699 js.quoteName(method.name); |
700 properties[js.string(namer.requiredParameterField)] = | 700 properties[js.string(namer.requiredParameterField)] = |
701 js.number(method.requiredParameterCount); | 701 js.number(method.requiredParameterCount); |
702 properties[js.string(namer.defaultValuesField)] = | 702 properties[js.string(namer.defaultValuesField)] = |
703 js.js('function() { return #; }', | 703 _encodeOptionalParameterDefaultValues(method); |
704 _encodeOptionalParameterDefaultValues(method)); | |
705 } | 704 } |
706 } | 705 } |
707 | 706 |
708 return properties; | 707 return properties; |
709 } | 708 } |
710 | 709 |
711 /// Emits the inheritance block of the fragment. | 710 /// Emits the inheritance block of the fragment. |
712 /// | 711 /// |
713 /// In this section prototype chains are updated and mixin functions are | 712 /// In this section prototype chains are updated and mixin functions are |
714 /// copied. | 713 /// copied. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 762 } |
764 | 763 |
765 /// Encodes the optional default values so that the runtime Function.apply | 764 /// Encodes the optional default values so that the runtime Function.apply |
766 /// can use them. | 765 /// can use them. |
767 js.Expression _encodeOptionalParameterDefaultValues(DartMethod method) { | 766 js.Expression _encodeOptionalParameterDefaultValues(DartMethod method) { |
768 // TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole]. | 767 // TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole]. |
769 if (method.optionalParameterDefaultValues is List) { | 768 if (method.optionalParameterDefaultValues is List) { |
770 List<ConstantValue> defaultValues = method.optionalParameterDefaultValues; | 769 List<ConstantValue> defaultValues = method.optionalParameterDefaultValues; |
771 Iterable<js.Expression> elements = | 770 Iterable<js.Expression> elements = |
772 defaultValues.map(generateConstantReference); | 771 defaultValues.map(generateConstantReference); |
773 return new js.ArrayInitializer(elements.toList()); | 772 return js.js('function() { return #; }', |
| 773 new js.ArrayInitializer(elements.toList())); |
774 } else { | 774 } else { |
775 Map<String, ConstantValue> defaultValues = | 775 Map<String, ConstantValue> defaultValues = |
776 method.optionalParameterDefaultValues; | 776 method.optionalParameterDefaultValues; |
777 List<js.Property> properties = <js.Property>[]; | 777 List<js.Property> properties = <js.Property>[]; |
778 List<String> names = defaultValues.keys.toList(growable: false); | 778 List<String> names = defaultValues.keys.toList(growable: false); |
779 // Sort the names the same way we sort them for the named-argument calling | 779 // Sort the names the same way we sort them for the named-argument calling |
780 // convention. | 780 // convention. |
781 names.sort(); | 781 names.sort(); |
782 | 782 |
783 for (String name in names) { | 783 for (String name in names) { |
784 ConstantValue value = defaultValues[name]; | 784 ConstantValue value = defaultValues[name]; |
785 properties.add(new js.Property(js.string(name), | 785 properties.add(new js.Property(js.string(name), |
786 generateConstantReference(value))); | 786 generateConstantReference(value))); |
787 } | 787 } |
788 return new js.ObjectInitializer(properties); | 788 return js.js('function() { return #; }', |
| 789 new js.ObjectInitializer(properties)); |
789 } | 790 } |
790 } | 791 } |
791 | 792 |
792 /// Emits the statement that installs a tear off for a method. | 793 /// Emits the statement that installs a tear off for a method. |
793 /// | 794 /// |
794 /// Tear-offs might be passed to `Function.apply` which means that all | 795 /// Tear-offs might be passed to `Function.apply` which means that all |
795 /// calling-conventions (with or without optional positional/named arguments) | 796 /// calling-conventions (with or without optional positional/named arguments) |
796 /// are possible. As such, the tear-off needs enough information to fill in | 797 /// are possible. As such, the tear-off needs enough information to fill in |
797 /// missing parameters. | 798 /// missing parameters. |
798 js.Statement emitInstallTearOff(js.Expression container, DartMethod method) { | 799 js.Statement emitInstallTearOff(js.Expression container, DartMethod method) { |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 } | 1235 } |
1235 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1236 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
1236 js.objectLiteral(interceptorsByTag))); | 1237 js.objectLiteral(interceptorsByTag))); |
1237 statements.add(js.js.statement("setOrUpdateLeafTags(#);", | 1238 statements.add(js.js.statement("setOrUpdateLeafTags(#);", |
1238 js.objectLiteral(leafTags))); | 1239 js.objectLiteral(leafTags))); |
1239 statements.add(subclassAssignment); | 1240 statements.add(subclassAssignment); |
1240 | 1241 |
1241 return new js.Block(statements); | 1242 return new js.Block(statements); |
1242 } | 1243 } |
1243 } | 1244 } |
OLD | NEW |