OLD | NEW |
---|---|
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 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1584 String receiver = backend.isInterceptorClass(member.getEnclosingClass()) | 1584 String receiver = backend.isInterceptorClass(member.getEnclosingClass()) |
1585 ? 'receiver' : 'this'; | 1585 ? 'receiver' : 'this'; |
1586 List<String> args = backend.isInterceptedMethod(member) | 1586 List<String> args = backend.isInterceptedMethod(member) |
1587 ? ['receiver', 'v'] | 1587 ? ['receiver', 'v'] |
1588 : ['v']; | 1588 : ['v']; |
1589 builder.addProperty(setterName, | 1589 builder.addProperty(setterName, |
1590 js.fun(args, js('$receiver.$fieldName = v'))); | 1590 js.fun(args, js('$receiver.$fieldName = v'))); |
1591 } | 1591 } |
1592 | 1592 |
1593 bool canGenerateCheckedSetter(Element member) { | 1593 bool canGenerateCheckedSetter(Element member) { |
1594 // We never generate accessors for top-level/static fields. | |
1595 if (!member.isInstanceMember()) return false; | |
1594 DartType type = member.computeType(compiler).unalias(compiler); | 1596 DartType type = member.computeType(compiler).unalias(compiler); |
1595 if (type.element.isTypeVariable() || | 1597 if (type.element.isTypeVariable() || |
1596 (type is FunctionType && type.containsTypeVariables) || | 1598 (type is FunctionType && type.containsTypeVariables) || |
1597 type.element == compiler.dynamicClass || | 1599 type.element == compiler.dynamicClass || |
1598 type.element == compiler.objectClass) { | 1600 type.element == compiler.objectClass) { |
1599 // TODO(ngeoffray): Support type checks on type parameters. | 1601 // TODO(ngeoffray): Support type checks on type parameters. |
1600 return false; | 1602 return false; |
1601 } | 1603 } |
1602 return true; | 1604 return true; |
1603 } | 1605 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1725 int getterCode = 0; | 1727 int getterCode = 0; |
1726 if (needsGetter) { | 1728 if (needsGetter) { |
1727 // 01: function() { return this.field; } | 1729 // 01: function() { return this.field; } |
1728 // 10: function(receiver) { return receiver.field; } | 1730 // 10: function(receiver) { return receiver.field; } |
1729 // 11: function(receiver) { return this.field; } | 1731 // 11: function(receiver) { return this.field; } |
1730 getterCode += backend.fieldHasInterceptedGetter(member) ? 2 : 0; | 1732 getterCode += backend.fieldHasInterceptedGetter(member) ? 2 : 0; |
1731 getterCode += backend.isInterceptorClass(classElement) ? 0 : 1; | 1733 getterCode += backend.isInterceptorClass(classElement) ? 0 : 1; |
1732 // TODO(sra): 'isInterceptorClass' might not be the correct test for | 1734 // TODO(sra): 'isInterceptorClass' might not be the correct test for |
1733 // methods forced to use the interceptor convention because the | 1735 // methods forced to use the interceptor convention because the |
1734 // method's class was elsewhere mixed-in to an interceptor. | 1736 // method's class was elsewhere mixed-in to an interceptor. |
1735 assert(getterCode != 0); | 1737 assert(!member.isInstanceMember() || getterCode != 0); |
sra1
2013/07/18 20:33:49
I'm trying to understand a bug in this area. (issu
| |
1736 } | 1738 } |
1737 int setterCode = 0; | 1739 int setterCode = 0; |
1738 if (needsSetter) { | 1740 if (needsSetter) { |
1739 // 01: function(value) { this.field = value; } | 1741 // 01: function(value) { this.field = value; } |
1740 // 10: function(receiver, value) { receiver.field = value; } | 1742 // 10: function(receiver, value) { receiver.field = value; } |
1741 // 11: function(receiver, value) { this.field = value; } | 1743 // 11: function(receiver, value) { this.field = value; } |
1742 setterCode += backend.fieldHasInterceptedSetter(member) ? 2 : 0; | 1744 setterCode += backend.fieldHasInterceptedSetter(member) ? 2 : 0; |
1743 setterCode += backend.isInterceptorClass(classElement) ? 0 : 1; | 1745 setterCode += backend.isInterceptorClass(classElement) ? 0 : 1; |
1744 assert(setterCode != 0); | 1746 assert(!member.isInstanceMember() || setterCode != 0); |
1745 } | 1747 } |
1746 int code = getterCode + (setterCode << 2); | 1748 int code = getterCode + (setterCode << 2); |
1747 if (code == 0) { | 1749 if (code == 0) { |
1748 compiler.reportInternalError( | 1750 compiler.reportInternalError( |
1749 member, 'Internal error: code is 0 ($classElement/$member)'); | 1751 member, 'Internal error: code is 0 ($classElement/$member)'); |
1750 } else { | 1752 } else { |
1751 buffer.write(FIELD_CODE_CHARACTERS[code - FIRST_FIELD_CODE]); | 1753 buffer.write(FIELD_CODE_CHARACTERS[code - FIRST_FIELD_CODE]); |
1752 } | 1754 } |
1753 } | 1755 } |
1754 } | 1756 } |
(...skipping 2130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3885 | 3887 |
3886 const String HOOKS_API_USAGE = """ | 3888 const String HOOKS_API_USAGE = """ |
3887 // The code supports the following hooks: | 3889 // The code supports the following hooks: |
3888 // dartPrint(message) - if this function is defined it is called | 3890 // dartPrint(message) - if this function is defined it is called |
3889 // instead of the Dart [print] method. | 3891 // instead of the Dart [print] method. |
3890 // dartMainRunner(main) - if this function is defined, the Dart [main] | 3892 // dartMainRunner(main) - if this function is defined, the Dart [main] |
3891 // method will not be invoked directly. | 3893 // method will not be invoked directly. |
3892 // Instead, a closure that will invoke [main] is | 3894 // Instead, a closure that will invoke [main] is |
3893 // passed to [dartMainRunner]. | 3895 // passed to [dartMainRunner]. |
3894 """; | 3896 """; |
OLD | NEW |