| 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 "native_testing.dart"; | 7 import "native_testing.dart"; |
| 8 | 8 |
| 9 @Native("A") | 9 @Native("A") |
| 10 class A { | 10 class A { |
| 11 @JSName('fooA') | 11 @JSName('fooA') |
| 12 int foo() native; | 12 int foo() native; |
| 13 } | 13 } |
| 14 | 14 |
| 15 @Native("B") | 15 @Native("B") |
| 16 class B extends A { | 16 class B extends A { |
| 17 @JSName('fooB') | 17 @JSName('fooB') |
| 18 int foo() native; | 18 int foo() native; |
| 19 } | 19 } |
| 20 | 20 |
| 21 makeA() native; | 21 makeA() native; |
| 22 makeB() native; | 22 makeB() native; |
| 23 | 23 |
| 24 void setup() native """ | 24 void setup() { |
| 25 // This code is all inside 'setup' and so not accessible from the global scope. | 25 JS('', r""" |
| 26 function inherits(child, parent) { | 26 (function(){ |
| 27 if (child.prototype.__proto__) { | 27 // This code is inside 'setup' and so not accessible from the global scope. |
| 28 child.prototype.__proto__ = parent.prototype; | 28 function inherits(child, parent) { |
| 29 } else { | 29 if (child.prototype.__proto__) { |
| 30 function tmp() {}; | 30 child.prototype.__proto__ = parent.prototype; |
| 31 tmp.prototype = parent.prototype; | 31 } else { |
| 32 child.prototype = new tmp(); | 32 function tmp() {}; |
| 33 child.prototype.constructor = child; | 33 tmp.prototype = parent.prototype; |
| 34 child.prototype = new tmp(); |
| 35 child.prototype.constructor = child; |
| 36 } |
| 34 } | 37 } |
| 38 function A(){} |
| 39 A.prototype.fooA = function(){return 100;}; |
| 40 function B(){} |
| 41 inherits(B, A); |
| 42 B.prototype.fooB = function(){return 200;}; |
| 43 |
| 44 makeA = function(){return new A()}; |
| 45 makeB = function(){return new B()}; |
| 46 |
| 47 self.nativeConstructor(A); |
| 48 self.nativeConstructor(B); |
| 49 })()"""); |
| 35 } | 50 } |
| 36 function A(){} | |
| 37 A.prototype.fooA = function(){return 100;}; | |
| 38 function B(){} | |
| 39 inherits(B, A); | |
| 40 B.prototype.fooB = function(){return 200;}; | |
| 41 | |
| 42 makeA = function(){return new A}; | |
| 43 makeB = function(){return new B}; | |
| 44 | |
| 45 self.nativeConstructor(A); | |
| 46 self.nativeConstructor(B); | |
| 47 """; | |
| 48 | 51 |
| 49 testDynamic() { | 52 testDynamic() { |
| 50 var things = [makeA(), makeB()]; | 53 var things = [makeA(), makeB()]; |
| 51 var a = things[0]; | 54 var a = things[0]; |
| 52 var b = things[1]; | 55 var b = things[1]; |
| 53 | 56 |
| 54 Expect.equals(100, a.foo()); | 57 Expect.equals(100, a.foo()); |
| 55 Expect.equals(200, b.foo()); | 58 Expect.equals(200, b.foo()); |
| 56 | 59 |
| 57 expectNoSuchMethod(() { | 60 expectNoSuchMethod(() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 88 expectNoSuchMethod(action, note) { | 91 expectNoSuchMethod(action, note) { |
| 89 bool caught = false; | 92 bool caught = false; |
| 90 try { | 93 try { |
| 91 action(); | 94 action(); |
| 92 } catch (ex) { | 95 } catch (ex) { |
| 93 caught = true; | 96 caught = true; |
| 94 Expect.isTrue(ex is NoSuchMethodError, note); | 97 Expect.isTrue(ex is NoSuchMethodError, note); |
| 95 } | 98 } |
| 96 Expect.isTrue(caught, note); | 99 Expect.isTrue(caught, note); |
| 97 } | 100 } |
| OLD | NEW |