Element-customElementRegistry-exceptions.html (3723B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> 5 <link rel="help" href="https://github.com/whatwg/html/issues/10854"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 </head> 9 <body> 10 <script> 11 12 setup({allow_uncaught_exception : true}); 13 14 test(() => { 15 const registry = new CustomElementRegistry; 16 registry.define('constructor-throws-exception', class extends HTMLElement { constructor() { super(); throw TypeError; } }); 17 registry.define('constructor-returns-different-element', class extends HTMLElement { constructor() { super(); return document.createElement('span'); } }); 18 assert_equals(document.createElement('constructor-throws-exception', {customElementRegistry: registry}).customElementRegistry, registry); 19 assert_equals(document.createElement('constructor-returns-different-element', {customElementRegistry: registry}).customElementRegistry, registry); 20 }, 'customElementRegistry on a failed custom element created by calling createElement on CustomElementRegistry should return the registry'); 21 22 test(() => { 23 const registry = new CustomElementRegistry; 24 registry.define('constructor-throws-exception', class extends HTMLElement { constructor() { super(); throw TypeError; } }); 25 registry.define('constructor-returns-different-element', class extends HTMLElement { constructor() { super(); return document.createElement('span'); } }); 26 const container = document.createElement('div', {customElementRegistry: registry}); 27 container.innerHTML = '<constructor-throws-exception></constructor-throws-exception><constructor-returns-different-element></constructor-returns-different-element>'; 28 assert_equals(container.querySelector('constructor-throws-exception').customElementRegistry, registry); 29 assert_equals(container.querySelector('constructor-returns-different-element').customElementRegistry, registry); 30 }, 'customElementRegistry on a failed custom element created by setting innerHTML should return the associated scoped registry'); 31 32 function insideDeclarativeShadowTreeWithNullRegistry(test, script, markup, check) { 33 const frame = document.body.appendChild(document.createElement('iframe')); 34 test.add_cleanup(() => frame.remove()); 35 36 frame.contentDocument.open(); 37 frame.contentDocument.write(`<!DOCTYPE html><html><body><div id="host"><template shadowrootmode="open" shadowrootcustomelementregistry><script>` 38 + script + `</` + 'script>' + markup + '</template></div></body></html>'); 39 frame.contentDocument.close(); 40 check(frame.contentDocument, frame.contentWindow); 41 } 42 43 test((t) => { 44 insideDeclarativeShadowTreeWithNullRegistry(t, ` 45 window.registry = new CustomElementRegistry; 46 registry.initialize(host.shadowRoot); 47 registry.define('constructor-throws-exception', class extends HTMLElement { constructor() { super(); throw TypeError; } }); 48 registry.define('constructor-returns-different-element', class extends HTMLElement { constructor() { super(); return document.createElement('span'); } });`, 49 '<constructor-throws-exception></constructor-throws-exception><constructor-returns-different-element></constructor-returns-different-element>', 50 (doc, win) => { 51 assert_equals(win.host.shadowRoot.querySelector('constructor-throws-exception').customElementRegistry, win.registry); 52 assert_equals(win.host.shadowRoot.querySelector('constructor-returns-different-element').customElementRegistry, win.registry); 53 }); 54 }, 'customElementRegistry on a failed custom element created by parser should return the specified custom regsitry'); 55 56 </script> 57 </body> 58 </html>