| 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 methods are not renamed to clash with native field names | 8 // Verify that methods are not renamed to clash with native field names |
| 9 // that are known from the DOM (like x, y, z). | 9 // that are known from the DOM (like x, y, z). |
| 10 @Native("A") | 10 @Native("A") |
| 11 class A { | 11 class A { |
| 12 int x; | 12 int x; |
| 13 int y; | 13 int y; |
| 14 int z; | 14 int z; |
| 15 int gettersCalled; | 15 int gettersCalled; |
| 16 } | 16 } |
| 17 | 17 |
| 18 | |
| 19 void setup() native r""" | 18 void setup() native r""" |
| 20 function getter() { | 19 function getter() { |
| 21 this.gettersCalled++; | 20 this.gettersCalled++; |
| 22 return 42; | 21 return 42; |
| 23 } | 22 } |
| 24 | 23 |
| 25 function A(){ | 24 function A(){ |
| 26 var a = Object.create( | 25 var a = Object.create( |
| 27 { constructor: { name: 'A'}}, | 26 { constructor: { name: 'A'}}, |
| 28 { x: { get: getter, configurable: false, writeable: false }, | 27 { x: { get: getter, configurable: false, writeable: false }, |
| 29 y: { get: getter, configurable: false, writeable: false }, | 28 y: { get: getter, configurable: false, writeable: false }, |
| 30 z: { get: getter, configurable: false, writeable: false } | 29 z: { get: getter, configurable: false, writeable: false } |
| 31 }); | 30 }); |
| 32 a.gettersCalled = 0; | 31 a.gettersCalled = 0; |
| 33 return a; | 32 return a; |
| 34 } | 33 } |
| 35 | 34 |
| 36 makeA = function() { return new A; }; | 35 makeA = function() { return new A; }; |
| 37 """; | 36 """; |
| 38 | 37 |
| 39 A makeA() native; | 38 A makeA() native ; |
| 40 | 39 |
| 41 class B { | 40 class B { |
| 42 void a() { } | 41 void a() {} |
| 43 void a0() { } | 42 void a0() {} |
| 44 void a1() { } | 43 void a1() {} |
| 45 void a2() { } | 44 void a2() {} |
| 46 void a3() { } | 45 void a3() {} |
| 47 void a4() { } | 46 void a4() {} |
| 48 void a5() { } | 47 void a5() {} |
| 49 void a6() { } | 48 void a6() {} |
| 50 void a7() { } | 49 void a7() {} |
| 51 void a8() { } | 50 void a8() {} |
| 52 void a9() { } | 51 void a9() {} |
| 53 void a10() { } | 52 void a10() {} |
| 54 void a11() { } | 53 void a11() {} |
| 55 void a12() { } | 54 void a12() {} |
| 56 void a13() { } | 55 void a13() {} |
| 57 void a14() { } | 56 void a14() {} |
| 58 void a15() { } | 57 void a15() {} |
| 59 void a16() { } | 58 void a16() {} |
| 60 void a17() { } | 59 void a17() {} |
| 61 void a18() { } | 60 void a18() {} |
| 62 void a19() { } | 61 void a19() {} |
| 63 void a20() { } | 62 void a20() {} |
| 64 void a21() { } | 63 void a21() {} |
| 65 void a22() { } | 64 void a22() {} |
| 66 void a23() { } | 65 void a23() {} |
| 67 void a24() { } | 66 void a24() {} |
| 68 void a25() { } | 67 void a25() {} |
| 69 void a26() { } | 68 void a26() {} |
| 70 int z = 0; | 69 int z = 0; |
| 71 } | 70 } |
| 72 | 71 |
| 73 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); | 72 int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1)); |
| 74 | 73 |
| 75 main() { | 74 main() { |
| 76 setup(); | 75 setup(); |
| 77 var both = [makeA(), new B()]; | 76 var both = [makeA(), new B()]; |
| 78 var x = both[inscrutable(0)]; | 77 var x = both[inscrutable(0)]; |
| 79 // Each of these will throw, because an instance of A doesn't have any of | 78 // Each of these will throw, because an instance of A doesn't have any of |
| 80 // these functions. The important thing is that none of them have been | 79 // these functions. The important thing is that none of them have been |
| 81 // renamed to be called 'z' by the minifier, because then the getter will be | 80 // renamed to be called 'z' by the minifier, because then the getter will be |
| 82 // hit. | 81 // hit. |
| 83 try { x.a(); } catch(e) { } | 82 try { |
| 84 try { x.a0(); } catch(e) { } | 83 x.a(); |
| 85 try { x.a1(); } catch(e) { } | 84 } catch (e) {} |
| 86 try { x.a2(); } catch(e) { } | 85 try { |
| 87 try { x.a3(); } catch(e) { } | 86 x.a0(); |
| 88 try { x.a4(); } catch(e) { } | 87 } catch (e) {} |
| 89 try { x.a5(); } catch(e) { } | 88 try { |
| 90 try { x.a6(); } catch(e) { } | 89 x.a1(); |
| 91 try { x.a7(); } catch(e) { } | 90 } catch (e) {} |
| 92 try { x.a8(); } catch(e) { } | 91 try { |
| 93 try { x.a9(); } catch(e) { } | 92 x.a2(); |
| 94 try { x.a10(); } catch(e) { } | 93 } catch (e) {} |
| 95 try { x.a11(); } catch(e) { } | 94 try { |
| 96 try { x.a12(); } catch(e) { } | 95 x.a3(); |
| 97 try { x.a13(); } catch(e) { } | 96 } catch (e) {} |
| 98 try { x.a14(); } catch(e) { } | 97 try { |
| 99 try { x.a15(); } catch(e) { } | 98 x.a4(); |
| 100 try { x.a16(); } catch(e) { } | 99 } catch (e) {} |
| 101 try { x.a17(); } catch(e) { } | 100 try { |
| 102 try { x.a18(); } catch(e) { } | 101 x.a5(); |
| 103 try { x.a19(); } catch(e) { } | 102 } catch (e) {} |
| 104 try { x.a20(); } catch(e) { } | 103 try { |
| 105 try { x.a21(); } catch(e) { } | 104 x.a6(); |
| 106 try { x.a12(); } catch(e) { } | 105 } catch (e) {} |
| 107 try { x.a23(); } catch(e) { } | 106 try { |
| 108 try { x.a24(); } catch(e) { } | 107 x.a7(); |
| 109 try { x.a25(); } catch(e) { } | 108 } catch (e) {} |
| 110 try { x.a26(); } catch(e) { } | 109 try { |
| 110 x.a8(); |
| 111 } catch (e) {} |
| 112 try { |
| 113 x.a9(); |
| 114 } catch (e) {} |
| 115 try { |
| 116 x.a10(); |
| 117 } catch (e) {} |
| 118 try { |
| 119 x.a11(); |
| 120 } catch (e) {} |
| 121 try { |
| 122 x.a12(); |
| 123 } catch (e) {} |
| 124 try { |
| 125 x.a13(); |
| 126 } catch (e) {} |
| 127 try { |
| 128 x.a14(); |
| 129 } catch (e) {} |
| 130 try { |
| 131 x.a15(); |
| 132 } catch (e) {} |
| 133 try { |
| 134 x.a16(); |
| 135 } catch (e) {} |
| 136 try { |
| 137 x.a17(); |
| 138 } catch (e) {} |
| 139 try { |
| 140 x.a18(); |
| 141 } catch (e) {} |
| 142 try { |
| 143 x.a19(); |
| 144 } catch (e) {} |
| 145 try { |
| 146 x.a20(); |
| 147 } catch (e) {} |
| 148 try { |
| 149 x.a21(); |
| 150 } catch (e) {} |
| 151 try { |
| 152 x.a12(); |
| 153 } catch (e) {} |
| 154 try { |
| 155 x.a23(); |
| 156 } catch (e) {} |
| 157 try { |
| 158 x.a24(); |
| 159 } catch (e) {} |
| 160 try { |
| 161 x.a25(); |
| 162 } catch (e) {} |
| 163 try { |
| 164 x.a26(); |
| 165 } catch (e) {} |
| 111 Expect.equals(0, x.gettersCalled); | 166 Expect.equals(0, x.gettersCalled); |
| 112 Expect.equals(42, x.z); | 167 Expect.equals(42, x.z); |
| 113 Expect.equals(1, x.gettersCalled); | 168 Expect.equals(1, x.gettersCalled); |
| 114 } | 169 } |
| OLD | NEW |