OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title>Custom Elements: HTML parser must construct a custom element instead of u
pgrading</title> |
| 5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> |
| 6 <meta name="assert" content="HTML parser must construct a custom element instead
of upgrading"> |
| 7 <script src="/resources/testharness.js"></script> |
| 8 <script src="/resources/testharnessreport.js"></script> |
| 9 <link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-t
oken"> |
| 10 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element"> |
| 11 </head> |
| 12 <body> |
| 13 <div id="log"></div> |
| 14 <script> |
| 15 |
| 16 let anotherElementCreatedBeforeSuperCall = undefined; |
| 17 let elementCreatedBySuperCall = undefined; |
| 18 let shouldCreateElementBeforeSuperCall = true; |
| 19 class InstantiatesItselfBeforeSuper extends HTMLElement { |
| 20 constructor() { |
| 21 if (shouldCreateElementBeforeSuperCall) { |
| 22 shouldCreateElementBeforeSuperCall = false; |
| 23 anotherElementCreatedBeforeSuperCall = new InstantiatesItselfBeforeS
uper(); |
| 24 } |
| 25 super(); |
| 26 elementCreatedBySuperCall = this; |
| 27 } |
| 28 }; |
| 29 customElements.define('instantiates-itself-before-super', InstantiatesItselfBefo
reSuper); |
| 30 |
| 31 let shouldCreateAnotherInstance = true; |
| 32 let anotherInstance = undefined; |
| 33 let firstInstance = undefined; |
| 34 class ReturnsAnotherInstance extends HTMLElement { |
| 35 constructor() { |
| 36 super(); |
| 37 if (shouldCreateAnotherInstance) { |
| 38 shouldCreateAnotherInstance = false; |
| 39 firstInstance = this; |
| 40 anotherInstance = new ReturnsAnotherInstance; |
| 41 return anotherInstance; |
| 42 } else |
| 43 return this; |
| 44 } |
| 45 }; |
| 46 customElements.define('returns-another-instance', ReturnsAnotherInstance); |
| 47 |
| 48 </script> |
| 49 <instantiates-itself-before-super></instantiates-itself-before-super> |
| 50 <returns-another-instance></returns-another-instance> |
| 51 <script> |
| 52 |
| 53 test(function () { |
| 54 var instance = document.querySelector('instantiates-itself-before-super'); |
| 55 |
| 56 assert_equals(instance instanceof InstantiatesItselfBeforeSuper, 'HTML parse
r must insert the synchronously constructed custom element'); |
| 57 assert_equals(instance, elementCreatedBySuperCall, 'HTML parser must insert
the element returned by the custom element constructor'); |
| 58 assert_not_equals(instance, anotherElementCreatedBeforeSuperCall, 'HTML pars
er must not insert another instance of the custom element created before super()
call'); |
| 59 assert_equals(anotherElementCreatedBeforeSuperCall.parentNode, null, 'HTML p
arser must not insert another instance of the custom element created before supe
r() call'); |
| 60 |
| 61 }, 'HTML parser must use the returned value of the custom element constructor in
stead of the one created before super() call'); |
| 62 |
| 63 test(function () { |
| 64 var instance = document.querySelector('returns-another-instance'); |
| 65 |
| 66 assert_equals(instance instanceof ReturnsAnotherInstance, 'HTML parser must
insert the synchronously constructed custom element'); |
| 67 assert_equals(instance, anotherInstance, 'HTML parser must insert the elemen
t returned by the custom element constructor'); |
| 68 assert_not_equals(instance, firstInstance, 'HTML parser must not insert the
element created by super() call if the constructor returned another element'); |
| 69 assert_equals(firstInstance.parentNode, null, 'HTML parser must not insert t
he element created by super() call if the constructor returned another element')
; |
| 70 |
| 71 }, 'HTML parser must use the returned value of the custom element constructor in
stead using the one created in super() call'); |
| 72 |
| 73 </script> |
| 74 </body> |
| 75 </html> |
OLD | NEW |