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 "native_testing.dart"; | 5 import "dart:_js_helper"; |
| 6 import "package:expect/expect.dart"; |
6 | 7 |
7 @Native("A") | 8 @Native("A") |
8 class A {} | 9 class A {} |
9 | 10 |
10 @Native("B") | 11 @Native("B") |
11 class B extends A { | 12 class B extends A { |
12 foo() native ; | 13 foo() native ; |
13 } | 14 } |
14 | 15 |
15 makeA() native ; | 16 makeA() native ; |
16 makeB() native ; | 17 makeB() native ; |
17 | 18 |
18 setup() native """ | 19 setup() native """ |
19 function inherits(child, parent) { | 20 function inherits(child, parent) { |
20 if (child.prototype.__proto__) { | 21 if (child.prototype.__proto__) { |
21 child.prototype.__proto__ = parent.prototype; | 22 child.prototype.__proto__ = parent.prototype; |
22 } else { | 23 } else { |
23 function tmp() {}; | 24 function tmp() {}; |
24 tmp.prototype = parent.prototype; | 25 tmp.prototype = parent.prototype; |
25 child.prototype = new tmp(); | 26 child.prototype = new tmp(); |
26 child.prototype.constructor = child; | 27 child.prototype.constructor = child; |
27 } | 28 } |
28 } | 29 } |
29 function A() {} | 30 function A() {} |
30 function B() {} | 31 function B() {} |
31 inherits(B, A); | 32 inherits(B, A); |
32 makeA = function() { return new A; } | 33 makeA = function() { return new A; } |
33 makeB = function() { return new B; } | 34 makeB = function() { return new B; } |
34 B.prototype.foo = function() { return 42; } | 35 B.prototype.foo = function() { return 42; } |
35 | |
36 self.nativeConstructor(A); | |
37 self.nativeConstructor(B); | |
38 """; | 36 """; |
39 | 37 |
40 main() { | 38 main() { |
41 nativeTesting(); | |
42 setup(); | 39 setup(); |
43 var a = makeA(); | 40 var a = makeA(); |
44 var exception; | 41 var exception; |
45 try { | 42 try { |
46 a.foo(); | 43 a.foo(); |
47 } on NoSuchMethodError catch (e) { | 44 } on NoSuchMethodError catch (e) { |
48 exception = e; | 45 exception = e; |
49 } | 46 } |
50 Expect.isNotNull(exception); | 47 Expect.isNotNull(exception); |
51 | 48 |
52 var b = makeB(); | 49 var b = makeB(); |
53 Expect.equals(42, b.foo()); | 50 Expect.equals(42, b.foo()); |
54 } | 51 } |
OLD | NEW |