| 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_incremental.library_updater; | 5 library dart2js_incremental.library_updater; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 if (info == null) { | 643 if (info == null) { |
| 644 compiler.internalError(element, '${element.runtimeType}'); | 644 compiler.internalError(element, '${element.runtimeType}'); |
| 645 } | 645 } |
| 646 String name = info.name; | 646 String name = info.name; |
| 647 jsAst.Node function = info.code; | 647 jsAst.Node function = info.code; |
| 648 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 648 List<jsAst.Statement> statements = <jsAst.Statement>[]; |
| 649 if (element.isInstanceMember) { | 649 if (element.isInstanceMember) { |
| 650 jsAst.Node elementAccess = namer.elementAccess(element.enclosingClass); | 650 jsAst.Node elementAccess = namer.elementAccess(element.enclosingClass); |
| 651 statements.add( | 651 statements.add( |
| 652 js.statement('#.prototype.# = f', [elementAccess, name])); | 652 js.statement('#.prototype.# = f', [elementAccess, name])); |
| 653 | |
| 654 if (backend.isAliasedSuperMember(element)) { | |
| 655 String superName = namer.getNameOfAliasedSuperMember(element); | |
| 656 statements.add( | |
| 657 js.statement('#.prototype.# = f', [elementAccess, superName])); | |
| 658 } | |
| 659 } else { | 653 } else { |
| 660 jsAst.Node elementAccess = namer.elementAccess(element); | 654 jsAst.Node elementAccess = namer.elementAccess(element); |
| 661 jsAst.Expression globalFunctionsAccess = | 655 jsAst.Expression globalFunctionsAccess = |
| 662 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); | 656 emitter.generateEmbeddedGlobalAccess(embeddedNames.GLOBAL_FUNCTIONS); |
| 663 statements.add( | 657 statements.add( |
| 664 js.statement( | 658 js.statement( |
| 665 '#.# = # = f', | 659 '#.# = # = f', |
| 666 [globalFunctionsAccess, name, elementAccess])); | 660 [globalFunctionsAccess, name, elementAccess])); |
| 667 if (info.canTearOff) { | 661 if (info.canTearOff) { |
| 668 String globalName = namer.globalObjectFor(element); | 662 String globalName = namer.globalObjectFor(element); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 } | 783 } |
| 790 | 784 |
| 791 class RemovedFunctionUpdate extends RemovalUpdate | 785 class RemovedFunctionUpdate extends RemovalUpdate |
| 792 with JsFeatures, ReuseFunction { | 786 with JsFeatures, ReuseFunction { |
| 793 final PartialFunctionElement element; | 787 final PartialFunctionElement element; |
| 794 | 788 |
| 795 /// Name of property to remove using JavaScript "delete". Null for | 789 /// Name of property to remove using JavaScript "delete". Null for |
| 796 /// non-instance methods. | 790 /// non-instance methods. |
| 797 String name; | 791 String name; |
| 798 | 792 |
| 799 /// Name of super-alias property to remove using JavaScript "delete". Null | |
| 800 /// for methods that aren't "super aliased", and non-instance methods. | |
| 801 String superName; | |
| 802 | |
| 803 /// For instance methods, access to class object. Otherwise, access to the | 793 /// For instance methods, access to class object. Otherwise, access to the |
| 804 /// method itself. | 794 /// method itself. |
| 805 jsAst.Node elementAccess; | 795 jsAst.Node elementAccess; |
| 806 | 796 |
| 807 bool wasStateCaptured = false; | 797 bool wasStateCaptured = false; |
| 808 | 798 |
| 809 RemovedFunctionUpdate(Compiler compiler, this.element) | 799 RemovedFunctionUpdate(Compiler compiler, this.element) |
| 810 : super(compiler); | 800 : super(compiler); |
| 811 | 801 |
| 812 PartialFunctionElement get before => element; | 802 PartialFunctionElement get before => element; |
| 813 | 803 |
| 814 PartialFunctionElement get after => null; | 804 PartialFunctionElement get after => null; |
| 815 | 805 |
| 816 void captureState() { | 806 void captureState() { |
| 817 if (wasStateCaptured) throw "captureState was called twice."; | 807 if (wasStateCaptured) throw "captureState was called twice."; |
| 818 wasStateCaptured = true; | 808 wasStateCaptured = true; |
| 819 | 809 |
| 820 if (element.isInstanceMember) { | 810 if (element.isInstanceMember) { |
| 821 elementAccess = namer.elementAccess(element.enclosingClass); | 811 elementAccess = namer.elementAccess(element.enclosingClass); |
| 822 name = namer.getNameOfMember(element); | 812 name = namer.getNameOfMember(element); |
| 823 if (backend.isAliasedSuperMember(element)) { | |
| 824 superName = namer.getNameOfAliasedSuperMember(element); | |
| 825 } | |
| 826 } else { | 813 } else { |
| 827 elementAccess = namer.elementAccess(element); | 814 elementAccess = namer.elementAccess(element); |
| 828 } | 815 } |
| 829 } | 816 } |
| 830 | 817 |
| 831 PartialFunctionElement apply() { | 818 PartialFunctionElement apply() { |
| 832 if (!wasStateCaptured) throw "captureState must be called before apply."; | 819 if (!wasStateCaptured) throw "captureState must be called before apply."; |
| 833 removeFromEnclosing(); | 820 removeFromEnclosing(); |
| 834 reuseElement(); | 821 reuseElement(); |
| 835 return null; | 822 return null; |
| 836 } | 823 } |
| 837 | 824 |
| 838 void writeUpdateJsOn(List<jsAst.Statement> updates) { | 825 void writeUpdateJsOn(List<jsAst.Statement> updates) { |
| 839 if (elementAccess == null) { | 826 if (elementAccess == null) { |
| 840 compiler.internalError( | 827 compiler.internalError( |
| 841 element, 'No elementAccess for ${element.runtimeType}'); | 828 element, 'No elementAccess for ${element.runtimeType}'); |
| 842 } | 829 } |
| 843 if (element.isInstanceMember) { | 830 if (element.isInstanceMember) { |
| 844 if (name == null) { | 831 if (name == null) { |
| 845 compiler.internalError(element, 'No name for ${element.runtimeType}'); | 832 compiler.internalError(element, 'No name for ${element.runtimeType}'); |
| 846 } | 833 } |
| 847 updates.add( | 834 updates.add( |
| 848 js.statement('delete #.prototype.#', [elementAccess, name])); | 835 js.statement('delete #.prototype.#', [elementAccess, name])); |
| 849 | |
| 850 if (superName != null) { | |
| 851 updates.add( | |
| 852 js.statement('delete #.prototype.#', [elementAccess, superName])); | |
| 853 } | |
| 854 } else { | 836 } else { |
| 855 updates.add(js.statement('delete #', [elementAccess])); | 837 updates.add(js.statement('delete #', [elementAccess])); |
| 856 } | 838 } |
| 857 } | 839 } |
| 858 } | 840 } |
| 859 | 841 |
| 860 class RemovedClassUpdate extends RemovalUpdate with JsFeatures { | 842 class RemovedClassUpdate extends RemovalUpdate with JsFeatures { |
| 861 final PartialClassElement element; | 843 final PartialClassElement element; |
| 862 | 844 |
| 863 bool wasStateCaptured = false; | 845 bool wasStateCaptured = false; |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 List<String> computeFields(ClassElement cls) { | 1145 List<String> computeFields(ClassElement cls) { |
| 1164 // TODO(ahe): Rewrite for new emitter. | 1146 // TODO(ahe): Rewrite for new emitter. |
| 1165 ClassBuilder builder = new ClassBuilder(cls, namer); | 1147 ClassBuilder builder = new ClassBuilder(cls, namer); |
| 1166 classEmitter.emitFields(cls, builder, ""); | 1148 classEmitter.emitFields(cls, builder, ""); |
| 1167 return builder.fields; | 1149 return builder.fields; |
| 1168 } | 1150 } |
| 1169 } | 1151 } |
| 1170 | 1152 |
| 1171 // TODO(ahe): Remove this method. | 1153 // TODO(ahe): Remove this method. |
| 1172 NO_WARN(x) => x; | 1154 NO_WARN(x) => x; |
| OLD | NEW |