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/from_iterable.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/from_iterable.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/from_iterable.js b/js/src/tests/non262/TypedArray/from_iterable.js new file mode 100644 index 0000000000..889c815898 --- /dev/null +++ b/js/src/tests/non262/TypedArray/from_iterable.js @@ -0,0 +1,49 @@ +for (var constructor of anyTypedArrayConstructors) { + // %TypedArray%.from works on arguments objects. + (function () { + assertDeepEq(constructor.from(arguments), new constructor(["0", "1", undefined])); + })("0", "1", undefined); + + // If an object has both .length and [@@iterator] properties, [@@iterator] is used. + var a = ['0', '1', '2', '3', '4']; + a[Symbol.iterator] = function* () { + for (var i = 5; i--; ) + yield this[i]; + }; + + var log = ''; + function f(x) { + log += x; + return x + x; + } + + var b = constructor.from(a, f); + assertDeepEq(b, new constructor(['44', '33', '22', '11', '00'])); + assertEq(log, '43210'); + + // In fact, if [@@iterator] is present, .length isn't queried at all. + var pa = new Proxy(a, { + has: function (target, id) { + if (id === "length") + throw new Error(".length should not be queried (has)"); + return id in target; + }, + get: function (target, id) { + if (id === "length") + throw new Error(".length should not be queried (get)"); + return target[id]; + }, + getOwnPropertyDescriptor: function (target, id) { + if (id === "length") + throw new Error(".length should not be queried (getOwnPropertyDescriptor)"); + return Object.getOwnPropertyDescriptor(target, id) + } + }); + log = ""; + b = constructor.from(pa, f); + assertDeepEq(b, new constructor(['44', '33', '22', '11', '00'])); + assertEq(log, '43210'); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |