OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Custom Elements: [HTMLConstructor] derives prototype from NewTarget</titl
e> | 2 <title>Custom Elements: [HTMLConstructor] derives prototype from NewTarget</titl
e> |
3 <meta name="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | 3 <meta name="author" title="Domenic Denicola" href="mailto:d@domenic.me"> |
4 <meta name="help" content="https://html.spec.whatwg.org/multipage/dom.html#htmlc
onstructor"> | 4 <meta name="help" content="https://html.spec.whatwg.org/multipage/dom.html#htmlc
onstructor"> |
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 "use strict"; | 10 "use strict"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }); | 94 }); |
95 | 95 |
96 [null, undefined, 5, "string"].forEach(function (notAnObject) { | 96 [null, undefined, 5, "string"].forEach(function (notAnObject) { |
97 test_with_window(w => { | 97 test_with_window(w => { |
98 // We have to return an object during define(), but not during super() | 98 // We have to return an object during define(), but not during super() |
99 let returnNotAnObject = false; | 99 let returnNotAnObject = false; |
100 | 100 |
101 function TestElement() { | 101 function TestElement() { |
102 const o = Reflect.construct(w.HTMLParagraphElement, [], new.target); | 102 const o = Reflect.construct(w.HTMLParagraphElement, [], new.target); |
103 | 103 |
104 assert_equals(Object.getPrototypeOf(o), window.HTMLParagraphElement, | 104 assert_equals(Object.getPrototypeOf(o), window.HTMLParagraphElement.protot
ype, |
105 "Must use the HTMLParagraphElement from the realm of NewTarget"); | 105 "Must use the HTMLParagraphElement from the realm of NewTarget"); |
106 assert_not_equals(Object.getPrototypeOf(o), w.HTMLParagraphElement, | 106 assert_not_equals(Object.getPrototypeOf(o), w.HTMLParagraphElement.prototy
pe, |
107 "Must not use the HTMLParagraphElement from the realm of the active func
tion object (w.HTMLParagraphElement)"); | 107 "Must not use the HTMLParagraphElement from the realm of the active func
tion object (w.HTMLParagraphElement)"); |
108 | 108 |
109 return o; | 109 return o; |
110 } | 110 } |
111 | 111 |
112 const ElementWithDynamicPrototype = new Proxy(TestElement, { | 112 const ElementWithDynamicPrototype = new Proxy(TestElement, { |
113 get: function (target, name) { | 113 get: function (target, name) { |
114 if (name == "prototype") | 114 if (name == "prototype") |
115 return returnNotAnObject ? notAnObject : {}; | 115 return returnNotAnObject ? notAnObject : {}; |
116 return target[name]; | 116 return target[name]; |
117 } | 117 } |
118 }); | 118 }); |
119 | 119 |
120 w.customElements.define("test-element", ElementWithDynamicPrototype, { exten
ds: "p" }); | 120 w.customElements.define("test-element", ElementWithDynamicPrototype, { exten
ds: "p" }); |
121 | 121 |
122 returnNotAnObject = true; | 122 returnNotAnObject = true; |
123 new ElementWithDynamicPrototype(); | 123 new ElementWithDynamicPrototype(); |
124 }, "If prototype is not object (" + notAnObject + "), derives the fallback fro
m NewTarget's realm (customized built-in elements)"); | 124 }, "If prototype is not object (" + notAnObject + "), derives the fallback fro
m NewTarget's realm (customized built-in elements)"); |
125 }); | 125 }); |
126 | 126 |
127 </script> | 127 </script> |
128 </body> | 128 </body> |
OLD | NEW |