OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../resources/testharness.js"></script> |
| 3 <script src="../resources/testharness-helpers.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="spec/resources/custom-elements-helpers.js"></script> |
| 6 <body> |
| 7 <script> |
| 8 'use strict'; |
| 9 |
| 10 test_with_window((w) => { |
| 11 let doc = w.document; |
| 12 let e = doc.createElement('a-a'); |
| 13 doc.body.appendChild(e); |
| 14 var misbehave = true; |
| 15 var invocations = []; |
| 16 class X extends w.HTMLElement { |
| 17 constructor() { |
| 18 if (misbehave) { |
| 19 misbehave = false; |
| 20 invocations.push('misbehaving'); |
| 21 return new X(); |
| 22 } |
| 23 super(); |
| 24 invocations.push(this); |
| 25 } |
| 26 } |
| 27 w.customElements.define('a-a', X); |
| 28 assert_array_equals(invocations, ['misbehaving', e], |
| 29 'returning the existing element should have succeeded'); |
| 30 }, 'HTMLElement constructor: poach but return upgrade candidate'); |
| 31 |
| 32 test_with_window((w) => { |
| 33 let doc = w.document; |
| 34 let e = doc.createElement('a-a'); |
| 35 doc.body.appendChild(e); |
| 36 var misbehave = true; |
| 37 var invocations = []; |
| 38 var poacher; |
| 39 class X extends w.HTMLElement { |
| 40 constructor() { |
| 41 if (misbehave) { |
| 42 misbehave = false; |
| 43 poacher = new X(); |
| 44 } |
| 45 try { |
| 46 super(); |
| 47 invocations.push(this); |
| 48 } catch (e) { |
| 49 invocations.push(e); |
| 50 } |
| 51 } |
| 52 } |
| 53 w.customElements.define('a-a', X); |
| 54 assert_equals(invocations.length, 2, |
| 55 'the constructor should have been invoked once for upgrade ' + |
| 56 'and once for the recursive call to "new"'); |
| 57 assert_equals(poacher, e, |
| 58 'the recursive "new" should steal the upgrade candidate'); |
| 59 assert_equals(poacher, invocations[0], |
| 60 'the recursize "new" should happen first'); |
| 61 assert_true(invocations[1] instanceof w.DOMException, |
| 62 'the super call should have thrown a DOMException'); |
| 63 assert_equals(invocations[1].name, 'InvalidStateError', |
| 64 'the exception should be an InvalidStateError'); |
| 65 }, 'HTMLElement constructor: poach upgrade candidate'); |
| 66 </script> |
OLD | NEW |