Chromium Code Reviews| 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 "native_testing.dart"; |
| 6 | 6 |
| 7 // Native class with named constructors and static methods. | 7 // Native class with named constructors and static methods. |
| 8 | 8 |
| 9 @Native("A") | 9 @Native("A") |
| 10 class A { | 10 class A { |
| 11 factory A(int len) => _construct(len); | 11 factory A(int len) => _construct(len); |
| 12 | 12 |
| 13 factory A.fromString(String s) => _construct(s.length); | 13 factory A.fromString(String s) => _construct(s.length); |
| 14 | 14 |
| 15 // Only functions with zero parameters are allowed with "native r'...'". | 15 // Only functions with zero parameters are allowed with "native r'...'". |
| 16 factory A.nativeConstructor() native r'return makeA(102);'; | 16 factory A.nativeConstructor() { |
|
Siggi Cherem (dart-lang)
2017/07/31 21:51:11
might be worth updating the comment above - from h
sra1
2017/07/31 22:11:30
Done.
| |
| 17 return JS('A|Null', 'makeA(102)'); | |
| 18 } | |
| 17 | 19 |
| 18 static A _construct(v) { | 20 static A _construct(v) { |
| 19 return makeA(v); | 21 return makeA(v); |
| 20 } | 22 } |
| 21 | 23 |
| 22 foo() native; | 24 foo() native; |
| 23 } | 25 } |
| 24 | 26 |
| 25 makeA(v) native; | 27 makeA(v) native; |
| 26 | 28 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 39 nativeTesting(); | 41 nativeTesting(); |
| 40 setup(); | 42 setup(); |
| 41 var a1 = new A(100); | 43 var a1 = new A(100); |
| 42 var a2 = new A.fromString('Hello'); | 44 var a2 = new A.fromString('Hello'); |
| 43 var a3 = new A.nativeConstructor(); | 45 var a3 = new A.nativeConstructor(); |
| 44 | 46 |
| 45 Expect.equals(100, a1.foo()); | 47 Expect.equals(100, a1.foo()); |
| 46 Expect.equals(5, a2.foo()); | 48 Expect.equals(5, a2.foo()); |
| 47 Expect.equals(102, a3.foo()); | 49 Expect.equals(102, a3.foo()); |
| 48 } | 50 } |
| OLD | NEW |