Chromium Code Reviews| 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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 return js.js.statement( | 1021 return js.js.statement( |
| 1022 ''' | 1022 ''' |
| 1023 installTearOff(#container, #getterName, #isStatic, #isIntercepted, | 1023 installTearOff(#container, #getterName, #isStatic, #isIntercepted, |
| 1024 #requiredParameterCount, #optionalParameterDefaultValues, | 1024 #requiredParameterCount, #optionalParameterDefaultValues, |
| 1025 #callNames, #funsOrNames, #funType)''', | 1025 #callNames, #funsOrNames, #funType)''', |
| 1026 { | 1026 { |
| 1027 "container": container, | 1027 "container": container, |
| 1028 "getterName": js.quoteName(method.tearOffName), | 1028 "getterName": js.quoteName(method.tearOffName), |
| 1029 "isStatic": new js.LiteralBool(method.isStatic), | 1029 // 'Truthy' values are ok for `isStatic` and `isIntercepted`. |
| 1030 "isIntercepted": new js.LiteralBool(isIntercepted), | 1030 "isStatic": js.number(method.isStatic ? 1 : 0), |
| 1031 "isIntercepted": js.number(isIntercepted ? 1 : 0), | |
| 1031 "requiredParameterCount": js.number(requiredParameterCount), | 1032 "requiredParameterCount": js.number(requiredParameterCount), |
| 1032 "optionalParameterDefaultValues": optionalParameterDefaultValues, | 1033 "optionalParameterDefaultValues": optionalParameterDefaultValues, |
| 1033 "callNames": callNameArray, | 1034 "callNames": callNameArray, |
| 1034 "funsOrNames": funsOrNamesArray, | 1035 "funsOrNames": funsOrNamesArray, |
| 1035 "funType": method.functionType, | 1036 "funType": method.functionType, |
| 1036 }); | 1037 }); |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 /// Wraps the statement in a named function to that it shows up as a unit in | 1040 /// Wraps the statement in a named function to that it shows up as a unit in |
|
floitsch
2017/04/24 13:21:20
so that
| |
| 1040 /// profiles. | 1041 /// profiles. |
| 1041 // TODO(sra): Should this be conditional? | 1042 // TODO(sra): Should this be conditional? |
| 1042 js.Statement wrapPhase(String name, js.Statement statement) { | 1043 js.Statement wrapPhase(String name, js.Statement statement) { |
| 1043 return js.js.statement('(function #(){#})();', [name, statement]); | 1044 return js.js.statement('(function #(){#})();', [name, statement]); |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 /// Emits the section that installs tear-off getters. | 1047 /// Emits the section that installs tear-off getters. |
| 1047 js.Statement emitInstallTearOffs(Fragment fragment) { | 1048 js.Statement emitInstallTearOffs(Fragment fragment) { |
| 1048 List<js.Statement> inits = <js.Statement>[]; | 1049 List<js.Statement> inits = <js.Statement>[]; |
| 1050 js.Expression temp; | |
| 1049 | 1051 |
| 1050 for (Library library in fragment.libraries) { | 1052 for (Library library in fragment.libraries) { |
| 1051 for (StaticMethod method in library.statics) { | 1053 for (StaticMethod method in library.statics) { |
| 1052 // TODO(floitsch): can there be anything else than a StaticDartMethod? | 1054 // TODO(floitsch): can there be anything else than a StaticDartMethod? |
| 1053 if (method is StaticDartMethod) { | 1055 if (method is StaticDartMethod) { |
| 1054 if (method.needsTearOff) { | 1056 if (method.needsTearOff) { |
| 1055 Holder holder = method.holder; | 1057 Holder holder = method.holder; |
| 1056 inits.add( | 1058 inits.add( |
| 1057 emitInstallTearOff(new js.VariableUse(holder.name), method)); | 1059 emitInstallTearOff(new js.VariableUse(holder.name), method)); |
| 1058 } | 1060 } |
| 1059 } | 1061 } |
| 1060 } | 1062 } |
| 1061 for (Class cls in library.classes) { | 1063 for (Class cls in library.classes) { |
| 1062 for (InstanceMethod method in cls.methods) { | 1064 var methods = cls.methods.where((m) => m.needsTearOff).toList(); |
| 1063 if (method.needsTearOff) { | 1065 js.Expression container = js.js("#.prototype", classReference(cls)); |
| 1064 js.Expression container = js.js("#.prototype", classReference(cls)); | 1066 if (methods.length > 1) { |
| 1065 inits.add(emitInstallTearOff(container, method)); | 1067 if (temp == null) { |
| 1068 inits.add(js.js.statement('var _;')); | |
| 1069 temp = js.js('_'); | |
| 1066 } | 1070 } |
| 1071 container = js.js('# = #', [temp, container]); | |
| 1072 } | |
| 1073 for (InstanceMethod method in methods) { | |
| 1074 inits.add(emitInstallTearOff(container, method)); | |
| 1075 container = temp; | |
|
floitsch
2017/04/24 13:21:20
Add a comment here, and/or at "container = ...".
T
sra1
2017/04/25 00:02:19
Done.
| |
| 1067 } | 1076 } |
| 1068 } | 1077 } |
| 1069 } | 1078 } |
| 1070 return wrapPhase('installTearOffs', new js.Block(inits)); | 1079 return wrapPhase('installTearOffs', new js.Block(inits)); |
| 1071 } | 1080 } |
| 1072 | 1081 |
| 1073 /// Emits the constants section. | 1082 /// Emits the constants section. |
| 1074 js.Statement emitConstants(Fragment fragment) { | 1083 js.Statement emitConstants(Fragment fragment) { |
| 1075 List<js.Statement> assignments = <js.Statement>[]; | 1084 List<js.Statement> assignments = <js.Statement>[]; |
| 1076 for (Constant constant in fragment.constants) { | 1085 for (Constant constant in fragment.constants) { |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1434 } | 1443 } |
| 1435 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", | 1444 statements.add(js.js.statement("setOrUpdateInterceptorsByTag(#);", |
| 1436 js.objectLiteral(interceptorsByTag))); | 1445 js.objectLiteral(interceptorsByTag))); |
| 1437 statements.add( | 1446 statements.add( |
| 1438 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); | 1447 js.js.statement("setOrUpdateLeafTags(#);", js.objectLiteral(leafTags))); |
| 1439 statements.addAll(subclassAssignments); | 1448 statements.addAll(subclassAssignments); |
| 1440 | 1449 |
| 1441 return wrapPhase('nativeSupport', new js.Block(statements)); | 1450 return wrapPhase('nativeSupport', new js.Block(statements)); |
| 1442 } | 1451 } |
| 1443 } | 1452 } |
| OLD | NEW |