| OLD | NEW |
| (Empty) |
| 1 #import('../../../../../dart/client/testing/unittest/unittest.dart'); | |
| 2 #import('dart:html'); | |
| 3 | |
| 4 // Test that the dart:html API does not leak native jsdom methods: | |
| 5 // appendChild operation. | |
| 6 | |
| 7 main() { | |
| 8 forLayoutTests(); | |
| 9 | |
| 10 test('test1', () { | |
| 11 document.body.elements.add(new Element.html(@''' | |
| 12 <div id='div1'> | |
| 13 Hello World! | |
| 14 </div>''')); | |
| 15 Element e = document.query('#div1'); | |
| 16 Element e2 = new Element.html(@"<div id='xx'>XX</div>"); | |
| 17 Expect.isTrue(e != null); | |
| 18 | |
| 19 checkNoSuchMethod(() { confuse(e).appendChild(e2); }); | |
| 20 | |
| 21 }); | |
| 22 } | |
| 23 | |
| 24 class Decoy { | |
| 25 void appendChild(x) { throw 'dead code'; } | |
| 26 } | |
| 27 | |
| 28 confuse(x) => opaqueTrue() ? x : (opaqueTrue() ? new Object() : new Decoy()); | |
| 29 | |
| 30 /** Returns [:true:], but in a way that confuses the compiler. */ | |
| 31 opaqueTrue() => true; // Expand as needed. | |
| 32 | |
| 33 checkNoSuchMethod(action()) { | |
| 34 var ex = null; | |
| 35 bool threw = false; | |
| 36 try { | |
| 37 action(); | |
| 38 } catch (var e) { | |
| 39 threw = true; | |
| 40 ex = e; | |
| 41 } | |
| 42 if (!threw) | |
| 43 Expect.fail('Action should have thrown exception'); | |
| 44 | |
| 45 Expect.isTrue(ex is NoSuchMethodException, 'ex is NoSuchMethodException'); | |
| 46 } | |
| OLD | NEW |