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