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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 checkedSetters, | 709 checkedSetters, |
710 isChecks, | 710 isChecks, |
711 callStubs, | 711 callStubs, |
712 noSuchMethodStubs, | 712 noSuchMethodStubs, |
713 gettersSetters | 713 gettersSetters |
714 ].expand((x) => x); | 714 ].expand((x) => x); |
715 | 715 |
716 List<js.Property> properties = <js.Property>[]; | 716 List<js.Property> properties = <js.Property>[]; |
717 | 717 |
718 if (cls.superclass == null) { | 718 if (cls.superclass == null) { |
| 719 // TODO(sra): What is this doing? Document or remove. |
719 properties | 720 properties |
720 .add(new js.Property(js.string("constructor"), classReference(cls))); | 721 .add(new js.Property(js.string("constructor"), classReference(cls))); |
721 properties | 722 properties |
722 .add(new js.Property(namer.operatorIs(cls.element), js.number(1))); | 723 .add(new js.Property(namer.operatorIs(cls.element), js.number(1))); |
723 } | 724 } |
724 | 725 |
725 allMethods.forEach((Method method) { | 726 allMethods.forEach((Method method) { |
726 emitInstanceMethod(method) | 727 emitInstanceMethod(method) |
727 .forEach((js.Expression name, js.Expression code) { | 728 .forEach((js.Expression name, js.Expression code) { |
728 var prop = new js.Property(name, code); | 729 var prop = new js.Property(name, code); |
729 compiler.dumpInfoTask.registerElementAst(method.element, prop); | 730 compiler.dumpInfoTask.registerElementAst(method.element, prop); |
730 properties.add(prop); | 731 properties.add(prop); |
731 }); | 732 }); |
732 }); | 733 }); |
733 | 734 |
| 735 if (cls.isClosureBaseClass) { |
| 736 // Closures extend a common base class, so we can put properties on the |
| 737 // prototype for common values. |
| 738 |
| 739 // Most closures have no optional arguments. |
| 740 properties.add(new js.Property( |
| 741 js.string(namer.defaultValuesField), new js.LiteralNull())); |
| 742 } |
| 743 |
734 return new js.ObjectInitializer(properties); | 744 return new js.ObjectInitializer(properties); |
735 } | 745 } |
736 | 746 |
737 /// Generates a getter for the given [field]. | 747 /// Generates a getter for the given [field]. |
738 Method generateGetter(Field field) { | 748 Method generateGetter(Field field) { |
739 assert(field.needsGetter); | 749 assert(field.needsGetter); |
740 | 750 |
741 String template; | 751 String template; |
742 if (field.needsInterceptedGetterOnReceiver) { | 752 if (field.needsInterceptedGetterOnReceiver) { |
743 template = "function(receiver) { return receiver[#]; }"; | 753 template = "function(receiver) { return receiver[#]; }"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 Map<js.Expression, js.Expression> emitInstanceMethod(Method method) { | 808 Map<js.Expression, js.Expression> emitInstanceMethod(Method method) { |
799 var properties = <js.Expression, js.Expression>{}; | 809 var properties = <js.Expression, js.Expression>{}; |
800 | 810 |
801 properties[method.name] = method.code; | 811 properties[method.name] = method.code; |
802 if (method is InstanceMethod) { | 812 if (method is InstanceMethod) { |
803 for (ParameterStubMethod stubMethod in method.parameterStubs) { | 813 for (ParameterStubMethod stubMethod in method.parameterStubs) { |
804 properties[stubMethod.name] = stubMethod.code; | 814 properties[stubMethod.name] = stubMethod.code; |
805 } | 815 } |
806 | 816 |
807 if (method.isClosureCallMethod && method.canBeApplied) { | 817 if (method.isClosureCallMethod && method.canBeApplied) { |
| 818 // TODO(sra): We should also add these properties for the user-defined |
| 819 // `call` method on classes. Function.apply is currently broken for |
| 820 // complex cases. [forceAdd] might be true when this is fixed. |
| 821 bool forceAdd = !method.isClosureCallMethod; |
| 822 |
808 properties[js.string(namer.callCatchAllName)] = | 823 properties[js.string(namer.callCatchAllName)] = |
809 js.quoteName(method.name); | 824 js.quoteName(method.name); |
810 properties[js.string(namer.requiredParameterField)] = | 825 properties[js.string(namer.requiredParameterField)] = |
811 js.number(method.requiredParameterCount); | 826 js.number(method.requiredParameterCount); |
812 properties[js.string(namer.defaultValuesField)] = | 827 |
| 828 js.Expression defaultValues = |
813 _encodeOptionalParameterDefaultValues(method); | 829 _encodeOptionalParameterDefaultValues(method); |
| 830 // Default values property of `null` is stored on the common JS |
| 831 // superclass. |
| 832 if (defaultValues is! js.LiteralNull || forceAdd) { |
| 833 properties[js.string(namer.defaultValuesField)] = defaultValues; |
| 834 } |
814 } | 835 } |
815 } | 836 } |
816 | 837 |
817 return properties; | 838 return properties; |
818 } | 839 } |
819 | 840 |
820 /// Emits the inheritance block of the fragment. | 841 /// Emits the inheritance block of the fragment. |
821 /// | 842 /// |
822 /// In this section prototype chains are updated and mixin functions are | 843 /// In this section prototype chains are updated and mixin functions are |
823 /// copied. | 844 /// copied. |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 } | 1413 } |
1393 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1414 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
1394 js.objectLiteral(interceptorsByTag))); | 1415 js.objectLiteral(interceptorsByTag))); |
1395 statements.add( | 1416 statements.add( |
1396 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1417 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
1397 statements.addAll(subclassAssignments); | 1418 statements.addAll(subclassAssignments); |
1398 | 1419 |
1399 return wrapPhase('nativeSupport', new js.Block(statements)); | 1420 return wrapPhase('nativeSupport', new js.Block(statements)); |
1400 } | 1421 } |
1401 } | 1422 } |
OLD | NEW |