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