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