| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 import "dart:_js_helper"; | 5 import "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // Verify that we can have fields with names that start with g and s even | 8 // Verify that we can have fields with names that start with g and s even |
| 9 // though those names are reserved for getters and setters in minified mode. | 9 // though those names are reserved for getters and setters in minified mode. |
| 10 | 10 |
| 11 // Note: this works because end and send are both in the list of | 11 // Note: this works because end and send are both in the list of |
| 12 // reservedNativeProperties. In general we don't check arbitrary | 12 // reservedNativeProperties. In general we don't check arbitrary |
| 13 // names for clashes because it's hard - subclasses can force superclasses | 13 // names for clashes because it's hard - subclasses can force superclasses |
| 14 // to rename getters, and that can force unrelated classes to change their | 14 // to rename getters, and that can force unrelated classes to change their |
| 15 // getters too if they have a property that has the same name. | 15 // getters too if they have a property that has the same name. |
| 16 @Native("A") | 16 @Native("A") |
| 17 class A { | 17 class A { |
| 18 int bar; | 18 int bar; |
| 19 int g; | 19 int g; |
| 20 int s; | 20 int s; |
| 21 int end; | 21 int end; |
| 22 int gend; | 22 int gend; |
| 23 int send; | 23 int send; |
| 24 int gettersCalled; | 24 int gettersCalled; |
| 25 int settersCalled; | 25 int settersCalled; |
| 26 } | 26 } |
| 27 | 27 |
| 28 | |
| 29 void setup() native r""" | 28 void setup() native r""" |
| 30 function getter() { | 29 function getter() { |
| 31 this.gettersCalled++; | 30 this.gettersCalled++; |
| 32 return 42; | 31 return 42; |
| 33 } | 32 } |
| 34 | 33 |
| 35 function setter(x) { | 34 function setter(x) { |
| 36 this.settersCalled++; | 35 this.settersCalled++; |
| 37 return 314; | 36 return 314; |
| 38 } | 37 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 send: descriptor | 54 send: descriptor |
| 56 }); | 55 }); |
| 57 a.gettersCalled = 0; | 56 a.gettersCalled = 0; |
| 58 a.settersCalled = 0; | 57 a.settersCalled = 0; |
| 59 return a; | 58 return a; |
| 60 } | 59 } |
| 61 | 60 |
| 62 makeA = function() { return new A; }; | 61 makeA = function() { return new A; }; |
| 63 """; | 62 """; |
| 64 | 63 |
| 65 A makeA() native; | 64 A makeA() native ; |
| 66 | 65 |
| 67 class B { | 66 class B {} |
| 68 } | |
| 69 | 67 |
| 70 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | 68 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); |
| 71 | 69 |
| 72 main() { | 70 main() { |
| 73 setup(); | 71 setup(); |
| 74 var both = [makeA(), new B()]; | 72 var both = [makeA(), new B()]; |
| 75 var foo = both[inscrutable(0)]; | 73 var foo = both[inscrutable(0)]; |
| 76 Expect.equals(42, foo.bar); | 74 Expect.equals(42, foo.bar); |
| 77 Expect.equals(42, foo.g); | 75 Expect.equals(42, foo.g); |
| 78 Expect.equals(42, foo.s); | 76 Expect.equals(42, foo.s); |
| 79 Expect.equals(42, foo.end); | 77 Expect.equals(42, foo.end); |
| 80 Expect.equals(42, foo.gend); | 78 Expect.equals(42, foo.gend); |
| 81 Expect.equals(42, foo.send); | 79 Expect.equals(42, foo.send); |
| 82 Expect.equals(271, foo.bar = 271); | 80 Expect.equals(271, foo.bar = 271); |
| 83 Expect.equals(271, foo.g = 271); | 81 Expect.equals(271, foo.g = 271); |
| 84 Expect.equals(271, foo.s = 271); | 82 Expect.equals(271, foo.s = 271); |
| 85 Expect.equals(271, foo.end = 271); | 83 Expect.equals(271, foo.end = 271); |
| 86 Expect.equals(271, foo.gend = 271); | 84 Expect.equals(271, foo.gend = 271); |
| 87 Expect.equals(271, foo.send = 271); | 85 Expect.equals(271, foo.send = 271); |
| 88 Expect.equals(6, foo.gettersCalled); | 86 Expect.equals(6, foo.gettersCalled); |
| 89 Expect.equals(6, foo.settersCalled); | 87 Expect.equals(6, foo.settersCalled); |
| 90 } | 88 } |
| OLD | NEW |