From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../basic/destructuring-requireobjectcoercible.js | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js (limited to 'js/src/jit-test/tests/basic/destructuring-requireobjectcoercible.js') 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")); -- cgit v1.2.3