summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js
diff options
context:
space:
mode:
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"));