Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArray / prototype / toLocaleString / return-result.js
blob60cd013f905e5be5804740bec4d16b1b35ef5a0e
1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-%typedarray%.prototype.tolocalestring
5 description: Returns a string
6 info: |
7   22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
9   %TypedArray%.prototype.toLocaleString is a distinct function that implements
10   the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
11   except that the this object's [[ArrayLength]] internal slot is accessed in
12   place of performing a [[Get]] of "length".
13   
14   22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
15   
16   ...
17   5. Let firstElement be ? Get(array, "0").
18   6. If firstElement is undefined or null, then
19     a. Let R be the empty String.
20   7. Else,
21     a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
22   8. Let k be 1.
23   9.Repeat, while k < len
24     a. Let S be a String value produced by concatenating R and separator.
25     b. Let nextElement be ? Get(array, ! ToString(k)).
26     c. If nextElement is undefined or null, then
27       i. Let R be the empty String.
28     d. Else,
29       i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
30 includes: [testTypedArray.js]
31 features: [TypedArray]
32 ---*/
34 var separator = ["", ""].toLocaleString();
36 var arr = [42, 0, 43];
38 testWithTypedArrayConstructors(function(TA, N) {
39   var sample = new TA(arr);
40   var expected =
41     sample[0].toLocaleString().toString() +
42     separator +
43     sample[1].toLocaleString().toString() +
44     separator +
45     sample[2].toLocaleString().toString();
46   assert.sameValue(sample.toLocaleString(), expected);
47 });
49 reportCompare(0, 0);