summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js')
-rw-r--r--js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js b/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
new file mode 100644
index 0000000000..c2b1403d30
--- /dev/null
+++ b/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
@@ -0,0 +1,107 @@
+load(libdir + 'asserts.js');
+load(libdir + 'iteration.js');
+
+function f(v)
+{
+ if (v + "")
+ ({} = v);
+}
+
+f(true);
+f({});
+assertThrowsInstanceOf(() => f(null), TypeError);
+assertThrowsInstanceOf(() => f(undefined), TypeError);
+
+function g(v)
+{
+ if (v + "")
+ ({} = v);
+}
+
+g(true);
+g({});
+assertThrowsInstanceOf(() => g(undefined), TypeError);
+assertThrowsInstanceOf(() => g(null), TypeError);
+
+function h(v)
+{
+ if (v + "")
+ ([] = v);
+}
+
+h([true]);
+h("foo");
+assertThrowsInstanceOf(() => h(undefined), TypeError);
+assertThrowsInstanceOf(() => h(null), TypeError);
+
+Object.defineProperty(Boolean.prototype, "v",
+ { get() { "use strict"; return typeof this; },
+ enumerable: true,
+ configurable: true });
+
+Object.defineProperty(Number.prototype, "v",
+ { get() { "use strict"; return typeof this; },
+ enumerable: true,
+ configurable: true });
+
+Object.defineProperty(String.prototype, "v",
+ { get() { "use strict"; return typeof this; },
+ enumerable: true,
+ configurable: true });
+
+Object.defineProperty(Symbol.prototype, "v",
+ { get() { "use strict"; return typeof this; },
+ enumerable: true,
+ configurable: true });
+
+function primitiveThisSupported()
+{
+ return 3.14.custom === "number";
+}
+
+function primitiveThisTests()
+{
+ function f(v)
+ {
+ var type = typeof v;
+
+ ({ v } = v);
+
+ assertEq(v, type);
+ }
+
+ f(true);
+ f(3.14);
+ f(72);
+ f("ohai");
+ f(Symbol.iterator);
+
+ assertThrowsInstanceOf(() => f(undefined), TypeError);
+ assertThrowsInstanceOf(() => f(null), TypeError);
+
+ function g(v)
+ {
+ var type = typeof v;
+
+ ({ v } = v);
+
+ assertEq(v, type);
+ }
+
+ g(true);
+ g(3.14);
+ g(72);
+ g("ohai");
+ g(Symbol.iterator);
+
+ assertThrowsInstanceOf(() => g(null), TypeError);
+ assertThrowsInstanceOf(() => g(undefined), TypeError);
+}
+if (primitiveThisSupported())
+ primitiveThisTests();
+
+// Ensure the internal implementation of destructuring object pattern
+// assignment -- using a self-hosted intrinsic function -- works even when lazy
+// standard class initialization hasn't occurred. Unfortunately we can't use
+// |newGlobal()| because that method eagerly initializes standard classes.
+evalcx("({} = 1);", evalcx("lazy"));