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_basics.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_basics.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/from_basics.js b/js/src/tests/non262/TypedArray/from_basics.js new file mode 100644 index 0000000000..9f53feb72d --- /dev/null +++ b/js/src/tests/non262/TypedArray/from_basics.js @@ -0,0 +1,42 @@ +for (var constructor of anyTypedArrayConstructors) { + // 'from' method is identical for all typed array constructors. + assertEq(anyTypedArrayConstructors[0].from === constructor.from, true); + + // %TypedArray%.from copies arrays. + var src = new constructor([1, 2, 3]), copy = constructor.from(src); + assertEq(copy === src, false); + assertEq(copy instanceof constructor, true); + assertDeepEq(copy, src); + + // Non-element properties are not copied. + var a = new constructor([0, 1]); + a.name = "lisa"; + assertDeepEq(constructor.from(a), new constructor([0, 1])); + + // %TypedArray%.from can copy non-iterable objects, if they're array-like. + src = {0: 0, 1: 1, length: 2}; + copy = constructor.from(src); + assertEq(copy instanceof constructor, true); + assertDeepEq(copy, new constructor([0, 1])); + + // Properties past the .length are not copied. + src = {0: "0", 1: "1", 2: "two", 9: "nine", name: "lisa", length: 2}; + assertDeepEq(constructor.from(src), new constructor([0, 1])); + + // If an object has neither an @@iterator method nor .length, + // then it's treated as zero-length. + assertDeepEq(constructor.from({}), new constructor()); + + // Primitives will be coerced to primitive wrapper first. + assertDeepEq(constructor.from(1), new constructor()); + assertDeepEq(constructor.from("123"), new constructor([1, 2, 3])); + assertDeepEq(constructor.from(true), new constructor()); + assertDeepEq(constructor.from(Symbol()), new constructor()); + + // Source object property order doesn't matter. + src = {length: 2, 1: "1", 0: "0"}; + assertDeepEq(constructor.from(src), new constructor([0, 1])); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |