| 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 // #3. The name does not get | 6 // #3. The name does not get |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:_js_helper' show Native, JSName; | 9 import 'dart:_js_helper' show Native, JSName; |
| 10 | 10 |
| 11 @Native("A") | 11 @Native("A") |
| 12 class A { | 12 class A { |
| 13 @JSName('fooA') | 13 @JSName('fooA') |
| 14 int foo() native; | 14 int foo() native ; |
| 15 } | 15 } |
| 16 | 16 |
| 17 @Native("B") | 17 @Native("B") |
| 18 class B extends A { | 18 class B extends A { |
| 19 @JSName('fooB') | 19 @JSName('fooB') |
| 20 int foo() native; | 20 int foo() native ; |
| 21 int fooA() => 333; | 21 int fooA() => 333; |
| 22 } | 22 } |
| 23 | 23 |
| 24 class Decoy { | 24 class Decoy { |
| 25 int fooA() => 666; | 25 int fooA() => 666; |
| 26 int fooB() => 999; | 26 int fooB() => 999; |
| 27 } | 27 } |
| 28 | 28 |
| 29 makeA() native; | 29 makeA() native ; |
| 30 makeB() native; | 30 makeB() native ; |
| 31 | |
| 32 | 31 |
| 33 void setup() native """ | 32 void setup() native """ |
| 34 // This code is all inside 'setup' and so not accesible from the global scope. | 33 // This code is all inside 'setup' and so not accesible from the global scope. |
| 35 function inherits(child, parent) { | 34 function inherits(child, parent) { |
| 36 if (child.prototype.__proto__) { | 35 if (child.prototype.__proto__) { |
| 37 child.prototype.__proto__ = parent.prototype; | 36 child.prototype.__proto__ = parent.prototype; |
| 38 } else { | 37 } else { |
| 39 function tmp() {}; | 38 function tmp() {}; |
| 40 tmp.prototype = parent.prototype; | 39 tmp.prototype = parent.prototype; |
| 41 child.prototype = new tmp(); | 40 child.prototype = new tmp(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 var things = [makeA(), makeB(), new Decoy()]; | 55 var things = [makeA(), makeB(), new Decoy()]; |
| 57 var a = things[0]; | 56 var a = things[0]; |
| 58 var b = things[1]; | 57 var b = things[1]; |
| 59 var d = things[2]; | 58 var d = things[2]; |
| 60 | 59 |
| 61 Expect.equals(100, a.foo()); | 60 Expect.equals(100, a.foo()); |
| 62 Expect.equals(200, b.foo()); | 61 Expect.equals(200, b.foo()); |
| 63 Expect.equals(666, d.fooA()); | 62 Expect.equals(666, d.fooA()); |
| 64 Expect.equals(999, d.fooB()); | 63 Expect.equals(999, d.fooB()); |
| 65 | 64 |
| 66 expectNoSuchMethod((){ a.fooA(); }, 'fooA should be invisible on A'); | 65 expectNoSuchMethod(() { |
| 66 a.fooA(); |
| 67 }, 'fooA should be invisible on A'); |
| 67 Expect.equals(333, b.fooA()); | 68 Expect.equals(333, b.fooA()); |
| 68 | 69 |
| 69 expectNoSuchMethod((){ a.fooB(); }, 'fooB should be absent on A'); | 70 expectNoSuchMethod(() { |
| 70 expectNoSuchMethod((){ b.fooB(); }, 'fooA should be invisible on B'); | 71 a.fooB(); |
| 72 }, 'fooB should be absent on A'); |
| 73 expectNoSuchMethod(() { |
| 74 b.fooB(); |
| 75 }, 'fooA should be invisible on B'); |
| 71 } | 76 } |
| 72 | 77 |
| 73 testTyped() { | 78 testTyped() { |
| 74 A a = makeA(); | 79 A a = makeA(); |
| 75 B b = makeB(); | 80 B b = makeB(); |
| 76 Decoy d = new Decoy(); | 81 Decoy d = new Decoy(); |
| 77 | 82 |
| 78 Expect.equals(100, a.foo()); | 83 Expect.equals(100, a.foo()); |
| 79 Expect.equals(200, b.foo()); | 84 Expect.equals(200, b.foo()); |
| 80 Expect.equals(666, d.fooA()); | 85 Expect.equals(666, d.fooA()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 expectNoSuchMethod(action, note) { | 96 expectNoSuchMethod(action, note) { |
| 92 bool caught = false; | 97 bool caught = false; |
| 93 try { | 98 try { |
| 94 action(); | 99 action(); |
| 95 } on NoSuchMethodError catch (ex) { | 100 } on NoSuchMethodError catch (ex) { |
| 96 caught = true; | 101 caught = true; |
| 97 Expect.isTrue(ex is NoSuchMethodError, note); | 102 Expect.isTrue(ex is NoSuchMethodError, note); |
| 98 } | 103 } |
| 99 Expect.isTrue(caught, note); | 104 Expect.isTrue(caught, note); |
| 100 } | 105 } |
| OLD | NEW |