diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString')
40 files changed, 1755 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js new file mode 100644 index 0000000000..233c0f4966 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tolocalestring-from-each-value.js @@ -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: 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: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + calls.push(this); + return "hacks" + calls.length; +}; + +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = []; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert( + compareArray(new TA(calls), sample), + "toLocaleString called for each item" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js new file mode 100644 index 0000000000..9848015a02 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-tostring-from-each-value.js @@ -0,0 +1,60 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.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 = [42n, 0n]; +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js new file mode 100644 index 0000000000..11e362dcf1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/calls-valueof-from-each-value.js @@ -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 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); +var calls; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + return "hacks" + calls; + } + }; +}; + +var expected = ["hacks1", "hacks2"].join(separator); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.sameValue(sample.toLocaleString(), expected, "returns expected value"); + assert.sameValue(calls, 2, "valueOf called once for each item"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js new file mode 100644 index 0000000000..9cb0bd490d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/detached-buffer.js @@ -0,0 +1,30 @@ +// 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: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js new file mode 100644 index 0000000000..f1ef22bbb7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/empty-instance-returns-empty-string.js @@ -0,0 +1,28 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.toLocaleString(), ""); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..2a0b386eb4 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/get-length-uses-internal-arraylength.js @@ -0,0 +1,44 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n]); + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + sample.toLocaleString(); + + assert.sameValue(getCalls, 0, "ignores length properties"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js new file mode 100644 index 0000000000..f9d23d808b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tolocalestring.js @@ -0,0 +1,43 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls; + +BigInt.prototype.toLocaleString = function() { + calls++; + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA([42n, 0n]); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "abrupt from first element"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js new file mode 100644 index 0000000000..2fe9aaa9e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-tostring.js @@ -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 => 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js new file mode 100644 index 0000000000..aa8f6b3cc1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-firstelement-valueof.js @@ -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 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js new file mode 100644 index 0000000000..9e5fbfee54 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tolocalestring.js @@ -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 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + calls = 0; + var sample = new TA([42n, 0n]); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a next element"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js new file mode 100644 index 0000000000..e95855d738 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-tostring.js @@ -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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js new file mode 100644 index 0000000000..e59ced5e31 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-nextelement-valueof.js @@ -0,0 +1,58 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var calls = 0; + +BigInt.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n]); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..bbd84a46a9 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 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 when "this" value fails buffer boundary checks +includes: [testBigIntTypedArray.js] +features: [ArrayBuffer, BigInt, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.toLocaleString, + 'function', + 'implements TypedArray.prototype.toLocaleString' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithBigIntTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.toLocaleString(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.toLocaleString(); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the toLocaleString operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.toLocaleString(); + throw new Test262Error('toLocaleString completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js new file mode 100644 index 0000000000..42add1d7e1 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/return-result.js @@ -0,0 +1,47 @@ +// 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 0n, 43n]); + var expected = + sample[0].toLocaleString().toString() + + separator + + sample[1].toLocaleString().toString() + + separator + + sample[2].toLocaleString().toString(); + assert.sameValue(sample.toLocaleString(), expected); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/BigInt/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/browser.js diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js new file mode 100644 index 0000000000..7cbb2cb39a --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tolocalestring-from-each-value.js @@ -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 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] +features: [TypedArray] +---*/ + +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" + ); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js new file mode 100644 index 0000000000..585035169e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-tostring-from-each-value.js @@ -0,0 +1,60 @@ +// 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] +features: [TypedArray] +---*/ + +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, N) { + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js new file mode 100644 index 0000000000..379470d105 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/calls-valueof-from-each-value.js @@ -0,0 +1,58 @@ +// 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] +features: [TypedArray] +---*/ + +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, N) { + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js new file mode 100644 index 0000000000..df5d1a5a8c --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/detached-buffer.js @@ -0,0 +1,30 @@ +// 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: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + ... + 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... +includes: [testTypedArray.js, detachArrayBuffer.js] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.toLocaleString(); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js new file mode 100644 index 0000000000..fb9690e4eb --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/empty-instance-returns-empty-string.js @@ -0,0 +1,28 @@ +// 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] +features: [TypedArray] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var sample = new TA(); + assert.sameValue(sample.toLocaleString(), ""); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js new file mode 100644 index 0000000000..910b72a391 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/get-length-uses-internal-arraylength.js @@ -0,0 +1,44 @@ +// 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] +features: [TypedArray] +---*/ + +var getCalls = 0; +var desc = { + get: function getLen() { + getCalls++; + return 0; + } +}; + +Object.defineProperty(TypedArray.prototype, "length", desc); + +testWithTypedArrayConstructors(function(TA, N) { + 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"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-func.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-func.js new file mode 100644 index 0000000000..50b138d41b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-func.js @@ -0,0 +1,33 @@ +// 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: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.sameValue(typeof toLocaleString, 'function'); + +assert.throws(TypeError, function() { + toLocaleString(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-method.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-method.js new file mode 100644 index 0000000000..da9ce62df8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/invoked-as-method.js @@ -0,0 +1,33 @@ +// 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: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.27 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + ... + + This function is not generic. ValidateTypedArray is applied to the this + value prior to evaluating the algorithm. If its result is an abrupt + completion that exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.toLocaleString, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.toLocaleString(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/length.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/length.js new file mode 100644 index 0000000000..fcd30d3ec8 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/length.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.tolocalestring +description: > + %TypedArray%.prototype.toLocaleString.length is 0. +info: | + %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.toLocaleString.length, 0); + +verifyNotEnumerable(TypedArray.prototype.toLocaleString, "length"); +verifyNotWritable(TypedArray.prototype.toLocaleString, "length"); +verifyConfigurable(TypedArray.prototype.toLocaleString, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/name.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/name.js new file mode 100644 index 0000000000..b793dd388b --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.tolocalestring +description: > + %TypedArray%.prototype.toLocaleString.name is "toLocaleString". +info: | + %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.toLocaleString.name, "toLocaleString"); + +verifyNotEnumerable(TypedArray.prototype.toLocaleString, "name"); +verifyNotWritable(TypedArray.prototype.toLocaleString, "name"); +verifyConfigurable(TypedArray.prototype.toLocaleString, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/not-a-constructor.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/not-a-constructor.js new file mode 100644 index 0000000000..3366ceacde --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + TypedArray.prototype.toLocaleString does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js, testTypedArray.js] +features: [Reflect.construct, arrow-function, TypedArray] +---*/ + +assert.sameValue( + isConstructor(TypedArray.prototype.toLocaleString), + false, + 'isConstructor(TypedArray.prototype.toLocaleString) must return false' +); + +assert.throws(TypeError, () => { + let u8 = new Uint8Array(1); new u8.toLocaleString(); +}, '`let u8 = new Uint8Array(1); new u8.toLocaleString()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/prop-desc.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/prop-desc.js new file mode 100644 index 0000000000..e4d7516476 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/prop-desc.js @@ -0,0 +1,21 @@ +// 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: > + "toLocaleString" property of TypedArrayPrototype +info: | + ES6 section 17: Every other data property described in clauses 18 through 26 + and in Annex B.2 has the attributes { [[Writable]]: true, + [[Enumerable]]: false, [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'toLocaleString'); +verifyWritable(TypedArrayPrototype, 'toLocaleString'); +verifyConfigurable(TypedArrayPrototype, 'toLocaleString'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js new file mode 100644 index 0000000000..9114df1a13 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tolocalestring.js @@ -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 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] +features: [TypedArray] +---*/ + +var calls; + +Number.prototype.toLocaleString = function() { + calls++; + throw new Test262Error(); +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + calls = 0; + var sample = new TA(arr); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "abrupt from first element"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js new file mode 100644 index 0000000000..05095bd645 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-tostring.js @@ -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 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] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js new file mode 100644 index 0000000000..690e9c32e6 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-firstelement-valueof.js @@ -0,0 +1,58 @@ +// 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] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: undefined, + valueOf: function() { + calls++; + throw new Test262Error(); + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 1, "toString called once"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js new file mode 100644 index 0000000000..f46d410a13 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tolocalestring.js @@ -0,0 +1,48 @@ +// 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] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + calls = 0; + var sample = new TA(arr); + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a next element"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js new file mode 100644 index 0000000000..7b3f2d68ba --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-tostring.js @@ -0,0 +1,59 @@ +// 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] +features: [TypedArray] +---*/ + +var calls = 0; + +Number.prototype.toLocaleString = function() { + return { + toString: function() { + calls++; + if (calls > 1) { + throw new Test262Error(); + } + } + }; +}; + +var arr = [42, 0]; + +testWithTypedArrayConstructors(function(TA, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js new file mode 100644 index 0000000000..acc8eca436 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-nextelement-valueof.js @@ -0,0 +1,60 @@ +// 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] +features: [TypedArray] +---*/ + +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, N) { + var sample = new TA(arr); + calls = 0; + assert.throws(Test262Error, function() { + sample.toLocaleString(); + }); + assert.sameValue(calls, 2, "abrupt from a nextElement"); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js new file mode 100644 index 0000000000..04a4238da7 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-abrupt-from-this-out-of-bounds.js @@ -0,0 +1,62 @@ +// |reftest| skip -- resizable-arraybuffer is not supported +// Copyright (C) 2021 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 when "this" value fails buffer boundary checks +includes: [testTypedArray.js] +features: [ArrayBuffer, TypedArray, arrow-function, resizable-arraybuffer] +---*/ + +assert.sameValue( + typeof TypedArray.prototype.toLocaleString, + 'function', + 'implements TypedArray.prototype.toLocaleString' +); + +assert.sameValue( + typeof ArrayBuffer.prototype.resize, + 'function', + 'implements ArrayBuffer.prototype.resize' +); + +testWithTypedArrayConstructors(TA => { + var BPE = TA.BYTES_PER_ELEMENT; + var ab = new ArrayBuffer(BPE * 4, {maxByteLength: BPE * 5}); + var array = new TA(ab, BPE, 2); + + try { + ab.resize(BPE * 5); + } catch (_) {} + + // no error following grow: + array.toLocaleString(); + + try { + ab.resize(BPE * 3); + } catch (_) {} + + // no error following shrink (within bounds): + array.toLocaleString(); + + var expectedError; + try { + ab.resize(BPE * 2); + // If the preceding "resize" operation is successful, the typed array will + // be out out of bounds, so the subsequent prototype method should produce + // a TypeError due to the semantics of ValidateTypedArray. + expectedError = TypeError; + } catch (_) { + // The host is permitted to fail any "resize" operation at its own + // discretion. If that occurs, the toLocaleString operation should complete + // successfully. + expectedError = Test262Error; + } + + assert.throws(expectedError, () => { + array.toLocaleString(); + throw new Test262Error('toLocaleString completed successfully'); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-result.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-result.js new file mode 100644 index 0000000000..60cd013f90 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/return-result.js @@ -0,0 +1,49 @@ +// 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] +features: [TypedArray] +---*/ + +var separator = ["", ""].toLocaleString(); + +var arr = [42, 0, 43]; + +testWithTypedArrayConstructors(function(TA, N) { + 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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-object.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-object.js new file mode 100644 index 0000000000..2c471f761e --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-object.js @@ -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: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [Symbol, TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + toLocaleString.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + toLocaleString.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + toLocaleString.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + toLocaleString.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + toLocaleString.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + toLocaleString.call(s); +}, "this is a Symbol"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js new file mode 100644 index 0000000000..b3c33fc0c2 --- /dev/null +++ b/js/src/tests/test262/built-ins/TypedArray/prototype/toLocaleString/this-is-not-typedarray-instance.js @@ -0,0 +1,44 @@ +// 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: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.28 %TypedArray%.prototype.toLocaleString ([ reserved1 [ , reserved2 ] ]) + + This function is not generic. ValidateTypedArray is applied to the this value + prior to evaluating the algorithm. If its result is an abrupt completion that + exception is thrown instead of evaluating the algorithm. + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError + exception. + ... +includes: [testTypedArray.js] +features: [TypedArray] +---*/ + +var toLocaleString = TypedArray.prototype.toLocaleString; + +assert.throws(TypeError, function() { + toLocaleString.call({}); +}, "this is an Object"); + +assert.throws(TypeError, function() { + toLocaleString.call([]); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + toLocaleString.call(ab); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + toLocaleString.call(dv); +}, "this is a DataView instance"); + +reportCompare(0, 0); |