mirror of
https://github.com/servo/servo.git
synced 2025-08-17 19:35:33 +01:00
Update web-platform-tests to revision dc5cbf088edcdb266541d4e5a76149a2c6e716a0
This commit is contained in:
parent
1d40075f03
commit
079092dfea
2381 changed files with 90360 additions and 17722 deletions
|
@ -110,7 +110,7 @@
|
|||
}, `Element names: defining an element named ${name} should throw a SyntaxError`);
|
||||
});
|
||||
|
||||
// 3. If this CustomElementsRegistry contains an entry with name name,
|
||||
// 3. If this CustomElementRegistry contains an entry with name name,
|
||||
// then throw a NotSupportedError and abort these steps.
|
||||
test(() => {
|
||||
customElements.define('test-define-dup-name', class {});
|
||||
|
@ -119,7 +119,7 @@
|
|||
});
|
||||
}, 'If the name is already defined, should throw a NotSupportedError');
|
||||
|
||||
// 4. If this CustomElementsRegistry contains an entry with constructor constructor,
|
||||
// 5. If this CustomElementRegistry contains an entry with constructor constructor,
|
||||
// then throw a NotSupportedError and abort these steps.
|
||||
test(() => {
|
||||
class TestDupConstructor {};
|
||||
|
@ -129,7 +129,7 @@
|
|||
});
|
||||
}, 'If the constructor is already defined, should throw a NotSupportedError');
|
||||
|
||||
// 7.1. If extends is a valid custom element name,
|
||||
// 9.1. If extends is a valid custom element name,
|
||||
// then throw a NotSupportedError.
|
||||
validCustomElementNames.forEach(name => {
|
||||
test(() => {
|
||||
|
@ -139,7 +139,7 @@
|
|||
}, `If extends is ${name}, should throw a NotSupportedError`);
|
||||
});
|
||||
|
||||
// 7.2. If the element interface for extends and the HTML namespace is HTMLUnknownElement
|
||||
// 9.2. If the element interface for extends and the HTML namespace is HTMLUnknownElement
|
||||
// (e.g., if extends does not indicate an element definition in this specification),
|
||||
// then throw a NotSupportedError.
|
||||
[
|
||||
|
@ -159,19 +159,7 @@
|
|||
}, `If extends is ${name}, should throw a NotSupportedError`);
|
||||
});
|
||||
|
||||
// 8. Let observedAttributesIterable be Get(constructor, "observedAttributes").
|
||||
// Rethrow any exceptions.
|
||||
test(() => {
|
||||
class C {
|
||||
static get observedAttributes() { throw_rethrown_error(); }
|
||||
attributeChangedCallback() {}
|
||||
}
|
||||
assert_rethrown(() => {
|
||||
customElements.define('test-define-observedattributes-rethrow', C);
|
||||
});
|
||||
}, 'If constructor.observedAttributes throws, should rethrow');
|
||||
|
||||
// 10. Let prototype be Get(constructor, "prototype"). Rethrow any exceptions.
|
||||
// 12.1. Let prototype be Get(constructor, "prototype"). Rethrow any exceptions.
|
||||
function assert_rethrown(func, description) {
|
||||
assert_throws({ name: 'rethrown' }, func, description);
|
||||
}
|
||||
|
@ -190,7 +178,8 @@
|
|||
customElements.define('test-define-constructor-prototype-rethrow', BadConstructor);
|
||||
});
|
||||
}, 'If constructor.prototype throws, should rethrow');
|
||||
// 11. If Type(prototype) is not Object,
|
||||
|
||||
// 12.2. If Type(prototype) is not Object,
|
||||
// then throw a TypeError exception.
|
||||
test(() => {
|
||||
const c = (function () { }).bind({}); // prototype is undefined.
|
||||
|
@ -206,18 +195,18 @@
|
|||
});
|
||||
}, 'If Type(constructor.prototype) is string, should throw a TypeError');
|
||||
|
||||
// 12. Let connectedCallback be Get(prototype, "connectedCallback"). Rethrow any exceptions.
|
||||
// 13. If connectedCallback is not undefined, and IsCallable(connectedCallback) is false,
|
||||
// then throw a TypeError exception.
|
||||
// 14. Let disconnectedCallback be Get(prototype, "disconnectedCallback"). Rethrow any exceptions.
|
||||
// 15. If disconnectedCallback is not undefined, and IsCallable(disconnectedCallback) is false,
|
||||
// then throw a TypeError exception.
|
||||
// 16. Let attributeChangedCallback be Get(prototype, "attributeChangedCallback"). Rethrow any exceptions.
|
||||
// 17. If attributeChangedCallback is not undefined, and IsCallable(attributeChangedCallback) is false,
|
||||
// then throw a TypeError exception.
|
||||
// 12.3. Let lifecycleCallbacks be a map with the four keys "connectedCallback",
|
||||
// "disconnectedCallback", "adoptedCallback", and "attributeChangedCallback",
|
||||
// each of which belongs to an entry whose value is null.
|
||||
// 12.4. For each of the four keys callbackName in lifecycleCallbacks:
|
||||
// 12.4.1. Let callbackValue be Get(prototype, callbackName). Rethrow any exceptions.
|
||||
// 12.4.2. If callbackValue is not undefined, then set the value of the entry in
|
||||
// lifecycleCallbacks with key callbackName to the result of converting callbackValue
|
||||
// to the Web IDL Function callback type. Rethrow any exceptions from the conversion.
|
||||
[
|
||||
'connectedCallback',
|
||||
'disconnectedCallback',
|
||||
'adoptedCallback',
|
||||
'attributeChangedCallback',
|
||||
].forEach(name => {
|
||||
test(() => {
|
|
@ -0,0 +1,124 @@
|
|||
<!DOCTYPE html>
|
||||
<title>Custom Elements: [HTMLConstructor] derives prototype from NewTarget</title>
|
||||
<meta name="author" title="Domenic Denicola" href="mailto:d@domenic.me">
|
||||
<meta name="help" content="https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="../resources/custom-elements-helpers.js"></script>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
test_with_window(w => {
|
||||
let afterDefinition = false;
|
||||
const proto1 = { "proto": "number one" };
|
||||
const proto2 = { "proto": "number two" };
|
||||
|
||||
const TestElement = (function () {
|
||||
assert_throws({ name: "prototype throws" }, () => {
|
||||
const o = Reflect.construct(w.HTMLElement, [], new.target);
|
||||
|
||||
assert_equals(Object.getPrototypeOf(o), proto2,
|
||||
"Must use the value returned from new.target.prototype");
|
||||
assert_not_equals(Object.getPrototypeOf(o), proto1,
|
||||
"Must not use the prototype stored at definition time");
|
||||
});
|
||||
}).bind({});
|
||||
|
||||
Object.defineProperty(TestElement, "prototype", {
|
||||
get() {
|
||||
return beforeDefinition ? proto1 : proto2;
|
||||
}
|
||||
});
|
||||
|
||||
w.customElements.define("test-element", TestElement);
|
||||
|
||||
beforeDefinition = true;
|
||||
new TestElement();
|
||||
|
||||
}, "Use NewTarget's prototype, not the one stored at definition time");
|
||||
|
||||
test_with_window(w => {
|
||||
// We have to not throw during define(), but throw during super()
|
||||
let throws = false;
|
||||
|
||||
const TestElement = (function () {
|
||||
assert_throws({ name: "prototype throws" }, () => {
|
||||
return Reflect.construct(w.HTMLElement, [], new.target);
|
||||
});
|
||||
}).bind({});
|
||||
|
||||
Object.defineProperty(TestElement, "prototype", {
|
||||
get() {
|
||||
if (throws) {
|
||||
throw { name: "prototype throws" };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
});
|
||||
|
||||
w.customElements.define("test-element", TestElement);
|
||||
|
||||
throws = true;
|
||||
new TestElement();
|
||||
|
||||
}, "Rethrow any exceptions thrown while getting the prototype");
|
||||
|
||||
test_with_window(w => {
|
||||
for (const notAnObject of [null, undefined, 5, "string"]) {
|
||||
// We have to return an object during define(), but not during super()
|
||||
let returnNotAnObject = false;
|
||||
|
||||
const TestElement = (function () {
|
||||
const o = Reflect.construct(w.HTMLElement, [], new.target);
|
||||
|
||||
assert_equals(Object.getPrototypeOf(o), window.HTMLElement,
|
||||
"Must use the HTMLElement from the realm of NewTarget");
|
||||
assert_not_equals(Object.getPrototypeOf(o), w.HTMLElement,
|
||||
"Must not use the HTMLElement from the realm of the active function object (w.HTMLElement)");
|
||||
|
||||
return o;
|
||||
}).bind({});
|
||||
|
||||
Object.defineProperty(TestElement, "prototype", {
|
||||
get() {
|
||||
return returnNotAnObject ? notAnObject : {};
|
||||
}
|
||||
});
|
||||
|
||||
w.customElements.define("test-element", TestElement);
|
||||
|
||||
returnNotAnObject = true;
|
||||
new TestElement();
|
||||
}
|
||||
}, "If prototype is not object, derives the fallback from NewTarget's realm (autonomous custom elements)");
|
||||
|
||||
test_with_window(w => {
|
||||
for (const notAnObject of [null, undefined, 5, "string"]) {
|
||||
// We have to return an object during define(), but not during super()
|
||||
let returnNotAnObject = false;
|
||||
|
||||
const TestElement = (function () {
|
||||
const o = Reflect.construct(w.HTMLParagraphElement, [], new.target);
|
||||
|
||||
assert_equals(Object.getPrototypeOf(o), window.HTMLParagraphElement,
|
||||
"Must use the HTMLParagraphElement from the realm of NewTarget");
|
||||
assert_not_equals(Object.getPrototypeOf(o), w.HTMLParagraphElement,
|
||||
"Must not use the HTMLParagraphElement from the realm of the active function object (w.HTMLParagraphElement)");
|
||||
|
||||
return o;
|
||||
}).bind({});
|
||||
|
||||
Object.defineProperty(TestElement, "prototype", {
|
||||
get() {
|
||||
return returnNotAnObject ? notAnObject : {};
|
||||
}
|
||||
});
|
||||
|
||||
w.customElements.define("test-element", TestElement, { extends: "p" });
|
||||
|
||||
returnNotAnObject = true;
|
||||
new TestElement();
|
||||
}
|
||||
}, "If prototype is not object, derives the fallback from NewTarget's realm (customized built-in elements)");
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
function create_window_in_test(t, srcdoc) {
|
||||
let p = new Promise((resolve) => {
|
||||
let f = document.createElement('iframe');
|
||||
f.srcdoc = srcdoc ? srcdoc : '';
|
||||
f.onload = (event) => {
|
||||
let w = f.contentWindow;
|
||||
t.add_cleanup(() => f.parentNode && f.remove());
|
||||
resolve(w);
|
||||
};
|
||||
document.body.appendChild(f);
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
function test_with_window(f, name, srcdoc) {
|
||||
promise_test((t) => {
|
||||
return create_window_in_test(t, srcdoc)
|
||||
.then((w) => {
|
||||
f(w);
|
||||
});
|
||||
}, name);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue