summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/Array/toLocaleString.js
blob: f94e531f8994abdbe54cf0fc52eb123d52ce4452 (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
if (typeof Intl === "object") {
    const localeSep = [,,].toLocaleString();

    // Missing arguments are passed as |undefined|.
    const objNoArgs = {
        toLocaleString() {
            assertEq(arguments.length, 2);
            assertEq(arguments[0], undefined);
            assertEq(arguments[1], undefined);
            return "pass";
        }
    };
    // - Single element case.
    assertEq([objNoArgs].toLocaleString(), "pass");
    // - More than one element.
    assertEq([objNoArgs, objNoArgs].toLocaleString(), "pass" + localeSep + "pass");

    // Ensure "locales" and "options" arguments are passed to the array elements.
    const locales = {}, options = {};
    const objWithArgs = {
        toLocaleString() {
            assertEq(arguments.length, 2);
            assertEq(arguments[0], locales);
            assertEq(arguments[1], options);
            return "pass";
        }
    };
    // - Single element case.
    assertEq([objWithArgs].toLocaleString(locales, options), "pass");
    // - More than one element.
    assertEq([objWithArgs, objWithArgs].toLocaleString(locales, options), "pass" + localeSep + "pass");
}

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