Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
|
ngeoffray
2012/12/12 08:14:10
2011 is so almost 2 years ago :-)
| |
| 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. | |
| 4 | |
| 5 // Test to see if novel HTML tags are interpreted as HTMLElement. | |
| 6 | |
| 7 class Element native "*HTMLElement" { | |
| 8 String foo(int x) => '[${bar(x+1)}]'; | |
| 9 String bar(int x) native; | |
| 10 } | |
| 11 | |
| 12 makeE() native; | |
| 13 makeF() native; | |
| 14 | |
| 15 void setup() native """ | |
| 16 // A novel HTML element. | |
| 17 function HTMLGoofyElement(){} | |
| 18 HTMLGoofyElement.prototype.bar = function(a){return 'Goofy.foo(' + a + ')';} | |
| 19 makeE = function(){return new HTMLGoofyElement}; | |
| 20 | |
| 21 // A non-HTML element with a misleading name. | |
| 22 function HTMLFakeyElement(){} | |
| 23 HTMLFakeyElement.prototype.bar = function(a){return 'Fakey.foo(' + a + ')';} | |
| 24 makeF = function(){return new HTMLFakeyElement}; | |
| 25 | |
| 26 // Make the HTMLGoofyElement look like a real host object. | |
| 27 var theRealObjectToString = Object.prototype.toString; | |
| 28 Object.prototype.toString = function() { | |
| 29 if (this instanceof HTMLGoofyElement) return '[object HTMLGoofyElement]'; | |
| 30 return theRealObjectToString.call(this); | |
| 31 } | |
| 32 """; | |
| 33 | |
| 34 | |
| 35 main() { | |
| 36 setup(); | |
| 37 | |
| 38 print(123); | |
|
kasperl
2012/12/12 06:43:50
Is this needed?
| |
| 39 var e = makeE(); | |
| 40 Expect.equals('[Goofy.foo(11)]', e.foo(10)); | |
| 41 | |
| 42 var f = makeF(); | |
| 43 expectNoSuchMethod(() => f.foo(20), 'f.foo(20) should fail'); | |
| 44 } | |
| 45 | |
| 46 expectNoSuchMethod(action, note) { | |
|
kasperl
2012/12/12 06:43:50
Can you use Expect.throws?
| |
| 47 bool caught = false; | |
| 48 try { | |
| 49 action(); | |
| 50 } catch (ex) { | |
| 51 caught = true; | |
| 52 Expect.isTrue(ex is NoSuchMethodError, note); | |
| 53 } | |
| 54 Expect.isTrue(caught, note); | |
| 55 } | |
| OLD | NEW |