summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt')
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js41
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/browser.js0
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js44
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js25
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js57
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js62
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js27
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/shell.js42
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js33
-rw-r--r--js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js33
12 files changed, 441 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js
new file mode 100644
index 0000000000..9f22698cee
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/arraylength-internal.js
@@ -0,0 +1,41 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.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"
+ );
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/browser.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/browser.js
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.js
new file mode 100644
index 0000000000..87b67132b2
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-call-throws.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.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");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.js
new file mode 100644
index 0000000000..e1133bb3fc
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-calls.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.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");
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js
new file mode 100644
index 0000000000..ed3575fba8
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-is-undefined.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2020 Rick Waldron. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-%typedarray%.prototype.sort
+description: >
+ Treats explicit undefined comparefn the same as implicit undefined comparefn
+info: |
+ %TypedArray%.prototype.sort ( comparefn )
+
+ 1. If comparefn is not undefined and IsCallable(comparefn) is false, throw a TypeError exception.
+ ...
+includes: [compareArray.js, testBigIntTypedArray.js]
+features: [TypedArray, BigInt]
+---*/
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ let sample = new TA([42n, 44n, 46n, 43n, 45n]);
+ let explicit = sample.sort(undefined);
+ let implicit = sample.sort();
+
+ assert.compareArray(explicit, [42n, 43n, 44n, 45n, 46n], 'The value of `explicit` is [42n, 43n, 44n, 45n, 46n]');
+ assert.compareArray(implicit, [42n, 43n, 44n, 45n, 46n], 'The value of `implicit` is [42n, 43n, 44n, 45n, 46n]');
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js
new file mode 100644
index 0000000000..2c96e3099d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/comparefn-nonfunction-call-throws.js
@@ -0,0 +1,57 @@
+// 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({});
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.js
new file mode 100644
index 0000000000..5f21eb1dda
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/detached-buffer.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.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);
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-abrupt-from-this-out-of-bounds.js
new file mode 100644
index 0000000000..dee08240ed
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/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.sort
+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.sort,
+ 'function',
+ 'implements TypedArray.prototype.sort'
+);
+
+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.sort();
+
+ try {
+ ab.resize(BPE * 3);
+ } catch (_) {}
+
+ // no error following shrink (within bounds):
+ array.sort();
+
+ 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 sort operation should complete
+ // successfully.
+ expectedError = Test262Error;
+ }
+
+ assert.throws(expectedError, () => {
+ array.sort();
+ throw new Test262Error('sort completed successfully');
+ });
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.js
new file mode 100644
index 0000000000..813b6d3659
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/return-same-instance.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: 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");
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/shell.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/shell.js
new file mode 100644
index 0000000000..90ee9c114d
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/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/sort/BigInt/sortcompare-with-no-tostring.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.js
new file mode 100644
index 0000000000..e610ad58a5
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sortcompare-with-no-tostring.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.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 toStringCalled = false;
+BigInt.prototype.toString = function() {
+ toStringCalled = true;
+}
+
+testWithBigIntTypedArrayConstructors(function(TA) {
+ var sample = new TA([20n, 100n, 3n]);
+ var result = sample.sort();
+ assert.sameValue(toStringCalled, false, "BigInt.prototype.toString will not be called");
+ assert(compareArray(result, [3n, 20n, 100n]));
+});
+
+reportCompare(0, 0);
diff --git a/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.js
new file mode 100644
index 0000000000..a56f0c442a
--- /dev/null
+++ b/js/src/tests/test262/built-ins/TypedArray/prototype/sort/BigInt/sorted-values.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.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");
+});
+
+var sample = new BigInt64Array([-4n, 3n, 4n, -3n, 2n, -2n, 1n, 0n]).sort();
+assert(compareArray(sample, [-4n, -3n, -2n, 0n, 1n, 2n, 3n, 4n]), "negative values");
+
+reportCompare(0, 0);