| 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 import 'native_testing.dart'; | 5 import 'native_testing.dart'; |
| 6 | 6 |
| 7 // Test to see if novel HTML tags are interpreted as HTMLElement. | 7 // Test to see if novel HTML tags are interpreted as HTMLElement. |
| 8 | 8 |
| 9 @Native("HTMLElement") | 9 @Native("HTMLElement") |
| 10 class Element { | 10 class Element { |
| 11 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; | 11 String dartMethod(int x) => 'dartMethod(${nativeMethod(x+1)})'; |
| 12 String nativeMethod(int x) native; | 12 String nativeMethod(int x) native; |
| 13 } | 13 } |
| 14 | 14 |
| 15 makeE() native; | 15 makeE() native; |
| 16 makeF() native; | 16 makeF() native; |
| 17 | 17 |
| 18 void setup() native """ | 18 void setup() { |
| 19 // A novel HTML element. | 19 JS('', r""" |
| 20 function HTMLGoofyElement(){} | 20 (function(){ |
| 21 HTMLGoofyElement.prototype.nativeMethod = function(a) { | 21 // A novel HTML element. |
| 22 return 'Goofy.nativeMethod(' + a + ')'; | 22 function HTMLGoofyElement(){} |
| 23 }; | 23 HTMLGoofyElement.prototype.nativeMethod = function(a) { |
| 24 makeE = function(){return new HTMLGoofyElement}; | 24 return 'Goofy.nativeMethod(' + a + ')'; |
| 25 }; |
| 26 makeE = function(){return new HTMLGoofyElement()}; |
| 25 | 27 |
| 26 // A non-HTML element with a misleading name. | 28 // A non-HTML element with a misleading name. |
| 27 function HTMLFakeyElement(){} | 29 function HTMLFakeyElement(){} |
| 28 HTMLFakeyElement.prototype.nativeMethod = function(a) { | 30 HTMLFakeyElement.prototype.nativeMethod = function(a) { |
| 29 return 'Fakey.nativeMethod(' + a + ')'; | 31 return 'Fakey.nativeMethod(' + a + ')'; |
| 30 }; | 32 }; |
| 31 makeF = function(){return new HTMLFakeyElement}; | 33 makeF = function(){return new HTMLFakeyElement()}; |
| 32 | 34 |
| 33 self.nativeConstructor(HTMLGoofyElement); | 35 self.nativeConstructor(HTMLGoofyElement); |
| 34 """; | 36 })()"""); |
| 37 } |
| 35 | 38 |
| 36 main() { | 39 main() { |
| 37 nativeTesting(); | 40 nativeTesting(); |
| 38 setup(); | 41 setup(); |
| 39 | 42 |
| 40 var e = makeE(); | 43 var e = makeE(); |
| 41 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); | 44 Expect.equals('Goofy.nativeMethod(10)', e.nativeMethod(10)); |
| 42 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); | 45 Expect.equals('dartMethod(Goofy.nativeMethod(11))', e.dartMethod(10)); |
| 43 | 46 |
| 44 var f = makeF(); | 47 var f = makeF(); |
| 45 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, | 48 Expect.throws(() => f.nativeMethod(20), (e) => e is NoSuchMethodError, |
| 46 'fake HTML Element must not run Dart method on native class'); | 49 'fake HTML Element must not run Dart method on native class'); |
| 47 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, | 50 Expect.throws(() => f.dartMethod(20), (e) => e is NoSuchMethodError, |
| 48 'fake HTML Element must not run native method on native class'); | 51 'fake HTML Element must not run native method on native class'); |
| 49 } | 52 } |
| OLD | NEW |