summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object')
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/DefineOwnProperty.html89
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/GetOwnProperty.html84
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/OwnPropertyKeys.html65
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/Set.html79
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/helper.js22
5 files changed, 339 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/DefineOwnProperty.html b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/DefineOwnProperty.html
new file mode 100644
index 0000000000..ad32f6f89f
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/DefineOwnProperty.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Legacy platform objects [[DefineOwnProperty]] method</title>
+<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-defineownproperty">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./helper.js"></script>
+<script>
+
+test(function() {
+ let span = document.createElement("span");
+ span.className = "foo";
+ // DOMTokenList supports an indexed property getter but not a setter.
+ let domTokenList = span.classList;
+ // Confirm the test settings.
+ assert_equals(domTokenList.length, 1);
+ assert_prop_desc_equals(domTokenList, "0",
+ {value: "foo", writable: false, enumerable: true,
+ configurable: true});
+ assert_prop_desc_equals(domTokenList, "1", undefined);
+ // Actual test
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "0", {value: true, writable: true}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "1", {value: true, writable: true}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "0", {get: () => {}}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "0", {set: () => {}}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "1", {get: () => {}}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(domTokenList, "1", {set: () => {}}));
+ assert_equals(domTokenList[0], "foo");
+ assert_equals(domTokenList[1], undefined);
+ domTokenList[0] = "bar";
+ domTokenList[1] = "bar";
+ assert_equals(domTokenList[0], "foo");
+ assert_equals(domTokenList[1], undefined);
+ assert_throws_js(TypeError, () => {
+ "use strict";
+ domTokenList[0] = "bar";
+ });
+ assert_throws_js(TypeError, () => {
+ "use strict";
+ domTokenList[1] = "bar";
+ });
+ // Nothing must change after all.
+ assert_equals(domTokenList.length, 1);
+ assert_prop_desc_equals(domTokenList, "0",
+ {value: "foo", writable: false, enumerable: true,
+ configurable: true});
+ assert_prop_desc_equals(domTokenList, "1", undefined);
+}, "Test [[DefineOwnProperty]] with no indexed property setter support.");
+
+test(function() {
+ // HTMLSelectElement supports an indexed property setter.
+ let select = document.createElement("select");
+ let option0 = document.createElement("option");
+ let option1 = document.createElement("option");
+ // Confirm the test settings.
+ assert_equals(select.length, 0);
+ assert_prop_desc_equals(select, "0", undefined);
+ // Try to define an accessor property with non supported property index.
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(select, "0", {get: () => {}}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(select, "0", {set: () => {}}));
+ assert_prop_desc_equals(select, "0", undefined);
+ // writable, enumerable, configurable will be ignored.
+ Object.defineProperty(select, "0", {value: option0, writable: false,
+ enumerable: false, configurable: false});
+ assert_prop_desc_equals(select, "0",
+ {value: option0, writable: true, enumerable: true,
+ configurable: true});
+ select[1] = option1;
+ assert_prop_desc_equals(select, "1",
+ {value: option1, writable: true, enumerable: true,
+ configurable: true});
+ // Try to define an accessor property with a supported property index.
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(select, "0", {get: () => {}}));
+ assert_throws_js(TypeError, () =>
+ Object.defineProperty(select, "0", {set: () => {}}));
+ assert_prop_desc_equals(select, "0",
+ {value: option0, writable: true, enumerable: true,
+ configurable: true});
+}, "Test [[DefineOwnProperty]] with indexed property setter support.");
+</script>
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/GetOwnProperty.html b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/GetOwnProperty.html
new file mode 100644
index 0000000000..be3bcc61f0
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/GetOwnProperty.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Legacy platform objects [[GetOwnProperty]] method</title>
+<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-getownproperty">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="./helper.js"></script>
+<script>
+
+test(function() {
+ // DOMTokenList has an indexed property getter, no indexed property setter
+ // and no named property handlers.
+ let div = document.createElement("div");
+ div.classList.add("baz", "quux");
+ const domTokenList = div.classList;
+ assert_prop_desc_equals(
+ domTokenList, "1",
+ {value: "quux", writable: false, enumerable: true, configurable: true},
+ "[[GetOwnProperty]] for indexed properties returns the right descriptor");
+ assert_prop_desc_equals(
+ domTokenList, "42", undefined,
+ "[[GetOwnProperty]] with invalid index returns undefined");
+ assert_array_equals(Object.keys(domTokenList), ["0", "1"]);
+ assert_array_equals(Object.values(domTokenList), ["baz", "quux"]);
+
+ // getElementsByTagName() returns an HTMLCollection.
+ // HTMLCollection has indexed and named property getters, no setters. Its IDL
+ // interface declaration has [LegacyUnenumerableNamedProperties] so its named
+ // properties are not enumerable.
+ let span1 = document.createElement("span");
+ span1.id = "foo";
+ let span2 = document.createElement("span");
+ span2.id = "bar";
+ document.head.appendChild(span1);
+ document.head.appendChild(span2);
+ const elementList = document.getElementsByTagName("span");
+ assert_prop_desc_equals(
+ elementList, "foo",
+ {value: span1, writable: false, enumerable: false, configurable: true},
+ "[[GetOwnProperty]] for named properties returns the right descriptor");
+ assert_prop_desc_equals(
+ elementList, "1",
+ {value: span2, writable: false, enumerable: true, configurable: true},
+ "[[GetOwnProperty]] for indexed properties returns the right descriptor");
+ assert_prop_desc_equals(
+ elementList, "unknown", undefined,
+ "[[GetOwnProperty]] with invalid property name returns undefined");
+ assert_array_equals(Object.keys(elementList), ["0", "1"]);
+ assert_array_equals(Object.values(elementList), [span1, span2]);
+}, "[[GetOwnProperty]] with getters and no setters");
+
+test(function() {
+ // DOMStringMap supports named property getters and setters, but not indexed
+ // properties.
+ let span = document.createElement("span");
+ span.dataset.foo = "bar";
+ assert_prop_desc_equals(
+ span.dataset, "foo",
+ {value: "bar", writable: true, enumerable: true, configurable: true},
+ "[[GetOwnProperty]] for named properties returns the right descriptor");
+ assert_prop_desc_equals(
+ span.dataset, "unknown", undefined,
+ "[[GetOwnProperty]] with invalid property name returns undefined");
+ assert_array_equals(Object.keys(span.dataset), ["foo"]);
+ assert_array_equals(Object.values(span.dataset), ["bar"]);
+}, "[[GetOwnProperty]] with named property getters and setters");
+
+test(function() {
+ // HTMLSelectElement has indexed property getters and setters, but no support
+ // for named properties.
+ let selectElement = document.createElement("select");
+ assert_prop_desc_equals(
+ selectElement, "0", undefined,
+ "[[GetOwnProperty]] with invalid property index returns undefined");
+ let optionElement = document.createElement("option");
+ selectElement.appendChild(optionElement);
+ assert_prop_desc_equals(
+ selectElement, "0",
+ {value: optionElement, writable: true, enumerable: true, configurable: true},
+ "[[GetOwnProperty]] for indexed properties returns the right descriptor");
+ assert_array_equals(Object.keys(selectElement), ["0"]);
+ assert_array_equals(Object.values(selectElement), [optionElement]);
+}, "[[GetOwnProperty]] with indexed property getters and setters");
+</script>
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/OwnPropertyKeys.html b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/OwnPropertyKeys.html
new file mode 100644
index 0000000000..d33980517b
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/OwnPropertyKeys.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Legacy platform objects [[OwnPropertyKeys]] method</title>
+<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-ownpropertykeys">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ function custom_assert_array_equals(actual, expected, msg) {
+ function replacer(k, v) {
+ if (typeof v === "symbol") {
+ return v.toString();
+ }
+ return v;
+ }
+ assert_array_equals(actual, expected, " actual " + JSON.stringify(actual, replacer) + " expected " + JSON.stringify(expected, replacer));
+ }
+
+ test(function() {
+ var element = document.createElement("div");
+ element.appendChild(document.createElement("div"));
+ element.appendChild(document.createElement("div"));
+ element.appendChild(document.createElement("div"));
+ custom_assert_array_equals(Reflect.ownKeys(element.childNodes), ["0", "1", "2"]);
+ }, "must enumerate property indices in ascending numerical order");
+
+ test(function() {
+ var element = document.createElement("div");
+ element.setAttribute("data-foo", "foo content");
+ element.setAttribute("data-bar", "bar content");
+ element.setAttribute("data-baz", "baz content");
+ custom_assert_array_equals(Reflect.ownKeys(element.dataset), ["foo", "bar", "baz"]);
+ }, "must enumerate property names in list order");
+
+
+ test(function() {
+ var element = document.createElement("div");
+ element.setAttribute("id", "foo");
+ element.setAttribute("class", "bar");
+ custom_assert_array_equals(Reflect.ownKeys(element.attributes), ["0", "1", "id", "class"]);
+ }, "must first enumerate property indices in ascending numerical order, then named properties in list order");
+
+
+ test(function() {
+ var element = document.createElement("div");
+ element.attributes.foo = "some value";
+ element.attributes.bar = "and another";
+ element.setAttribute("id", "foo");
+ element.setAttribute("class", "bar");
+ custom_assert_array_equals(Reflect.ownKeys(element.attributes), ["0", "1", "id", "class", "foo", "bar"]);
+ }, "must enumerate own properties after indexed and named properties even when they're added first");
+
+ test(function() {
+ var symb1 = Symbol();
+ var symb2 = Symbol();
+ var element = document.createElement("div");
+ element.attributes.foo = "some value";
+ element.attributes[symb1] = "symb1";
+ element.attributes[symb2] = "symb2";
+ element.attributes.bar = "and another";
+ element.setAttribute("id", "foo");
+ element.setAttribute("class", "bar");
+ custom_assert_array_equals(Reflect.ownKeys(element.attributes),
+ ["0", "1", "id", "class", "foo", "bar", symb1, symb2]);
+ }, "must enumerate symbols after strings, regardless of which ones got added first");
+</script>
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/Set.html b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/Set.html
new file mode 100644
index 0000000000..3134c81859
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/Set.html
@@ -0,0 +1,79 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Legacy platform objects [[Set]] method</title>
+<link rel="help" href="https://webidl.spec.whatwg.org/#legacy-platform-object-set">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+ test(function() {
+ var element = document.createElement("div");
+ element.appendChild(document.createElement("div"));
+ element.childNodes["5"] = "foo";
+ assert_equals(element.childNodes["5"], undefined);
+ }, "must not set the property value when assigning to a numeric property on an object which implements an indexed property getter but not a setter when not in strict mode");
+
+ test(function() {
+ "use strict";
+ var element = document.createElement("div");
+ element.appendChild(document.createElement("div"));
+ assert_throws_js(TypeError, function() { element.childNodes["5"] = "foo"; });
+ }, "must throw when assigning to a numeric property on an object which implements a indexed property getter but not a setter in strict mode");
+
+ test(function() {
+ var element = document.createElement("div");
+ element.attributes.foo = "foo";
+ assert_equals(element.attributes.foo, "foo");
+ }, "must allow assigning to a named property on an object which implements a named property getter but not a setter when not in strict mode");
+
+ test(function() {
+ "use strict";
+ var element = document.createElement("div");
+ element.attributes.foo = "foo";
+ assert_equals(element.attributes.foo, "foo");
+ }, "must allow assigning to a named property on an object which implements a named property getter but not a setter in strict mode");
+
+ var symbol = Symbol();
+
+ test(function() {
+ var element = document.createElement("div");
+ element.appendChild(document.createElement("div"));
+ element.childNodes[symbol] = "foo";
+ assert_equals(element.childNodes[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements an indexed property getter but not a setter when not in strict mode");
+
+ test(function() {
+ "use strict";
+ var element = document.createElement("div");
+ element.appendChild(document.createElement("div"));
+ element.childNodes[symbol] = "foo";
+ assert_equals(element.childNodes[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements an indexed property getter but not a setter in strict mode");
+
+ test(function() {
+ var element = document.createElement("div");
+ element.attributes[symbol] = "foo";
+ assert_equals(element.attributes[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements indexed and named property getters but no setters when not in strict mode");
+
+ test(function() {
+ "use strict";
+ var element = document.createElement("div");
+ element.attributes[symbol] = "foo";
+ assert_equals(element.attributes[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements indexed and named property getters but no setters in strict mode");
+
+ test(function() {
+ sessionStorage.clear();
+ this.add_cleanup(function() { sessionStorage.clear(); });
+ sessionStorage[symbol] = "foo";
+ assert_equals(sessionStorage[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements indexed and named property getters and setters when not in strict mode");
+
+ test(function() {
+ "use strict";
+ sessionStorage.clear();
+ this.add_cleanup(function() { sessionStorage.clear(); });
+ sessionStorage[symbol] = "foo";
+ assert_equals(sessionStorage[symbol], "foo");
+ }, "must allow assigning to a symbol property on an object which implements indexed and named property getters and setters in strict mode");
+</script>
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/helper.js b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/helper.js
new file mode 100644
index 0000000000..01c1d00694
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/legacy-platform-object/helper.js
@@ -0,0 +1,22 @@
+function assert_prop_desc_equals(object, property_key, expected) {
+ let actual = Object.getOwnPropertyDescriptor(object, property_key);
+ if (expected === undefined) {
+ assert_equals(
+ actual, undefined,
+ "(assert_prop_desc_equals: no property descriptor expected)");
+ return;
+ }
+ for (p in actual) {
+ assert_true(
+ expected.hasOwnProperty(p),
+ "(assert_prop_desc_equals: property '" + p + "' is not expected)");
+ assert_equals(
+ actual[p], expected[p],
+ "(assert_prop_desc_equals: property '" + p + "')");
+ }
+ for (p in expected) {
+ assert_true(
+ actual.hasOwnProperty(p),
+ "(assert_prop_desc_equals: expected property '" + p + "' missing)");
+ }
+}