Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart |
| index e12847056c39984e0b7a9e3aaff588d105e8d99a..1eaf72ad6ad0fb25bb6f34184dfee532d39e2634 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart |
| @@ -1026,8 +1026,9 @@ class FragmentEmitter { |
| { |
| "container": container, |
| "getterName": js.quoteName(method.tearOffName), |
| - "isStatic": new js.LiteralBool(method.isStatic), |
| - "isIntercepted": new js.LiteralBool(isIntercepted), |
| + // 'Truthy' values are ok for `isStatic` and `isIntercepted`. |
| + "isStatic": js.number(method.isStatic ? 1 : 0), |
| + "isIntercepted": js.number(isIntercepted ? 1 : 0), |
| "requiredParameterCount": js.number(requiredParameterCount), |
| "optionalParameterDefaultValues": optionalParameterDefaultValues, |
| "callNames": callNameArray, |
| @@ -1046,6 +1047,7 @@ class FragmentEmitter { |
| /// Emits the section that installs tear-off getters. |
| js.Statement emitInstallTearOffs(Fragment fragment) { |
| List<js.Statement> inits = <js.Statement>[]; |
| + js.Expression temp; |
| for (Library library in fragment.libraries) { |
| for (StaticMethod method in library.statics) { |
| @@ -1059,11 +1061,18 @@ class FragmentEmitter { |
| } |
| } |
| for (Class cls in library.classes) { |
| - for (InstanceMethod method in cls.methods) { |
| - if (method.needsTearOff) { |
| - js.Expression container = js.js("#.prototype", classReference(cls)); |
| - inits.add(emitInstallTearOff(container, method)); |
| + var methods = cls.methods.where((m) => m.needsTearOff).toList(); |
| + js.Expression container = js.js("#.prototype", classReference(cls)); |
| + if (methods.length > 1) { |
| + if (temp == null) { |
| + inits.add(js.js.statement('var _;')); |
| + temp = js.js('_'); |
| } |
| + container = js.js('# = #', [temp, container]); |
| + } |
| + for (InstanceMethod method in methods) { |
| + inits.add(emitInstallTearOff(container, method)); |
| + 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.
|
| } |
| } |
| } |