From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/TypedArray/from_iterable.js | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 js/src/tests/non262/TypedArray/from_iterable.js (limited to 'js/src/tests/non262/TypedArray/from_iterable.js') 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); -- cgit v1.2.3