summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/TypedArray/toString.js
blob: 0879b8b31dd9533193bae6a8b1591238b5d657d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const TypedArrayPrototype = Object.getPrototypeOf(Int8Array.prototype);

// %TypedArrayPrototype% has an own "toString" property.
assertEq(TypedArrayPrototype.hasOwnProperty("toString"), true);

// The initial value of %TypedArrayPrototype%.toString is Array.prototype.toString.
assertEq(TypedArrayPrototype.toString, Array.prototype.toString);

// The concrete TypedArray prototypes do not have an own "toString" property.
assertEq(anyTypedArrayConstructors.every(c => !c.hasOwnProperty("toString")), true);

assertDeepEq(Object.getOwnPropertyDescriptor(TypedArrayPrototype, "toString"), {
    value: TypedArrayPrototype.toString,
    writable: true,
    enumerable: false,
    configurable: true,
});

for (let constructor of anyTypedArrayConstructors) {
    assertEq(new constructor([]).toString(), "");
    assertEq(new constructor([1]).toString(), "1");
    assertEq(new constructor([1, 2]).toString(), "1,2");
}

const testCases = {
    [Int8Array.name]: {
        array: [-1, 2, -3, 4, NaN],
        expected: "-1,2,-3,4,0",
    },
    [Int16Array.name]: {
        array: [-1, 2, -3, 4, NaN],
        expected: "-1,2,-3,4,0",
    },
    [Int32Array.name]: {
        array: [-1, 2, -3, 4, NaN],
        expected: "-1,2,-3,4,0",
    },
    [Uint8Array.name]: {
        array: [255, 2, 3, 4, NaN],
        expected: "255,2,3,4,0",
    },
    [Uint16Array.name]: {
        array: [-1, 2, 3, 4, NaN],
        expected: "65535,2,3,4,0",
    },
    [Uint32Array.name]: {
        array: [-1, 2, 3, 4, NaN],
        expected: "4294967295,2,3,4,0",
    },
    [Uint8ClampedArray.name]: {
        array: [255, 256, 2, 3, 4, NaN],
        expected: "255,255,2,3,4,0",
    },
    [Float32Array.name]: {
        array: [-0, 0, 0.5, -0.5, NaN, Infinity, -Infinity],
        expected: "0,0,0.5,-0.5,NaN,Infinity,-Infinity",
    },
    [Float64Array.name]: {
        array: [-0, 0, 0.5, -0.5, NaN, Infinity, -Infinity],
        expected: "0,0,0.5,-0.5,NaN,Infinity,-Infinity",
    },
};
for (let constructor of anyTypedArrayConstructors) {
    let {array, expected} = testCases[constructor.name];
    assertEq(new constructor(array).toString(), expected);
}

if (typeof reportCompare === "function")
    reportCompare(true, true);