mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
Tests/LibWeb: Import WPT test for IDL handling of attribute setters
This commit is contained in:
committed by
Jelle Raaijmakers
parent
435f0634ea
commit
02e5e419d9
Notes:
github-actions[bot]
2026-02-06 18:25:27 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/02e5e419d93 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7699 Reviewed-by: https://github.com/gmta ✅
@@ -0,0 +1,176 @@
|
||||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title>Setter should treat no arguments as undefined</title>
|
||||
<script src="../../resources/testharness.js"></script>
|
||||
<script src="../../resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
const invalidThisValues = [undefined, null, 1, {}, new Image()];
|
||||
|
||||
// String attribute.
|
||||
|
||||
test(() => {
|
||||
const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
|
||||
|
||||
for (const thisValue of invalidThisValues) {
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue); });
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue, undefined); });
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue, "foo"); });
|
||||
}
|
||||
}, `String attribute setter should throw if this value is invalid`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Animation();
|
||||
const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
|
||||
|
||||
assert_equals(thisValue.id, "");
|
||||
|
||||
setter.call(thisValue);
|
||||
assert_equals(thisValue.id, "undefined",
|
||||
"undefined value should be stringified");
|
||||
}, `String attribute setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Animation();
|
||||
const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
|
||||
|
||||
assert_equals(thisValue.id, "");
|
||||
|
||||
setter.call(thisValue, undefined);
|
||||
assert_equals(thisValue.id, "undefined",
|
||||
"undefined value should be stringified");
|
||||
}, `String attribute setter called with undefined should behave in the same way as no arguments`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Animation();
|
||||
const setter = Object.getOwnPropertyDescriptor(Animation.prototype, "id").set;
|
||||
|
||||
assert_equals(thisValue.id, "");
|
||||
|
||||
setter.call(thisValue, "foo");
|
||||
assert_equals(thisValue.id, "foo");
|
||||
}, `String attribute setter called with string should just work`);
|
||||
|
||||
// Object attribute.
|
||||
|
||||
test(() => {
|
||||
const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
|
||||
|
||||
for (const thisValue of invalidThisValues) {
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue); });
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue, undefined); });
|
||||
assert_throws_js(TypeError, () => { setter.call(thisValue, "foo"); });
|
||||
}
|
||||
}, `Object attribute setter should throw if this value is invalid`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Document();
|
||||
const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
|
||||
|
||||
assert_throws_dom("HierarchyRequestError", () => { setter.call(thisValue); });
|
||||
}, `Object attribute setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Document();
|
||||
const setter = Object.getOwnPropertyDescriptor(Document.prototype, "body").set;
|
||||
|
||||
assert_throws_dom("HierarchyRequestError", () => { setter.call(thisValue, undefined); });
|
||||
}, `Object attribute setter called with undefined should behave in the same way as no arguments`);
|
||||
|
||||
// [Replaceable] attribute.
|
||||
|
||||
test(() => {
|
||||
const thisValue = window;
|
||||
const setter = Object.getOwnPropertyDescriptor(window, "scrollX").set;
|
||||
|
||||
setter.call(thisValue);
|
||||
assert_equals(thisValue.scrollX, undefined);
|
||||
}, `[Replaceable] setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = window;
|
||||
const setter = Object.getOwnPropertyDescriptor(window, "screenLeft").set;
|
||||
|
||||
setter.call(thisValue, undefined);
|
||||
assert_equals(thisValue.screenLeft, undefined);
|
||||
}, `[Replaceable] setter called with undefined should behave in the same way as no arguments`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = window;
|
||||
const setter = Object.getOwnPropertyDescriptor(window, "screenTop").set;
|
||||
|
||||
setter.call(thisValue, "foo");
|
||||
assert_equals(thisValue.screenTop, "foo");
|
||||
}, `[Replaceable] setter called with other value should just work`);
|
||||
|
||||
// [LegacyLenientThis] attribute.
|
||||
|
||||
test(() => {
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
|
||||
|
||||
for (const thisValue of invalidThisValues) {
|
||||
setter.call(thisValue);
|
||||
setter.call(thisValue, undefined);
|
||||
setter.call(thisValue, "foo");
|
||||
}
|
||||
}, `[LegacyLenientThis] setter should not throw even if this value is invalid, regardless of the arguments count`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = document.createElement("div");
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
|
||||
|
||||
setter.call(thisValue);
|
||||
assert_equals(thisValue.onmouseenter, null);
|
||||
}, `[LegacyLenientThis] setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = document.createElement("div");
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onmouseenter").set;
|
||||
|
||||
setter.call(thisValue, undefined);
|
||||
assert_equals(thisValue.onmouseenter, null);
|
||||
}, `[LegacyLenientThis] setter called with undefined should behave in the same way as no arguments`);
|
||||
|
||||
// [LegacyLenientSetter] attribute.
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Document();
|
||||
const setter = Object.getOwnPropertyDescriptor(Document.prototype, "fullscreenEnabled").set;
|
||||
|
||||
setter.call(thisValue);
|
||||
assert_equals(thisValue.fullscreenEnabled, false);
|
||||
}, `[LegacyLenientSetter] setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = new Document();
|
||||
const setter = Object.getOwnPropertyDescriptor(Document.prototype, "fullscreenEnabled").set;
|
||||
|
||||
setter.call(thisValue, undefined);
|
||||
assert_equals(thisValue.fullscreenEnabled, false);
|
||||
}, `[LegacyLenientSetter] setter called with undefined should behave in the same way as no arguments`);
|
||||
|
||||
// [PutForward] attribute.
|
||||
|
||||
test(() => {
|
||||
const thisValue = document.createElement("a");
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLAnchorElement.prototype, "relList").set;
|
||||
|
||||
assert_equals(thisValue.relList.length, 0);
|
||||
|
||||
setter.call(thisValue);
|
||||
assert_equals(thisValue.relList.length, 1);
|
||||
assert_equals(thisValue.relList[0], "undefined");
|
||||
}, `[PutForward] setter should treat no arguments as undefined`);
|
||||
|
||||
test(() => {
|
||||
const thisValue = document.createElement("a");
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLAnchorElement.prototype, "relList").set;
|
||||
|
||||
assert_equals(thisValue.relList.length, 0);
|
||||
|
||||
setter.call(thisValue, undefined);
|
||||
|
||||
assert_equals(thisValue.relList.length, 1);
|
||||
assert_equals(thisValue.relList[0], "undefined");
|
||||
}, `[PutForward] setter called with undefined should behave in the same way as no arguments`);
|
||||
</script>
|
||||
Reference in New Issue
Block a user