Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11416257: Revert "Add @JSName annotation for native fields and methods." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 bool needsGetter, 724 bool needsGetter,
725 bool needsSetter, 725 bool needsSetter,
726 bool needsCheckedSetter)) { 726 bool needsCheckedSetter)) {
727 assert(invariant(classElement, classElement.isDeclaration)); 727 assert(invariant(classElement, classElement.isDeclaration));
728 // If the class is never instantiated we still need to set it up for 728 // If the class is never instantiated we still need to set it up for
729 // inheritance purposes, but we can simplify its JavaScript constructor. 729 // inheritance purposes, but we can simplify its JavaScript constructor.
730 bool isInstantiated = 730 bool isInstantiated =
731 compiler.codegenWorld.instantiatedClasses.contains(classElement); 731 compiler.codegenWorld.instantiatedClasses.contains(classElement);
732 732
733 void visitField(ClassElement enclosingClass, Element member) { 733 void visitField(ClassElement enclosingClass, Element member) {
734 assert(!member.isNative());
734 assert(invariant(classElement, member.isDeclaration)); 735 assert(invariant(classElement, member.isDeclaration));
735 736
736 LibraryElement library = member.getLibrary(); 737 LibraryElement library = member.getLibrary();
737 SourceString name = member.name; 738 SourceString name = member.name;
738 bool isPrivate = name.isPrivate(); 739 bool isPrivate = name.isPrivate();
739 // See if we can dynamically create getters and setters. 740 // See if we can dynamically create getters and setters.
740 // We can only generate getters and setters for [classElement] since 741 // We can only generate getters and setters for [classElement] since
741 // the fields of super classes could be overwritten with getters or 742 // the fields of super classes could be overwritten with getters or
742 // setters. 743 // setters.
743 bool needsGetter = false; 744 bool needsGetter = false;
744 bool needsSetter = false; 745 bool needsSetter = false;
745 // We need to name shadowed fields differently, so they don't clash with 746 // We need to name shadowed fields differently, so they don't clash with
746 // the non-shadowed field. 747 // the non-shadowed field.
747 bool isShadowed = false; 748 bool isShadowed = false;
748 if (identical(enclosingClass, classElement)) { 749 if (identical(enclosingClass, classElement)) {
749 needsGetter = instanceFieldNeedsGetter(member); 750 needsGetter = instanceFieldNeedsGetter(member);
750 needsSetter = instanceFieldNeedsSetter(member); 751 needsSetter = instanceFieldNeedsSetter(member);
751 } else { 752 } else {
752 isShadowed = classElement.isShadowedByField(member); 753 isShadowed = classElement.isShadowedByField(member);
753 } 754 }
754 755
755 if ((isInstantiated && !enclosingClass.isNative()) 756 if ((isInstantiated && !enclosingClass.isNative())
756 || needsGetter 757 || needsGetter
757 || needsSetter) { 758 || needsSetter) {
758 String accessorName = isShadowed 759 String fieldName = isShadowed
759 ? namer.shadowedFieldName(member) 760 ? namer.shadowedFieldName(member)
760 : namer.getName(member); 761 : namer.getName(member);
761 String fieldName = member.isNative()
762 ? member.nativeName()
763 : accessorName;
764 bool needsCheckedSetter = false; 762 bool needsCheckedSetter = false;
765 if (needsSetter && compiler.enableTypeAssertions 763 if (needsSetter && compiler.enableTypeAssertions
766 && canGenerateCheckedSetter(member)) { 764 && canGenerateCheckedSetter(member)) {
767 needsCheckedSetter = true; 765 needsCheckedSetter = true;
768 needsSetter = false; 766 needsSetter = false;
769 } 767 }
770 // Getters and setters with suffixes will be generated dynamically. 768 // Getters and setters with suffixes will be generated dynamically.
771 addField(member, 769 addField(member,
772 fieldName, 770 fieldName,
773 needsGetter, 771 needsGetter,
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 */ 1246 */
1249 void emitCallStubForGetter(Element member, 1247 void emitCallStubForGetter(Element member,
1250 Set<Selector> selectors, 1248 Set<Selector> selectors,
1251 DefineMemberFunction defineInstanceMember) { 1249 DefineMemberFunction defineInstanceMember) {
1252 assert(invariant(member, member.isDeclaration)); 1250 assert(invariant(member, member.isDeclaration));
1253 LibraryElement memberLibrary = member.getLibrary(); 1251 LibraryElement memberLibrary = member.getLibrary();
1254 String getter; 1252 String getter;
1255 if (member.isGetter()) { 1253 if (member.isGetter()) {
1256 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 1254 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()";
1257 } else { 1255 } else {
1258 String name = member.isNative() 1256 String name = namer.instanceFieldName(memberLibrary, member.name);
1259 ? member.nativeName()
1260 : namer.instanceFieldName(memberLibrary, member.name);
1261 getter = "this.$name"; 1257 getter = "this.$name";
1262 } 1258 }
1263 for (Selector selector in selectors) { 1259 for (Selector selector in selectors) {
1264 if (selector.applies(member, compiler)) { 1260 if (selector.applies(member, compiler)) {
1265 String invocationName = 1261 String invocationName =
1266 namer.instanceMethodInvocationName(memberLibrary, member.name, 1262 namer.instanceMethodInvocationName(memberLibrary, member.name,
1267 selector); 1263 selector);
1268 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; 1264 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
1269 String closureCallName = 1265 String closureCallName =
1270 namer.instanceMethodInvocationName(memberLibrary, callName, 1266 namer.instanceMethodInvocationName(memberLibrary, callName,
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 const String HOOKS_API_USAGE = """ 1775 const String HOOKS_API_USAGE = """
1780 // Generated by dart2js, the Dart to JavaScript compiler. 1776 // Generated by dart2js, the Dart to JavaScript compiler.
1781 // The code supports the following hooks: 1777 // The code supports the following hooks:
1782 // dartPrint(message) - if this function is defined it is called 1778 // dartPrint(message) - if this function is defined it is called
1783 // instead of the Dart [print] method. 1779 // instead of the Dart [print] method.
1784 // dartMainRunner(main) - if this function is defined, the Dart [main] 1780 // dartMainRunner(main) - if this function is defined, the Dart [main]
1785 // method will not be invoked directly. 1781 // method will not be invoked directly.
1786 // Instead, a closure that will invoke [main] is 1782 // Instead, a closure that will invoke [main] is
1787 // passed to [dartMainRunner]. 1783 // passed to [dartMainRunner].
1788 """; 1784 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698