| 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 // Properties on hidden native classes. | 5 // Properties on hidden native classes. |
| 6 | 6 |
| 7 @native("*A") | 7 import 'native_metadata.dart'; |
| 8 |
| 9 @Native("*A") |
| 8 class A { | 10 class A { |
| 9 | 11 |
| 10 // Setters and getters should be similar to these methods: | 12 // Setters and getters should be similar to these methods: |
| 11 @native('return this._x;') | 13 @Native('return this._x;') |
| 12 int getX(); | 14 int getX(); |
| 13 | 15 |
| 14 @native('this._x = value;') | 16 @Native('this._x = value;') |
| 15 void setX(int value); | 17 void setX(int value); |
| 16 | 18 |
| 17 @native | 19 @native |
| 18 int get X; | 20 int get X; |
| 19 | 21 |
| 20 @native | 22 @native |
| 21 set X(int value); | 23 set X(int value); |
| 22 | 24 |
| 23 @native | 25 @native |
| 24 int get Y; | 26 int get Y; |
| 25 | 27 |
| 26 @native | 28 @native |
| 27 set Y(int value); | 29 set Y(int value); |
| 28 | 30 |
| 29 @native('return this._z;') | 31 @Native('return this._z;') |
| 30 int get Z; | 32 int get Z; |
| 31 | 33 |
| 32 @native('this._z = value;') | 34 @Native('this._z = value;') |
| 33 set Z(int value); | 35 set Z(int value); |
| 34 } | 36 } |
| 35 | 37 |
| 36 @native | 38 @native |
| 37 A makeA() { return new A(); } | 39 A makeA() { return new A(); } |
| 38 | 40 |
| 39 @native(""" | 41 @Native(""" |
| 40 function A() {} | 42 function A() {} |
| 41 | 43 |
| 42 Object.defineProperty(A.prototype, "X", { | 44 Object.defineProperty(A.prototype, "X", { |
| 43 get: function () { return this._x; }, | 45 get: function () { return this._x; }, |
| 44 set: function (v) { this._x = v; } | 46 set: function (v) { this._x = v; } |
| 45 }); | 47 }); |
| 46 | 48 |
| 47 makeA = function(){return new A;}; | 49 makeA = function(){return new A;}; |
| 48 """) | 50 """) |
| 49 void setup(); | 51 void setup(); |
| 50 | 52 |
| 51 | 53 |
| 52 main() { | 54 main() { |
| 53 setup(); | 55 setup(); |
| 54 | 56 |
| 55 var a = makeA(); | 57 var a = makeA(); |
| 56 | 58 |
| 57 a.setX(5); | 59 a.setX(5); |
| 58 Expect.equals(5, a.getX()); | 60 Expect.equals(5, a.getX()); |
| 59 | 61 |
| 60 a.X = 10; | 62 a.X = 10; |
| 61 a.Y = 20; | 63 a.Y = 20; |
| 62 a.Z = 30; | 64 a.Z = 30; |
| 63 | 65 |
| 64 Expect.equals(10, a.X); | 66 Expect.equals(10, a.X); |
| 65 Expect.equals(20, a.Y); | 67 Expect.equals(20, a.Y); |
| 66 Expect.equals(30, a.Z); | 68 Expect.equals(30, a.Z); |
| 67 } | 69 } |
| OLD | NEW |