diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/TypedArray/write-out-of-bounds-tonumber.js | |
parent | Initial commit. (diff) | |
download | firefox-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 '')
-rw-r--r-- | js/src/tests/non262/TypedArray/write-out-of-bounds-tonumber.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/write-out-of-bounds-tonumber.js b/js/src/tests/non262/TypedArray/write-out-of-bounds-tonumber.js new file mode 100644 index 0000000000..48a538eab7 --- /dev/null +++ b/js/src/tests/non262/TypedArray/write-out-of-bounds-tonumber.js @@ -0,0 +1,60 @@ +// ToNumber(value) is executed for OOB writes when using a direct assignment. +function plainSet() { + var callCount = 0; + var value = { + valueOf() { + callCount++; + return 1; + } + }; + + var N = 100; + var ta = new Int32Array(0); + for (var i = 0; i < N; ++i) + ta[0] = value + + assertEq(callCount, N); +} +for (var i = 0; i < 2; ++i) plainSet(); + +// ToNumber(value) is executed for OOB writes when using Reflect.set(...). +function reflectSet() { + var callCount = 0; + var value = { + valueOf() { + callCount++; + return 1; + } + }; + + var N = 100; + var ta = new Int32Array(0); + for (var i = 0; i < N; ++i) + assertEq(Reflect.set(ta, 0, value), true); + + assertEq(callCount, N); +} +for (var i = 0; i < 2; ++i) reflectSet(); + +// ToNumber(value) is not executed for OOB writes when using Reflect.defineProperty(...). +function defineProp() { + var callCount = 0; + var value = { + valueOf() { + callCount++; + return 1; + } + }; + var desc = {value, writable: true, enumerable: true, configurable: true}; + + var N = 100; + var ta = new Int32Array(0); + for (var i = 0; i < N; ++i) + assertEq(Reflect.defineProperty(ta, 0, desc), false); + + assertEq(callCount, 0); +} +for (var i = 0; i < 2; ++i) defineProp(); + +if (typeof reportCompare === "function") + reportCompare(true, true); |