| 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/testharness-helpers.js"></script> | 6 <script src="../../resources/testharness-helpers.js"></script> |
| 7 <script src="../../resources/testharnessreport.js"></script> | 7 <script src="../../resources/testharnessreport.js"></script> |
| 8 <script src="resources/custom-elements-helpers.js"></script> | 8 <script src="resources/custom-elements-helpers.js"></script> |
| 9 <body> | 9 <body> |
| 10 <script> | 10 <script> |
| 11 // TODO(dominicc): Merge these tests with | 11 // TODO(dominicc): Merge these tests with |
| 12 // https://github.com/w3c/web-platform-tests/pull/2940 | 12 // https://github.com/w3c/web-platform-tests/pull/2940 |
| 13 | 13 |
| 14 'use strict'; | 14 'use strict'; |
| 15 | 15 |
| 16 test_with_window((w) => { | 16 test_with_window((w) => { |
| 17 assert_throws(TypeError.prototype, () => { | 17 assert_throws(TypeError.prototype, () => { |
| 18 w.customElements.define('a-a', 42); | 18 w.customElements.define('a-a', 42); |
| 19 }, 'defining a non-constructor should throw a TypeError'); | 19 }, 'defining a number "constructor" should throw a TypeError'); |
| 20 assert_throws(TypeError.prototype, () => { |
| 21 w.customElements.define('a-a', () => {}); |
| 22 }, 'defining an arrow function "constructor" should throw a TypeError'); |
| 23 assert_throws(TypeError.prototype, () => { |
| 24 w.customElements.define('a-a', { m() {} }.m); |
| 25 }, 'defining a concise method "constructor" should throw a TypeError'); |
| 20 }, 'A "constructor" that is not a constructor'); | 26 }, 'A "constructor" that is not a constructor'); |
| 21 | 27 |
| 22 test_with_window((w) => { | 28 test_with_window((w) => { |
| 23 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-
name | 29 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-element-
name |
| 24 let invalid_names = [ | 30 let invalid_names = [ |
| 25 'annotation-xml', | 31 'annotation-xml', |
| 26 'color-profile', | 32 'color-profile', |
| 27 'font-face', | 33 'font-face', |
| 28 'font-face-src', | 34 'font-face-src', |
| 29 'font-face-uri', | 35 'font-face-uri', |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 function F() {} | 77 function F() {} |
| 72 F.prototype = 42; | 78 F.prototype = 42; |
| 73 assert_throws(TypeError.prototype, () => { | 79 assert_throws(TypeError.prototype, () => { |
| 74 w.customElements.define('a-a', F); | 80 w.customElements.define('a-a', F); |
| 75 }, 'defining an element with a constructor with a prototype that is not an ' + | 81 }, 'defining an element with a constructor with a prototype that is not an ' + |
| 76 'object should throw a TypeError'); | 82 'object should throw a TypeError'); |
| 77 }, 'Retrieved prototype is a non-object'); | 83 }, 'Retrieved prototype is a non-object'); |
| 78 | 84 |
| 79 test_with_window((w) => { | 85 test_with_window((w) => { |
| 80 assert_throws(TypeError.prototype, () => { | 86 assert_throws(TypeError.prototype, () => { |
| 81 let not_a_constructor = new Object(); | 87 let not_a_constructor = () => {}; |
| 82 let invalid_name = 'annotation-xml'; | 88 let invalid_name = 'annotation-xml'; |
| 83 // TODO(dominicc): When V8 supports IsConstructor, replace this with a | |
| 84 // function. | |
| 85 w.customElements.define(invalid_name, not_a_constructor); | 89 w.customElements.define(invalid_name, not_a_constructor); |
| 86 }, 'Defining an element with an invalid name and invalid constructor ' + | 90 }, 'Defining an element with an invalid name and invalid constructor ' + |
| 87 'should throw a TypeError for the constructor and not a SyntaxError'); | 91 'should throw a TypeError for the constructor and not a SyntaxError'); |
| 88 | 92 |
| 89 class C extends w.HTMLElement {} | 93 class C extends w.HTMLElement {} |
| 90 w.customElements.define('a-a', C); | 94 w.customElements.define('a-a', C); |
| 91 assert_throws('SYNTAX_ERR', () => { | 95 assert_throws('SYNTAX_ERR', () => { |
| 92 let invalid_name = 'annotation-xml'; | 96 let invalid_name = 'annotation-xml'; |
| 93 let reused_constructor = C; | 97 let reused_constructor = C; |
| 94 w.customElements.define(invalid_name, reused_constructor); | 98 w.customElements.define(invalid_name, reused_constructor); |
| 95 }, 'Defining an element with an invalid name and a reused constructor ' + | 99 }, 'Defining an element with an invalid name and a reused constructor ' + |
| 96 'should throw a SyntaxError for the name and not a NotSupportedError'); | 100 'should throw a SyntaxError for the name and not a NotSupportedError'); |
| 97 }, 'Order of checks'); | 101 }, 'Order of checks'); |
| 98 </script> | 102 </script> |
| OLD | NEW |