HTMLElement-constructor-customized-builtins.html (2449B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Custom Elements: HTMLElement must allow subclassing</title> 5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org"> 6 <meta name="assert" content="HTMLElement must allow subclassing"> 7 <link rel="help" href="https://html.spec.whatwg.org/#html-element-constructors"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 </head> 11 <body> 12 <div id="log"></div> 13 <script> 14 15 test(function() { 16 class SomeCustomElement extends HTMLElement {}; 17 var getCount = 0; 18 var countingProxy = new Proxy(SomeCustomElement, { 19 get: function(target, prop, receiver) { 20 if (prop == "prototype") { 21 ++getCount; 22 } 23 return Reflect.get(target, prop, receiver); 24 } 25 }); 26 customElements.define("failure-counting-element-1", countingProxy, 27 { extends: "button" }); 28 // define() gets the prototype of the constructor it's passed, so 29 // reset the counter. 30 getCount = 0; 31 assert_throws_js(TypeError, 32 function () { new countingProxy() }, 33 "Should not be able to construct an HTMLElement named 'button'"); 34 assert_equals(getCount, 0, "Should never have gotten .prototype"); 35 }, 'HTMLElement constructor must not get .prototype until it finishes its extends sanity checks, calling proxy constructor directly'); 36 37 test(function() { 38 class SomeCustomElement extends HTMLElement {}; 39 var getCount = 0; 40 var countingProxy = new Proxy(SomeCustomElement, { 41 get: function(target, prop, receiver) { 42 if (prop == "prototype") { 43 ++getCount; 44 } 45 return Reflect.get(target, prop, receiver); 46 } 47 }); 48 customElements.define("failure-counting-element-2", countingProxy, 49 { extends: "button" }); 50 // define() gets the prototype of the constructor it's passed, so 51 // reset the counter. 52 getCount = 0; 53 assert_throws_js(TypeError, 54 function () { Reflect.construct(HTMLElement, [], countingProxy) }, 55 "Should not be able to construct an HTMLElement named 'button'"); 56 assert_equals(getCount, 0, "Should never have gotten .prototype"); 57 }, 'HTMLElement constructor must not get .prototype until it finishes its extends sanity checks, calling via Reflect'); 58 59 </script> 60 </body> 61 </html>