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