OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:mirrors" show reflect; | 5 import "dart:mirrors" show reflect; |
6 import "native_testing.dart"; | 6 import "native_testing.dart"; |
7 | 7 |
8 class GetName { | 8 class GetName { |
9 foo(x, y) => "foo"; | 9 foo(x, y) => "foo"; |
10 baz(x, y, z) => "baz"; | 10 baz(x, y, z) => "baz"; |
11 } | 11 } |
12 | 12 |
13 String getName(im) => reflect(new GetName()).delegate(im); | 13 String getName(im) => reflect(new GetName()).delegate(im); |
14 | 14 |
15 @Native("A") | 15 @Native("A") |
16 class A { | 16 class A { |
17 bar() => 42; | 17 bar() => 42; |
18 noSuchMethod(x) => "native(${getName(x)}:${x.positionalArguments})"; | 18 noSuchMethod(x) => "native(${getName(x)}:${x.positionalArguments})"; |
19 } | 19 } |
20 | 20 |
21 @Native("B") | 21 @Native("B") |
22 class B { | 22 class B { |
23 baz() => 42; | 23 baz() => 42; |
24 } | 24 } |
25 | 25 |
26 makeA() native ; | 26 makeA() native; |
27 | 27 |
28 setup() native """ | 28 setup() native """ |
29 function A() {} | 29 function A() {} |
30 makeA = function() { return new A; } | 30 makeA = function() { return new A; } |
31 self.nativeConstructor(A); | 31 self.nativeConstructor(A); |
32 """; | 32 """; |
33 | 33 |
34 main() { | 34 main() { |
35 nativeTesting(); | 35 nativeTesting(); |
36 setup(); | 36 setup(); |
37 var a = makeA(); | 37 var a = makeA(); |
38 a.bar(); | 38 a.bar(); |
39 Expect.equals("native(foo:[1, 2])", a.foo(1, 2)); | 39 Expect.equals("native(foo:[1, 2])", a.foo(1, 2)); |
40 Expect.equals("native(baz:[3, 4, 5])", a.baz(3, 4, 5)); | 40 Expect.equals("native(baz:[3, 4, 5])", a.baz(3, 4, 5)); |
41 } | 41 } |
OLD | NEW |