| 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 "native_testing.dart"; | 5 import "native_testing.dart"; |
| 6 | 6 |
| 7 // Verify that native fields on classes are not renamed by the minifier. | 7 // Verify that native fields on classes are not renamed by the minifier. |
| 8 @Native("A") | 8 @Native("A") |
| 9 class A { | 9 class A { |
| 10 int myLongPropertyName; | 10 int myLongPropertyName; |
| 11 int getValue; | 11 int getValue; |
| 12 | 12 |
| 13 int method(int z) => myLongPropertyName; | 13 int method(int z) => myLongPropertyName; |
| 14 } | 14 } |
| 15 | 15 |
| 16 void setup() native r""" | 16 void setup() { |
| 17 JS('', r""" |
| 18 (function(){ |
| 17 function getter() { | 19 function getter() { |
| 18 return ++this.getValue; | 20 return ++this.getValue; |
| 19 } | 21 } |
| 20 | 22 |
| 21 function setter(x) { | 23 function setter(x) { |
| 22 this.getValue += 10; | 24 this.getValue += 10; |
| 23 } | 25 } |
| 24 | 26 |
| 25 function A(){ | 27 function A(){ |
| 26 var a = Object.create( | 28 var a = Object.create( |
| 27 { constructor: A}, | 29 { constructor: A}, |
| 28 { myLongPropertyName: { get: getter, | 30 { myLongPropertyName: { get: getter, |
| 29 set: setter, | 31 set: setter, |
| 30 configurable: false, | 32 configurable: false, |
| 31 writeable: false | 33 writeable: false |
| 32 } | 34 } |
| 33 }); | 35 }); |
| 34 a.getValue = 0; | 36 a.getValue = 0; |
| 35 return a; | 37 return a; |
| 36 } | 38 } |
| 37 | 39 |
| 38 makeA = function(){return new A;}; | 40 makeA = function(){return new A()}; |
| 39 self.nativeConstructor(A); | 41 self.nativeConstructor(A); |
| 40 """; | 42 })()"""); |
| 43 } |
| 41 | 44 |
| 42 A makeA() native; | 45 A makeA() native; |
| 43 | 46 |
| 44 main() { | 47 main() { |
| 45 nativeTesting(); | 48 nativeTesting(); |
| 46 setup(); | 49 setup(); |
| 47 var a = makeA(); | 50 var a = makeA(); |
| 48 a.myLongPropertyName = 21; | 51 a.myLongPropertyName = 21; |
| 49 int gotten = a.myLongPropertyName; | 52 int gotten = a.myLongPropertyName; |
| 50 Expect.equals(11, gotten); | 53 Expect.equals(11, gotten); |
| 51 | 54 |
| 52 // Force interceptor dispatch. | 55 // Force interceptor dispatch. |
| 53 confuse(a).myLongPropertyName = 99; | 56 confuse(a).myLongPropertyName = 99; |
| 54 gotten = confuse(a).myLongPropertyName; | 57 gotten = confuse(a).myLongPropertyName; |
| 55 Expect.equals(22, gotten); | 58 Expect.equals(22, gotten); |
| 56 | 59 |
| 57 var a2 = makeA(); | 60 var a2 = makeA(); |
| 58 if (a2 is A) { | 61 if (a2 is A) { |
| 59 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted | 62 // Inside this 'if' the compiler knows that a2 is an A, so it is tempted |
| 60 // to access myLongPropertyName directly, using its minified name. But | 63 // to access myLongPropertyName directly, using its minified name. But |
| 61 // renaming of native properties can only work using getters and setters | 64 // renaming of native properties can only work using getters and setters |
| 62 // that access the original name. | 65 // that access the original name. |
| 63 a2.myLongPropertyName = 21; | 66 a2.myLongPropertyName = 21; |
| 64 int gotten = a2.myLongPropertyName; | 67 int gotten = a2.myLongPropertyName; |
| 65 Expect.equals(11, gotten); | 68 Expect.equals(11, gotten); |
| 66 } | 69 } |
| 67 } | 70 } |
| OLD | NEW |