summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webidl/ecmascript-binding/class-string-interface.any.js
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/class-string-interface.any.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.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/class-string-interface.any.js')
-rw-r--r--testing/web-platform/tests/webidl/ecmascript-binding/class-string-interface.any.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webidl/ecmascript-binding/class-string-interface.any.js b/testing/web-platform/tests/webidl/ecmascript-binding/class-string-interface.any.js
new file mode 100644
index 0000000000..ee792d5368
--- /dev/null
+++ b/testing/web-platform/tests/webidl/ecmascript-binding/class-string-interface.any.js
@@ -0,0 +1,62 @@
+"use strict";
+
+test(() => {
+ assert_own_property(Blob.prototype, Symbol.toStringTag);
+
+ const propDesc = Object.getOwnPropertyDescriptor(Blob.prototype, Symbol.toStringTag);
+ assert_equals(propDesc.value, "Blob", "value");
+ assert_equals(propDesc.configurable, true, "configurable");
+ assert_equals(propDesc.enumerable, false, "enumerable");
+ assert_equals(propDesc.writable, false, "writable");
+}, "@@toStringTag exists on the prototype with the appropriate descriptor");
+
+test(() => {
+ assert_not_own_property(new Blob(), Symbol.toStringTag);
+}, "@@toStringTag must not exist on the instance");
+
+test(() => {
+ assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Blob]");
+}, "Object.prototype.toString applied to the prototype");
+
+test(() => {
+ assert_equals(Object.prototype.toString.call(new Blob()), "[object Blob]");
+}, "Object.prototype.toString applied to an instance");
+
+test(t => {
+ assert_own_property(Blob.prototype, Symbol.toStringTag, "Precondition for this test: @@toStringTag on the prototype");
+
+ t.add_cleanup(() => {
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "Blob" });
+ });
+
+ Object.defineProperty(Blob.prototype, Symbol.toStringTag, { value: "NotABlob" });
+ assert_equals(Object.prototype.toString.call(Blob.prototype), "[object NotABlob]", "prototype");
+ assert_equals(Object.prototype.toString.call(new Blob()), "[object NotABlob]", "instance");
+}, "Object.prototype.toString applied after modifying the prototype's @@toStringTag");
+
+test(t => {
+ const instance = new Blob();
+ assert_not_own_property(instance, Symbol.toStringTag, "Precondition for this test: no @@toStringTag on the instance");
+
+ Object.defineProperty(instance, Symbol.toStringTag, { value: "NotABlob" });
+ assert_equals(Object.prototype.toString.call(instance), "[object NotABlob]");
+}, "Object.prototype.toString applied to the instance after modifying the instance's @@toStringTag");
+
+// Chrome had a bug (https://bugs.chromium.org/p/chromium/issues/detail?id=793406) where if there
+// was no @@toStringTag in the prototype, it would fall back to a magic class string. This tests
+// that the bug is fixed.
+
+test(() => {
+ const instance = new Blob();
+ Object.setPrototypeOf(instance, null);
+
+ assert_equals(Object.prototype.toString.call(instance), "[object Object]");
+}, "Object.prototype.toString applied to a null-prototype instance");
+
+// This test must be last.
+test(() => {
+ delete Blob.prototype[Symbol.toStringTag];
+
+ assert_equals(Object.prototype.toString.call(Blob.prototype), "[object Object]", "prototype");
+ assert_equals(Object.prototype.toString.call(new Blob()), "[object Object]", "instance");
+}, "Object.prototype.toString applied after deleting @@toStringTag");