|
@@ -219,3 +219,49 @@ func TestUnscopables(t *testing.T) {
|
|
|
`
|
|
|
testScript1(SCRIPT, valueTrue, t)
|
|
|
}
|
|
|
+
|
|
|
+func TestArraySort(t *testing.T) {
|
|
|
+ const SCRIPT = `
|
|
|
+ assert.throws(TypeError, function() {
|
|
|
+ [1,2].sort(null);
|
|
|
+ }, "null compare function");
|
|
|
+ assert.throws(TypeError, function() {
|
|
|
+ [1,2].sort({});
|
|
|
+ }, "non-callable compare function");
|
|
|
+ `
|
|
|
+ testScript1(TESTLIB+SCRIPT, _undefined, t)
|
|
|
+}
|
|
|
+
|
|
|
+func TestArrayConcat(t *testing.T) {
|
|
|
+ const SCRIPT = `
|
|
|
+ var concat = Array.prototype.concat;
|
|
|
+ var array = [1, 2];
|
|
|
+ var sparseArray = [1, , 2];
|
|
|
+ var nonSpreadableArray = [1, 2];
|
|
|
+ nonSpreadableArray[Symbol.isConcatSpreadable] = false;
|
|
|
+ var arrayLike = { 0: 1, 1: 2, length: 2 };
|
|
|
+ var spreadableArrayLike = { 0: 1, 1: 2, length: 2 };
|
|
|
+ spreadableArrayLike[Symbol.isConcatSpreadable] = true;
|
|
|
+ assert(looksNative(concat));
|
|
|
+ assert(deepEqual(array.concat(), [1, 2]), '#1');
|
|
|
+ assert(deepEqual(sparseArray.concat(), [1, , 2]), '#2');
|
|
|
+ assert(deepEqual(nonSpreadableArray.concat(), [[1, 2]]), '#3');
|
|
|
+ assert(deepEqual(concat.call(arrayLike), [{ 0: 1, 1: 2, length: 2 }]), '#4');
|
|
|
+ assert(deepEqual(concat.call(spreadableArrayLike), [1, 2]), '#5');
|
|
|
+ assert(deepEqual([].concat(array), [1, 2]), '#6');
|
|
|
+ assert(deepEqual([].concat(sparseArray), [1, , 2]), '#7');
|
|
|
+ assert(deepEqual([].concat(nonSpreadableArray), [[1, 2]]), '#8');
|
|
|
+ assert(deepEqual([].concat(arrayLike), [{ 0: 1, 1: 2, length: 2 }]), '#9');
|
|
|
+ assert(deepEqual([].concat(spreadableArrayLike), [1, 2]), '#10');
|
|
|
+ assert(deepEqual(array.concat(sparseArray, nonSpreadableArray, arrayLike, spreadableArrayLike), [
|
|
|
+ 1, 2, 1, , 2, [1, 2], { 0: 1, 1: 2, length: 2 }, 1, 2,
|
|
|
+ ]), '#11');
|
|
|
+ array = [];
|
|
|
+ array.constructor = {};
|
|
|
+ array.constructor[Symbol.species] = function () {
|
|
|
+ return { foo: 1 };
|
|
|
+ }
|
|
|
+ assert.sameValue(array.concat().foo, 1, '@@species');
|
|
|
+ `
|
|
|
+ testScript1(TESTLIBX+SCRIPT, _undefined, t)
|
|
|
+}
|