| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: defineElement</title> | 2 <title>Custom Elements: defineElement</title> |
| 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus
tomelementsregistry"> | 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#cus
tomelementsregistry"> |
| 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> | 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="resources/custom-elements-helpers.js"></script> | 7 <script src="resources/custom-elements-helpers.js"></script> |
| 8 <body> | 8 <body> |
| 9 <script> | 9 <script> |
| 10 // TODO(dominicc): Merge these tests with | 10 // TODO(dominicc): Merge these tests with |
| 11 // https://github.com/w3c/web-platform-tests/pull/2940 | 11 // https://github.com/w3c/web-platform-tests/pull/2940 |
| 12 | 12 |
| 13 'use strict'; | 13 'use strict'; |
| 14 | 14 |
| 15 function assert_throws_dom_exception(global_context, code, func, description) { | |
| 16 let exception; | |
| 17 assert_throws(code, () => { | |
| 18 try { | |
| 19 func.call(this); | |
| 20 } catch(e) { | |
| 21 exception = e; | |
| 22 throw e; | |
| 23 } | |
| 24 }, description); | |
| 25 assert_true(exception instanceof global_context.DOMException, 'DOMException on
the appropriate window'); | |
| 26 } | |
| 27 | |
| 28 test_with_window((w) => { | 15 test_with_window((w) => { |
| 29 assert_throws(TypeError.prototype, () => { | 16 assert_throws(TypeError.prototype, () => { |
| 30 w.customElements.define('a-a', 42); | 17 w.customElements.define('a-a', 42); |
| 31 }, 'defining a number "constructor" should throw a TypeError'); | 18 }, 'defining a number "constructor" should throw a TypeError'); |
| 32 assert_throws(TypeError.prototype, () => { | 19 assert_throws(TypeError.prototype, () => { |
| 33 w.customElements.define('a-a', () => {}); | 20 w.customElements.define('a-a', () => {}); |
| 34 }, 'defining an arrow function "constructor" should throw a TypeError'); | 21 }, 'defining an arrow function "constructor" should throw a TypeError'); |
| 35 assert_throws(TypeError.prototype, () => { | 22 assert_throws(TypeError.prototype, () => { |
| 36 w.customElements.define('a-a', { m() {} }.m); | 23 w.customElements.define('a-a', { m() {} }.m); |
| 37 }, 'defining a concise method "constructor" should throw a TypeError'); | 24 }, 'defining a concise method "constructor" should throw a TypeError'); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // step 2 | 325 // step 2 |
| 339 test_with_window((w) => { | 326 test_with_window((w) => { |
| 340 let invalid_name = 'annotation-xml'; | 327 let invalid_name = 'annotation-xml'; |
| 341 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => { | 328 assert_throws_dom_exception(w, 'SYNTAX_ERR', () => { |
| 342 w.customElements.define(invalid_name, class extends HTMLElement {}); | 329 w.customElements.define(invalid_name, class extends HTMLElement {}); |
| 343 }, 'defining author-defined custom element constructor' + | 330 }, 'defining author-defined custom element constructor' + |
| 344 'should pass this step without throwing TypeError'); | 331 'should pass this step without throwing TypeError'); |
| 345 }, 'Invalid constructor'); | 332 }, 'Invalid constructor'); |
| 346 </script> | 333 </script> |
| 347 </body> | 334 </body> |
| OLD | NEW |