| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.new_js_emitter.model_emitter; | 5 library dart2js.new_js_emitter.model_emitter; |
| 6 | 6 |
| 7 import '../../constants/values.dart' show ConstantValue; | 7 import '../../constants/values.dart' show ConstantValue; |
| 8 import '../../dart2jslib.dart' show Compiler; | 8 import '../../dart2jslib.dart' show Compiler; |
| 9 import '../../dart_types.dart' show DartType; | 9 import '../../dart_types.dart' show DartType; |
| 10 import '../../elements/elements.dart' show ClassElement; | 10 import '../../elements/elements.dart' show ClassElement; |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 if (descriptor[pos] != null) { | 622 if (descriptor[pos] != null) { |
| 623 f[#argCnt] = descriptor[pos]; | 623 f[#argCnt] = descriptor[pos]; |
| 624 f[#defArgValues] = descriptor[pos + 1]; | 624 f[#defArgValues] = descriptor[pos + 1]; |
| 625 } | 625 } |
| 626 } else { | 626 } else { |
| 627 proto[name] = descriptor; | 627 proto[name] = descriptor; |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 """; | 630 """; |
| 631 | 631 |
| 632 js.Expression _generateFunctionType(DartType memberType) { | |
| 633 if (memberType.containsTypeVariables) { | |
| 634 js.Expression thisAccess = js.js(r'this.$receiver'); | |
| 635 return backend.rti.getSignatureEncoding(memberType, thisAccess); | |
| 636 } else { | |
| 637 return js.number(backend.emitter.metadataCollector.reifyType(memberType)); | |
| 638 } | |
| 639 } | |
| 640 | |
| 641 js.Expression _encodeOptionalParameterDefaultValues(DartMethod method) { | 632 js.Expression _encodeOptionalParameterDefaultValues(DartMethod method) { |
| 642 js.Expression result; | 633 js.Expression result; |
| 643 // TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole]. | 634 // TODO(herhut): Replace [js.LiteralNull] with [js.ArrayHole]. |
| 644 if (method.optionalParameterDefaultValues is List) { | 635 if (method.optionalParameterDefaultValues is List) { |
| 645 List<ConstantValue> defs = method.optionalParameterDefaultValues; | 636 List<ConstantValue> defs = method.optionalParameterDefaultValues; |
| 646 Iterable<js.Expression> elements = defs.map(constantEmitter.reference); | 637 Iterable<js.Expression> elements = defs.map(constantEmitter.reference); |
| 647 return new js.ArrayInitializer(elements.toList()); | 638 return new js.ArrayInitializer(elements.toList()); |
| 648 } else { | 639 } else { |
| 649 Map<String, ConstantValue> defs = method.optionalParameterDefaultValues; | 640 Map<String, ConstantValue> defs = method.optionalParameterDefaultValues; |
| 650 List<js.Property> properties = <js.Property>[]; | 641 List<js.Property> properties = <js.Property>[]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 679 if (method.aliasName != null) { | 670 if (method.aliasName != null) { |
| 680 data.add(js.string(method.aliasName)); | 671 data.add(js.string(method.aliasName)); |
| 681 } | 672 } |
| 682 data.add(method.code); | 673 data.add(method.code); |
| 683 data.add(js.string(method.callName)); | 674 data.add(js.string(method.callName)); |
| 684 | 675 |
| 685 if (method.needsTearOff) { | 676 if (method.needsTearOff) { |
| 686 bool isIntercepted = backend.isInterceptedMethod(method.element); | 677 bool isIntercepted = backend.isInterceptedMethod(method.element); |
| 687 data.add(new js.LiteralBool(isIntercepted)); | 678 data.add(new js.LiteralBool(isIntercepted)); |
| 688 data.add(js.string(method.tearOffName)); | 679 data.add(js.string(method.tearOffName)); |
| 689 data.add(_generateFunctionType(method.type)); | 680 data.add((method.functionType)); |
| 690 } | 681 } |
| 691 | 682 |
| 692 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); | 683 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); |
| 693 if (method.canBeApplied) { | 684 if (method.canBeApplied) { |
| 694 data.add(js.number(method.requiredParameterCount)); | 685 data.add(js.number(method.requiredParameterCount)); |
| 695 data.add(_encodeOptionalParameterDefaultValues(method)); | 686 data.add(_encodeOptionalParameterDefaultValues(method)); |
| 696 } | 687 } |
| 697 return [js.string(method.name), new js.ArrayInitializer(data)]; | 688 return [js.string(method.name), new js.ArrayInitializer(data)]; |
| 698 } else { | 689 } else { |
| 699 // TODO(floitsch): not the most efficient way... | 690 // TODO(floitsch): not the most efficient way... |
| (...skipping 28 matching lines...) Expand all Loading... |
| 728 if (method is StaticDartMethod) { | 719 if (method is StaticDartMethod) { |
| 729 if (method.needsTearOff) { | 720 if (method.needsTearOff) { |
| 730 /// The format emitted is the same as for the parser specified at | 721 /// The format emitted is the same as for the parser specified at |
| 731 /// [parseFunctionDescriptorBoilerplate] except for the missing | 722 /// [parseFunctionDescriptorBoilerplate] except for the missing |
| 732 /// field whether the method is intercepted. | 723 /// field whether the method is intercepted. |
| 733 // [name, [function, callName, tearOffName, functionType, | 724 // [name, [function, callName, tearOffName, functionType, |
| 734 // stub1_name, stub1_callName, stub1_code, ...] | 725 // stub1_name, stub1_callName, stub1_code, ...] |
| 735 var data = [unparse(compiler, method.code)]; | 726 var data = [unparse(compiler, method.code)]; |
| 736 data.add(js.string(method.callName)); | 727 data.add(js.string(method.callName)); |
| 737 data.add(js.string(method.tearOffName)); | 728 data.add(js.string(method.tearOffName)); |
| 738 data.add(_generateFunctionType(method.type)); | 729 data.add(method.functionType); |
| 739 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); | 730 data.addAll(method.parameterStubs.expand(makeNameCallNameCodeTriplet)); |
| 740 if (method.canBeApplied) { | 731 if (method.canBeApplied) { |
| 741 data.add(js.number(method.requiredParameterCount)); | 732 data.add(js.number(method.requiredParameterCount)); |
| 742 data.add(_encodeOptionalParameterDefaultValues(method)); | 733 data.add(_encodeOptionalParameterDefaultValues(method)); |
| 743 } | 734 } |
| 744 return [js.string(method.name), holderIndex, | 735 return [js.string(method.name), holderIndex, |
| 745 new js.ArrayInitializer(data)]; | 736 new js.ArrayInitializer(data)]; |
| 746 } else { | 737 } else { |
| 747 method.parameterStubs.forEach(_addMethod); | 738 method.parameterStubs.forEach(_addMethod); |
| 748 } | 739 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 | 1015 |
| 1025 var end = Date.now(); | 1016 var end = Date.now(); |
| 1026 // print('Setup: ' + (end - start) + ' ms.'); | 1017 // print('Setup: ' + (end - start) + ' ms.'); |
| 1027 | 1018 |
| 1028 #invokeMain; // Start main. | 1019 #invokeMain; // Start main. |
| 1029 | 1020 |
| 1030 }(Date.now(), #code) | 1021 }(Date.now(), #code) |
| 1031 }"""; | 1022 }"""; |
| 1032 | 1023 |
| 1033 } | 1024 } |
| OLD | NEW |