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