diff options
Diffstat (limited to 'test/built-ins/TypedArray/prototype/sort')
22 files changed, 638 insertions, 5 deletions
diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js b/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js new file mode 100644 index 000000000..8a3d5a7f8 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js @@ -0,0 +1,39 @@ +// 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.sort +description: Use internal ArrayLength instead of getting a length property +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + ... + 3. Let len be the value of obj's [[ArrayLength]] internal slot. +includes: [testBigIntTypedArray.js, compareArray.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, 42n, 42n]); + getCalls = 0; + + Object.defineProperty(TA.prototype, "length", desc); + Object.defineProperty(sample, "length", desc); + + var result = sample.sort(); + + assert.sameValue(getCalls, 0, "ignores length properties"); + assert( + compareArray(result, sample), + "result is not affected by custom length" + ); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js new file mode 100644 index 000000000..668f33e06 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js @@ -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.sort +description: Returns abrupt from comparefn +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... + + 22.1.3.25 Array.prototype.sort (comparefn) + + The following steps are taken: + + - If an abrupt completion is returned from any of these operations, it is + immediately returned as the value of this function. +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n, 45n, 46n]); + var calls = 0; + + var comparefn = function() { + calls += 1; + throw new Test262Error(); + }; + + assert.throws(Test262Error, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1, "immediately returned"); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js new file mode 100644 index 000000000..0e8846c13 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js @@ -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.sort +description: comparefn is called if not undefined +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var expectedThis = (function() { + return this; +})(); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 42n, 42n, 42n, 42n]); + var calls = []; + + var comparefn = function() { + calls.push([this, arguments]); + }; + + sample.sort(comparefn); + + assert(calls.length > 0, "calls comparefn"); + calls.forEach(function(args) { + assert.sameValue(args[0], expectedThis, "comparefn is called no specific this"); + assert.sameValue(args[1].length, 2, "comparefn is always called with 2 args"); + assert.sameValue(args[1][0], 42n, "x is a listed value"); + assert.sameValue(args[1][0], 42n, "y is a listed value"); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js new file mode 100644 index 000000000..4770b66da --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js @@ -0,0 +1,55 @@ +// Copyright (C) 2017 Jordan Harband. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.sort +description: throws on a non-undefined non-function +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + Upon entry, the following steps are performed to initialize evaluation + of the sort function. These steps are used instead of the entry steps + in 22.1.3.25: + + ... + 1. If _comparefn_ is not *undefined* and IsCallable(_comparefn_) is *false*, throw a *TypeError* exception. + ... + +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([42n, 43n, 44n, 45n, 46n]); + + assert.throws(TypeError, function() { + sample.sort(null); + }); + + assert.throws(TypeError, function() { + sample.sort(true); + }); + + assert.throws(TypeError, function() { + sample.sort(false); + }); + + assert.throws(TypeError, function() { + sample.sort(''); + }); + + assert.throws(TypeError, function() { + sample.sort(/a/g); + }); + + assert.throws(TypeError, function() { + sample.sort(42); + }); + + assert.throws(TypeError, function() { + sample.sort([]); + }); + + assert.throws(TypeError, function() { + sample.sort({}); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js new file mode 100644 index 000000000..caa7f80a2 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer-comparefn.js @@ -0,0 +1,38 @@ +// 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.sort +description: Throws a TypeError if comparefn detaches the object buffer +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + b. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. + ... + ... +includes: [testBigIntTypedArray.js, detachArrayBuffer.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(4); + var calls = 0; + var comparefn = function() { + if (calls > 0) { + throw new Test262Error(); + } + calls++; + $DETACHBUFFER(sample.buffer); + }; + + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); + + assert.sameValue(calls, 1); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js new file mode 100644 index 000000000..e49bb0883 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js @@ -0,0 +1,31 @@ +// 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.sort +description: Throws a TypeError if this has a detached buffer +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value. + 2. Let buffer be ? ValidateTypedArray(obj). + + 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] +---*/ + +var comparefn = function() { + throw new Test262Error(); +}; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA(1); + $DETACHBUFFER(sample.buffer); + assert.throws(TypeError, function() { + sample.sort(comparefn); + }); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.js b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.js new file mode 100644 index 000000000..760443c6f --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-func.js @@ -0,0 +1,35 @@ +// 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.sort +description: Throws a TypeError exception when invoked as a function +info: | + 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; + +assert.sameValue(typeof sort, 'function'); + +assert.throws(TypeError, function() { + sort(); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.js b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.js new file mode 100644 index 000000000..e288c99e5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/invoked-as-method.js @@ -0,0 +1,35 @@ +// 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.sort +description: Requires a [[TypedArrayName]] internal slot. +info: | + 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) + + ... + This function is not generic. The this value must be an object with a + [[TypedArrayName]] internal slot. + ... + + 1. Let obj be the this value as the argument. + 2. Let buffer be ValidateTypedArray(obj). + 3. ReturnIfAbrupt(buffer). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +assert.sameValue(typeof TypedArrayPrototype.sort, 'function'); + +assert.throws(TypeError, function() { + TypedArrayPrototype.sort(); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/length.js b/test/built-ins/TypedArray/prototype/sort/BigInt/length.js new file mode 100644 index 000000000..c6bbb9f28 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/length.js @@ -0,0 +1,30 @@ +// 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.sort +description: > + %TypedArray%.prototype.sort.length is 1. +info: | + %TypedArray%.prototype.sort ( comparefn ) + + 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, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.sort.length, 1); + +verifyNotEnumerable(TypedArray.prototype.sort, "length"); +verifyNotWritable(TypedArray.prototype.sort, "length"); +verifyConfigurable(TypedArray.prototype.sort, "length"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/name.js b/test/built-ins/TypedArray/prototype/sort/BigInt/name.js new file mode 100644 index 000000000..5f516c540 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/name.js @@ -0,0 +1,27 @@ +// 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.sort +description: > + %TypedArray%.prototype.sort.name is "sort". +info: | + %TypedArray%.prototype.sort ( comparefn ) + + 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, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +assert.sameValue(TypedArray.prototype.sort.name, "sort"); + +verifyNotEnumerable(TypedArray.prototype.sort, "name"); +verifyNotWritable(TypedArray.prototype.sort, "name"); +verifyConfigurable(TypedArray.prototype.sort, "name"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js b/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js new file mode 100644 index 000000000..86fc9e32b --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/prop-desc.js @@ -0,0 +1,19 @@ +// 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.sort +description: > + "sort" 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, testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var TypedArrayPrototype = TypedArray.prototype; + +verifyNotEnumerable(TypedArrayPrototype, 'sort'); +verifyWritable(TypedArrayPrototype, 'sort'); +verifyConfigurable(TypedArrayPrototype, 'sort'); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js b/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js new file mode 100644 index 000000000..702f45015 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js @@ -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.sort +description: Returns the same instance +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([2n, 1n]); + var result = sample.sort(); + + assert.sameValue(sample, result, "without comparefn"); + + result = sample.sort(function() { return 0; }); + assert.sameValue(sample, result, "with comparefn"); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js new file mode 100644 index 000000000..3f6402c66 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js @@ -0,0 +1,27 @@ +// 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.sort +description: TypedArrays sort does not cast values to String +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + 2. If the argument comparefn is not undefined, then + a. Let v be ? Call(comparefn, undefined, « x, y »). + ... + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +var origToString = Number.prototype.toString; + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([20n, 100n, 3n]); + var result = sample.sort(); + assert(compareArray(result, [3n, 20n, 100n])); +}); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js new file mode 100644 index 000000000..7a553b13e --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values-nan.js @@ -0,0 +1,38 @@ +// 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.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... + + NOTE: Because NaN always compares greater than any other value, NaN property + values always sort to the end of the result when comparefn is not provided. +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([2, NaN, NaN, 0, 1]).sort(); + assert.sameValue(sample[0], 0, "#1 [0]"); + assert.sameValue(sample[1], 1, "#1 [1]"); + assert.sameValue(sample[2], 2, "#1 [2]"); + assert.sameValue(sample[3], NaN, "#1 [3]"); + assert.sameValue(sample[4], NaN, "#1 [4]"); + + sample = new TA([3, NaN, NaN, Infinity, 0, -Infinity, 2]).sort(); + assert.sameValue(sample[0], -Infinity, "#2 [0]"); + assert.sameValue(sample[1], 0, "#2 [1]"); + assert.sameValue(sample[2], 2, "#2 [2]"); + assert.sameValue(sample[3], 3, "#2 [3]"); + assert.sameValue(sample[4], Infinity, "#2 [4]"); + assert.sameValue(sample[5], NaN, "#2 [5]"); + assert.sameValue(sample[6], NaN, "#2 [6]"); +}, [Float64Array, Float32Array]); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js new file mode 100644 index 000000000..57b491551 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js @@ -0,0 +1,53 @@ +// 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.sort +description: Sort values to numeric ascending order +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + When the TypedArray SortCompare abstract operation is called with two + arguments x and y, the following steps are taken: + + ... +includes: [testBigIntTypedArray.js, compareArray.js] +features: [BigInt, TypedArray] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([4n, 3n, 2n, 1n]).sort(); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "descending values"); + + sample = new TA([3n, 4n, 1n, 2n]).sort(); + assert(compareArray(sample, [1n, 2n, 3n, 4n]), "mixed numbers"); + + sample = new TA([3n, 4n, 3n, 1n, 0n, 1n, 2n]).sort(); + assert(compareArray(sample, [0n, 1n, 1n, 2n, 3n, 3n, 4n]), "repeating numbers"); + + sample = new TA([1n, 0n, -0n, 2n]).sort(); + assert(compareArray(sample, [0n, 0n, 1n, 2n]), "0s"); +}); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample = new TA([-4, 3, 4, -3, 2, -2, 1, 0]).sort(); + assert(compareArray(sample, [-4, -3, -2, 0, 1, 2, 3, 4]), "negative values"); +}, [Float64Array, Float32Array, Int8Array, Int16Array, Int32Array]); + +testWithBigIntTypedArrayConstructors(function(TA) { + var sample; + + sample = new TA([0.5, 0, 1.5, 1]).sort(); + assert(compareArray(sample, [0, 0.5, 1, 1.5]), "non integers"); + + sample = new TA([0.5, 0, 1.5, -0.5, -1, -1.5, 1]).sort(); + assert(compareArray(sample, [-1.5, -1, -0.5, 0, 0.5, 1, 1.5]), "non integers + negatives"); + + sample = new TA([1, 0, -0, 2]).sort(); + assert(compareArray(sample, [0, 0, 1, 2]), "0 and -0"); + + sample = new TA([3, 4, Infinity, -Infinity, 1, 2]).sort(); + assert(compareArray(sample, [-Infinity, 1, 2, 3, 4, Infinity]), "infinities"); + +}, [Float64Array, Float32Array]); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.js b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.js new file mode 100644 index 000000000..9c8a4c7fb --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-object.js @@ -0,0 +1,51 @@ +// 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.sort +description: Throws a TypeError exception when `this` is not Object +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateTypedArray(obj). + ... + + 22.2.3.5.1 Runtime Semantics: ValidateTypedArray ( O ) + + 1. If Type(O) is not Object, throw a TypeError exception. + ... +includes: [testBigIntTypedArray.js] +features: [BigInt, Symbol, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call(undefined, comparefn); +}, "this is undefined"); + +assert.throws(TypeError, function() { + sort.call(null, comparefn); +}, "this is null"); + +assert.throws(TypeError, function() { + sort.call(42, comparefn); +}, "this is 42"); + +assert.throws(TypeError, function() { + sort.call("1", comparefn); +}, "this is a string"); + +assert.throws(TypeError, function() { + sort.call(true, comparefn); +}, "this is true"); + +assert.throws(TypeError, function() { + sort.call(false, comparefn); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + sort.call(s, comparefn); +}, "this is a Symbol"); diff --git a/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.js b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.js new file mode 100644 index 000000000..74e47bae5 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/sort/BigInt/this-is-not-typedarray-instance.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.sort +description: > + Throws a TypeError exception when `this` is not a TypedArray instance +info: | + 22.2.3.26 %TypedArray%.prototype.sort ( comparefn ) + + 1. Let obj be the this value as the argument. + 2. Let buffer be ? ValidateTypedArray(obj). + ... + + 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: [testBigIntTypedArray.js] +features: [BigInt, TypedArray] +---*/ + +var sort = TypedArray.prototype.sort; +var comparefn = function() {}; + +assert.throws(TypeError, function() { + sort.call({}, comparefn); +}, "this is an Object"); + +assert.throws(TypeError, function() { + sort.call([], comparefn); +}, "this is an Array"); + +var ab = new ArrayBuffer(8); +assert.throws(TypeError, function() { + sort.call(ab, comparefn); +}, "this is an ArrayBuffer instance"); + +var dv = new DataView(new ArrayBuffer(8), 0, 1); +assert.throws(TypeError, function() { + sort.call(dv, comparefn); +}, "this is a DataView instance"); diff --git a/test/built-ins/TypedArray/prototype/sort/invoked-as-func.js b/test/built-ins/TypedArray/prototype/sort/invoked-as-func.js index b3e77e4cb..705ef3a3d 100644 --- a/test/built-ins/TypedArray/prototype/sort/invoked-as-func.js +++ b/test/built-ins/TypedArray/prototype/sort/invoked-as-func.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.25 +esid: sec-%typedarray%.prototype.sort description: Throws a TypeError exception when invoked as a function info: | 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) diff --git a/test/built-ins/TypedArray/prototype/sort/invoked-as-method.js b/test/built-ins/TypedArray/prototype/sort/invoked-as-method.js index 33edcc428..4f18b417e 100644 --- a/test/built-ins/TypedArray/prototype/sort/invoked-as-method.js +++ b/test/built-ins/TypedArray/prototype/sort/invoked-as-method.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.25 +esid: sec-%typedarray%.prototype.sort description: Requires a [[TypedArrayName]] internal slot. info: | 22.2.3.25 %TypedArray%.prototype.sort ( comparefn ) diff --git a/test/built-ins/TypedArray/prototype/sort/length.js b/test/built-ins/TypedArray/prototype/sort/length.js index d8237d233..8bd6a93ad 100644 --- a/test/built-ins/TypedArray/prototype/sort/length.js +++ b/test/built-ins/TypedArray/prototype/sort/length.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.25 +esid: sec-%typedarray%.prototype.sort description: > %TypedArray%.prototype.sort.length is 1. info: | @@ -20,6 +20,7 @@ info: | object has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] ---*/ assert.sameValue(TypedArray.prototype.sort.length, 1); diff --git a/test/built-ins/TypedArray/prototype/sort/name.js b/test/built-ins/TypedArray/prototype/sort/name.js index e1785cd7e..d920126ec 100644 --- a/test/built-ins/TypedArray/prototype/sort/name.js +++ b/test/built-ins/TypedArray/prototype/sort/name.js @@ -2,7 +2,7 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.25 +esid: sec-%typedarray%.prototype.sort description: > %TypedArray%.prototype.sort.name is "sort". info: | @@ -17,6 +17,7 @@ info: | object, if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. includes: [propertyHelper.js, testTypedArray.js] +features: [TypedArray] ---*/ assert.sameValue(TypedArray.prototype.sort.name, "sort"); diff --git a/test/built-ins/TypedArray/prototype/sort/prop-desc.js b/test/built-ins/TypedArray/prototype/sort/prop-desc.js index 681de6475..b8fecb045 100644 --- a/test/built-ins/TypedArray/prototype/sort/prop-desc.js +++ b/test/built-ins/TypedArray/prototype/sort/prop-desc.js @@ -1,7 +1,7 @@ // Copyright (C) 2016 the V8 project authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- -es6id: 22.2.3.25 +esid: sec-%typedarray%.prototype.sort description: > "sort" property of TypedArrayPrototype info: | @@ -9,6 +9,7 @@ info: | 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; |