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 // Test the feature where the native string declares the native method's name. | 5 // Test the feature where the native string declares the native method's name. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:_js_helper' show Native, JSName; | 8 import 'dart:_js_helper' show Native, JSName; |
9 | 9 |
10 @Native("A") | 10 @Native("A") |
11 class A { | 11 class A { |
12 @JSName('fooA') | 12 @JSName('fooA') |
13 int foo() native; | 13 int foo() native ; |
14 | 14 |
15 @JSName('barA') | 15 @JSName('barA') |
16 int bar() native; | 16 int bar() native ; |
17 | 17 |
18 @JSName('bazA') | 18 @JSName('bazA') |
19 int baz() native; | 19 int baz() native ; |
20 } | 20 } |
21 | 21 |
22 A makeA() native; | 22 A makeA() native ; |
23 | 23 |
24 class B { | 24 class B { |
25 int bar([x]) => 800; | 25 int bar([x]) => 800; |
26 int baz() => 900; | 26 int baz() => 900; |
27 } | 27 } |
28 | 28 |
29 void setup() native """ | 29 void setup() native """ |
30 // This code is all inside 'setup' and so not accesible from the global scope. | 30 // This code is all inside 'setup' and so not accesible from the global scope. |
31 function A(){} | 31 function A(){} |
32 A.prototype.fooA = function(){return 100;}; | 32 A.prototype.fooA = function(){return 100;}; |
33 A.prototype.barA = function(){return 200;}; | 33 A.prototype.barA = function(){return 200;}; |
34 A.prototype.bazA = function(){return 300;}; | 34 A.prototype.bazA = function(){return 300;}; |
35 | 35 |
36 makeA = function(){return new A}; | 36 makeA = function(){return new A}; |
37 """; | 37 """; |
38 | 38 |
39 | |
40 testDynamic() { | 39 testDynamic() { |
41 setup(); | 40 setup(); |
42 | 41 |
43 var things = [makeA(), new B()]; | 42 var things = [makeA(), new B()]; |
44 var a = things[0]; | 43 var a = things[0]; |
45 var b = things[1]; | 44 var b = things[1]; |
46 | 45 |
47 Expect.equals(100, a.foo()); | 46 Expect.equals(100, a.foo()); |
48 Expect.equals(200, a.bar()); | 47 Expect.equals(200, a.bar()); |
49 Expect.equals(300, a.baz()); | 48 Expect.equals(300, a.baz()); |
(...skipping 21 matching lines...) Expand all Loading... |
71 expectNoSuchMethod(action, note) { | 70 expectNoSuchMethod(action, note) { |
72 bool caught = false; | 71 bool caught = false; |
73 try { | 72 try { |
74 action(); | 73 action(); |
75 } catch (ex) { | 74 } catch (ex) { |
76 caught = true; | 75 caught = true; |
77 Expect.isTrue(ex is NoSuchMethodError, note); | 76 Expect.isTrue(ex is NoSuchMethodError, note); |
78 } | 77 } |
79 Expect.isTrue(caught, note); | 78 Expect.isTrue(caught, note); |
80 } | 79 } |
OLD | NEW |