mirror of https://github.com/tc39/test262.git
Merge pull request #1687 from leobalter/fix-tests-flat
some quick fixes for Array.prototype.{flat,flatMap} tests
This commit is contained in:
commit
9cb6333cb9
|
@ -16,16 +16,16 @@ var a = getArgumentsObject([1], [2]);
|
||||||
var actual = [].flat.call(a);
|
var actual = [].flat.call(a);
|
||||||
assert.compareArray(actual, [1, 2], 'arguments objects');
|
assert.compareArray(actual, [1, 2], 'arguments objects');
|
||||||
|
|
||||||
var a = {
|
a = {
|
||||||
length: 1,
|
length: 1,
|
||||||
0: [1],
|
0: [1],
|
||||||
};
|
};
|
||||||
var actual = [].flat.call(a);
|
actual = [].flat.call(a);
|
||||||
assert.compareArray(actual, [1], 'array-like objects');
|
assert.compareArray(actual, [1], 'array-like objects');
|
||||||
|
|
||||||
var a = {
|
a = {
|
||||||
length: undefined,
|
length: undefined,
|
||||||
0: [1],
|
0: [1],
|
||||||
};
|
};
|
||||||
var actual = [].flat.call(a);
|
actual = [].flat.call(a);
|
||||||
assert.compareArray(actual, [], 'array-like objects; undefined length');
|
assert.compareArray(actual, [], 'array-like objects; undefined length');
|
||||||
|
|
|
@ -14,6 +14,8 @@ assert.sameValue(
|
||||||
'The value of `Array.prototype.flat.length` is `0`'
|
'The value of `Array.prototype.flat.length` is `0`'
|
||||||
);
|
);
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype.flat, 'length');
|
verifyProperty(Array.prototype.flat, 'length', {
|
||||||
verifyNotWritable(Array.prototype.flat, 'length');
|
enumerable: false,
|
||||||
verifyConfigurable(Array.prototype.flat, 'length');
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
|
@ -15,6 +15,8 @@ assert.sameValue(
|
||||||
'The value of `Array.prototype.flat.name` is `"flat"`'
|
'The value of `Array.prototype.flat.name` is `"flat"`'
|
||||||
);
|
);
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype.flat, 'name');
|
verifyProperty(Array.prototype.flat, 'name', {
|
||||||
verifyNotWritable(Array.prototype.flat, 'name');
|
enumerable: false,
|
||||||
verifyConfigurable(Array.prototype.flat, 'name');
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
|
@ -17,27 +17,27 @@ var actual = a.flat(depthNum);
|
||||||
assert(compareArray(actual, expected), 'non integral string depthNum');
|
assert(compareArray(actual, expected), 'non integral string depthNum');
|
||||||
|
|
||||||
// object type depthNum is converted to 0
|
// object type depthNum is converted to 0
|
||||||
var depthNum = {};
|
depthNum = {};
|
||||||
var actual = a.flat(depthNum);
|
actual = a.flat(depthNum);
|
||||||
assert(compareArray(actual, expected), 'object type depthNum');
|
assert(compareArray(actual, expected), 'object type depthNum');
|
||||||
|
|
||||||
// negative infinity depthNum is converted to 0
|
// negative infinity depthNum is converted to 0
|
||||||
var depthNum = Number.NEGATIVE_INFINITY;
|
depthNum = Number.NEGATIVE_INFINITY;
|
||||||
var actual = a.flat(depthNum);
|
actual = a.flat(depthNum);
|
||||||
assert(compareArray(actual, expected), 'negative infinity depthNum');
|
assert(compareArray(actual, expected), 'negative infinity depthNum');
|
||||||
|
|
||||||
// positive zero depthNum is converted to 0
|
// positive zero depthNum is converted to 0
|
||||||
var depthNum = +0;
|
depthNum = +0;
|
||||||
var actual = a.flat(depthNum);
|
actual = a.flat(depthNum);
|
||||||
assert(compareArray(actual, expected), 'positive zero depthNum');
|
assert(compareArray(actual, expected), 'positive zero depthNum');
|
||||||
|
|
||||||
// negative zero depthNum is converted to 0
|
// negative zero depthNum is converted to 0
|
||||||
var depthNum = -0;
|
depthNum = -0;
|
||||||
var actual = a.flat(depthNum);
|
actual = a.flat(depthNum);
|
||||||
assert(compareArray(actual, expected), 'negative zero depthNum');
|
assert(compareArray(actual, expected), 'negative zero depthNum');
|
||||||
|
|
||||||
// integral string depthNum is converted to an integer
|
// integral string depthNum is converted to an integer
|
||||||
var depthNum = '1';
|
depthNum = '1';
|
||||||
var actual = a.flat(depthNum);
|
actual = a.flat(depthNum);
|
||||||
var expected = [1, 2]
|
expected = [1, 2]
|
||||||
assert(compareArray(actual, expected), 'integral string depthNum');
|
assert(compareArray(actual, expected), 'integral string depthNum');
|
||||||
|
|
|
@ -14,19 +14,19 @@ assert.throws(TypeError, function() {
|
||||||
a.flat();
|
a.flat();
|
||||||
}, 'null value');
|
}, 'null value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = 1;
|
a.constructor = 1;
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flat();
|
a.flat();
|
||||||
}, 'number value');
|
}, 'number value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = 'string';
|
a.constructor = 'string';
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flat();
|
a.flat();
|
||||||
}, 'string value');
|
}, 'string value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = true;
|
a.constructor = true;
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flat();
|
a.flat();
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
/*---
|
/*---
|
||||||
esid: sec-array.prototype.flat
|
esid: sec-array.prototype.flat
|
||||||
es6id: 22.1.3
|
|
||||||
description: Property type and descriptor.
|
description: Property type and descriptor.
|
||||||
info: >
|
info: >
|
||||||
17 ECMAScript Standard Built-in Objects
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
@ -16,6 +15,8 @@ assert.sameValue(
|
||||||
'`typeof Array.prototype.flat` is `function`'
|
'`typeof Array.prototype.flat` is `function`'
|
||||||
);
|
);
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype, 'flat');
|
verifyProperty(Array.prototype, 'flat', {
|
||||||
verifyWritable(Array.prototype, 'flat');
|
enumerable: false,
|
||||||
verifyConfigurable(Array.prototype, 'flat');
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
|
@ -3,12 +3,24 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-array.prototype.flat
|
esid: sec-array.prototype.flat
|
||||||
description: >
|
description: >
|
||||||
properties are accessed correct number of times by .flat
|
properties are accessed correct number of times by .flat
|
||||||
|
info: |
|
||||||
|
Array.prototype.flat( [ depth ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, depthNum).
|
||||||
|
|
||||||
|
FlattenIntoArray (target, source, sourceLen, start, depth [ , mapperFunction, thisArg ])
|
||||||
|
|
||||||
|
3. Repeat, while sourceIndex < sourceLen
|
||||||
|
a. Let P be ! ToString(sourceIndex).
|
||||||
|
b. Let exists be ? HasProperty(source, P).
|
||||||
|
c. If exists is true, then
|
||||||
|
i. Let element be ? Get(source, P).
|
||||||
features: [Array.prototype.flat]
|
features: [Array.prototype.flat]
|
||||||
includes: [compareArray.js]
|
includes: [compareArray.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
|
||||||
const getCalls = [], hasCalls = [];
|
const getCalls = [], hasCalls = [];
|
||||||
const handler = {
|
const handler = {
|
||||||
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },
|
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },
|
||||||
|
|
|
@ -20,16 +20,16 @@ var a = getArgumentsObject(1, 2);
|
||||||
var actual = [].flatMap.call(a, double);
|
var actual = [].flatMap.call(a, double);
|
||||||
assert.compareArray(actual, [2, 4], 'arguments objects');
|
assert.compareArray(actual, [2, 4], 'arguments objects');
|
||||||
|
|
||||||
var a = {
|
a = {
|
||||||
length: 1,
|
length: 1,
|
||||||
0: 1,
|
0: 1,
|
||||||
};
|
};
|
||||||
var actual = [].flatMap.call(a, double);
|
actual = [].flatMap.call(a, double);
|
||||||
assert.compareArray(actual, [2], 'array-like objects');
|
assert.compareArray(actual, [2], 'array-like objects');
|
||||||
|
|
||||||
var a = {
|
a = {
|
||||||
length: void 0,
|
length: void 0,
|
||||||
0: 1,
|
0: 1,
|
||||||
};
|
};
|
||||||
var actual = [].flatMap.call(a, double);
|
actual = [].flatMap.call(a, double);
|
||||||
assert.compareArray(actual, [], 'array-like objects; undefined length');
|
assert.compareArray(actual, [], 'array-like objects; undefined length');
|
||||||
|
|
|
@ -14,6 +14,8 @@ assert.sameValue(
|
||||||
'The value of `Array.prototype.flatmap.length` is `1`'
|
'The value of `Array.prototype.flatmap.length` is `1`'
|
||||||
);
|
);
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype.flatMap, 'length');
|
verifyProperty(Array.prototype.flatMap, 'length', {
|
||||||
verifyNotWritable(Array.prototype.flatMap, 'length');
|
enumerable: false,
|
||||||
verifyConfigurable(Array.prototype.flatMap, 'length');
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
|
@ -14,6 +14,8 @@ assert.sameValue(
|
||||||
'The value of `Array.prototype.flatMap.name` is `"flatMap"`'
|
'The value of `Array.prototype.flatMap.name` is `"flatMap"`'
|
||||||
);
|
);
|
||||||
|
|
||||||
verifyNotEnumerable(Array.prototype.flatMap, 'name');
|
verifyProperty(Array.prototype.flatMap, 'name', {
|
||||||
verifyNotWritable(Array.prototype.flatMap, 'name');
|
enumerable: false,
|
||||||
verifyConfigurable(Array.prototype.flatMap, 'name');
|
writable: false,
|
||||||
|
configurable: true,
|
||||||
|
});
|
||||||
|
|
|
@ -14,19 +14,19 @@ assert.throws(TypeError, function() {
|
||||||
a.flatMap();
|
a.flatMap();
|
||||||
}, 'null value');
|
}, 'null value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = 1;
|
a.constructor = 1;
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flatMap();
|
a.flatMap();
|
||||||
}, 'number value');
|
}, 'number value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = 'string';
|
a.constructor = 'string';
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flatMap();
|
a.flatMap();
|
||||||
}, 'string value');
|
}, 'string value');
|
||||||
|
|
||||||
var a = [];
|
a = [];
|
||||||
a.constructor = true;
|
a.constructor = true;
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
a.flatMap();
|
a.flatMap();
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright (C) 2018 Leo Balter. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
esid: sec-array.prototype.flatMap
|
||||||
|
description: Property type and descriptor.
|
||||||
|
info: >
|
||||||
|
17 ECMAScript Standard Built-in Objects
|
||||||
|
|
||||||
|
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]
|
||||||
|
features: [Array.prototype.flatMap]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(
|
||||||
|
typeof Array.prototype.flatMap,
|
||||||
|
'function',
|
||||||
|
'`typeof Array.prototype.flatMap` is `function`'
|
||||||
|
);
|
||||||
|
|
||||||
|
verifyProperty(Array.prototype, 'flatMap', {
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
});
|
|
@ -3,12 +3,24 @@
|
||||||
/*---
|
/*---
|
||||||
esid: sec-array.prototype.flatMap
|
esid: sec-array.prototype.flatMap
|
||||||
description: >
|
description: >
|
||||||
properties are accessed correct number of times by .flatMap
|
properties are accessed correct number of times by .flatMap
|
||||||
|
info: |
|
||||||
|
Array.prototype.flatMap ( mapperFunction [ , thisArg ] )
|
||||||
|
|
||||||
|
...
|
||||||
|
6. Perform ? FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T).
|
||||||
|
|
||||||
|
FlattenIntoArray (target, source, sourceLen, start, depth [ , mapperFunction, thisArg ])
|
||||||
|
|
||||||
|
3. Repeat, while sourceIndex < sourceLen
|
||||||
|
a. Let P be ! ToString(sourceIndex).
|
||||||
|
b. Let exists be ? HasProperty(source, P).
|
||||||
|
c. If exists is true, then
|
||||||
|
i. Let element be ? Get(source, P).
|
||||||
features: [Array.prototype.flat]
|
features: [Array.prototype.flat]
|
||||||
includes: [compareArray.js]
|
includes: [compareArray.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
|
||||||
const getCalls = [], hasCalls = [];
|
const getCalls = [], hasCalls = [];
|
||||||
const handler = {
|
const handler = {
|
||||||
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },
|
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },
|
||||||
|
|
Loading…
Reference in New Issue