mirror of https://github.com/tc39/test262.git
Add tests for TypedArrays toLocaleString
This commit is contained in:
parent
9c45e2ac68
commit
177b2f6018
52
test/built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js
vendored
Normal file
52
test/built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Calls toLocaleString from each property's value
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js, compareArray.js]
|
||||
---*/
|
||||
|
||||
var separator = ["", ""].toLocaleString();
|
||||
var calls;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
calls.push(this);
|
||||
return "hacks" + calls.length;
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
var expected = ["hacks1", "hacks2"].join(separator);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = [];
|
||||
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
|
||||
assert(
|
||||
compareArray(new TA(calls), sample),
|
||||
"toLocaleString called for each item"
|
||||
);
|
||||
});
|
57
test/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js
vendored
Normal file
57
test/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Calls toString from each property's value return from toLocaleString
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var separator = ["", ""].toLocaleString();
|
||||
var calls;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: function() {
|
||||
calls++;
|
||||
return "hacks" + calls;
|
||||
},
|
||||
valueOf: function() {
|
||||
throw new Test262Error("should not call valueOf if toString is present");
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
var expected = ["hacks1", "hacks2"].join(separator);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
|
||||
assert.sameValue(calls, 2, "toString called once for each item");
|
||||
});
|
55
test/built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js
vendored
Normal file
55
test/built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Calls valueOf from each property's value return from toLocaleString
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var separator = ["", ""].toLocaleString();
|
||||
var calls;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: undefined,
|
||||
valueOf: function() {
|
||||
calls++;
|
||||
return "hacks" + calls;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
var expected = ["hacks1", "hacks2"].join(separator);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.sameValue(sample.toLocaleString(), expected, "returns expected value");
|
||||
assert.sameValue(calls, 2, "valueOf called once for each item");
|
||||
});
|
25
test/built-ins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js
vendored
Normal file
25
test/built-ins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Returns an empty string if called on an empty instance
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
4. If len is zero, return the empty String.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA();
|
||||
assert.sameValue(sample.toLocaleString(), "");
|
||||
});
|
41
test/built-ins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js
vendored
Normal file
41
test/built-ins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Get "length" uses internal ArrayLength
|
||||
info: >
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
1. Let array be ? ToObject(this value).
|
||||
2.Let len be ? ToLength(? Get(array, "length")).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var getCalls = 0;
|
||||
var desc = {
|
||||
get: function getLen() {
|
||||
getCalls++;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(TypedArray.prototype, "length", desc);
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA([42, 43]);
|
||||
|
||||
Object.defineProperty(TA.prototype, "length", desc);
|
||||
Object.defineProperty(sample, "length", desc);
|
||||
|
||||
sample.toLocaleString();
|
||||
|
||||
assert.sameValue(getCalls, 0, "ignores length properties");
|
||||
});
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Returns abrupt from firstElement's toLocaleString
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
4. If len is zero, return the empty String.
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
calls++;
|
||||
throw new Test262Error();
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
calls = 0;
|
||||
var sample = new TA(arr);
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 1, "abrupt from first element");
|
||||
});
|
54
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js
vendored
Normal file
54
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Return abrupt from firstElement's toLocaleString => toString
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: function() {
|
||||
calls++;
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 1, "toString called once");
|
||||
});
|
55
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js
vendored
Normal file
55
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Return abrupt from firstElement's toLocaleString => valueOf
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: undefined,
|
||||
valueOf: function() {
|
||||
calls++;
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 1, "toString called once");
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Returns abrupt from a nextElement's toLocaleString
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
calls++;
|
||||
if (calls > 1) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
calls = 0;
|
||||
var sample = new TA(arr);
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 2, "abrupt from a next element");
|
||||
});
|
56
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js
vendored
Normal file
56
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Return abrupt from nextElement's toLocaleString => valueOf
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: function() {
|
||||
calls++;
|
||||
if (calls > 1) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 2, "abrupt from a nextElement");
|
||||
});
|
57
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js
vendored
Normal file
57
test/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: >
|
||||
Return abrupt from nextElement's toLocaleString => valueOf
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var calls = 0;
|
||||
|
||||
Number.prototype.toLocaleString = function() {
|
||||
return {
|
||||
toString: undefined,
|
||||
valueOf: function() {
|
||||
calls++;
|
||||
if (calls > 1) {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var arr = [42, 0];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
calls = 0;
|
||||
assert.throws(Test262Error, function() {
|
||||
sample.toLocaleString();
|
||||
});
|
||||
assert.sameValue(calls, 2, "abrupt from a nextElement");
|
||||
});
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-%typedarray%.prototype.tolocalestring
|
||||
description: Returns a string
|
||||
info: |
|
||||
22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ])
|
||||
|
||||
%TypedArray%.prototype.toLocaleString is a distinct function that implements
|
||||
the same algorithm as Array.prototype.toLocaleString as defined in 22.1.3.27
|
||||
except that the this object's [[ArrayLength]] internal slot is accessed in
|
||||
place of performing a [[Get]] of "length".
|
||||
|
||||
22.1.3.27 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
|
||||
|
||||
...
|
||||
5. Let firstElement be ? Get(array, "0").
|
||||
6. If firstElement is undefined or null, then
|
||||
a. Let R be the empty String.
|
||||
7. Else,
|
||||
a. Let R be ? ToString(? Invoke(firstElement, "toLocaleString")).
|
||||
8. Let k be 1.
|
||||
9.Repeat, while k < len
|
||||
a. Let S be a String value produced by concatenating R and separator.
|
||||
b. Let nextElement be ? Get(array, ! ToString(k)).
|
||||
c. If nextElement is undefined or null, then
|
||||
i. Let R be the empty String.
|
||||
d. Else,
|
||||
i. Let R be ? ToString(? Invoke(nextElement, "toLocaleString")).
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
||||
var separator = ["", ""].toLocaleString();
|
||||
|
||||
var arr = [42, 0, 43];
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = new TA(arr);
|
||||
var expected =
|
||||
sample[0].toLocaleString().toString() +
|
||||
separator +
|
||||
sample[1].toLocaleString().toString() +
|
||||
separator +
|
||||
sample[2].toLocaleString().toString();
|
||||
assert.sameValue(sample.toLocaleString(), expected);
|
||||
});
|
Loading…
Reference in New Issue