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