Merge pull request #1687 from leobalter/fix-tests-flat

some quick fixes for Array.prototype.{flat,flatMap} tests
This commit is contained in:
Leo Balter 2018-08-20 12:12:54 -04:00 committed by GitHub
commit 9cb6333cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 105 additions and 45 deletions

View File

@ -16,16 +16,16 @@ var a = getArgumentsObject([1], [2]);
var actual = [].flat.call(a);
assert.compareArray(actual, [1, 2], 'arguments objects');
var a = {
a = {
length: 1,
0: [1],
};
var actual = [].flat.call(a);
actual = [].flat.call(a);
assert.compareArray(actual, [1], 'array-like objects');
var a = {
a = {
length: undefined,
0: [1],
};
var actual = [].flat.call(a);
actual = [].flat.call(a);
assert.compareArray(actual, [], 'array-like objects; undefined length');

View File

@ -14,6 +14,8 @@ assert.sameValue(
'The value of `Array.prototype.flat.length` is `0`'
);
verifyNotEnumerable(Array.prototype.flat, 'length');
verifyNotWritable(Array.prototype.flat, 'length');
verifyConfigurable(Array.prototype.flat, 'length');
verifyProperty(Array.prototype.flat, 'length', {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -15,6 +15,8 @@ assert.sameValue(
'The value of `Array.prototype.flat.name` is `"flat"`'
);
verifyNotEnumerable(Array.prototype.flat, 'name');
verifyNotWritable(Array.prototype.flat, 'name');
verifyConfigurable(Array.prototype.flat, 'name');
verifyProperty(Array.prototype.flat, 'name', {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -17,27 +17,27 @@ var actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'non integral string depthNum');
// object type depthNum is converted to 0
var depthNum = {};
var actual = a.flat(depthNum);
depthNum = {};
actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'object type depthNum');
// negative infinity depthNum is converted to 0
var depthNum = Number.NEGATIVE_INFINITY;
var actual = a.flat(depthNum);
depthNum = Number.NEGATIVE_INFINITY;
actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'negative infinity depthNum');
// positive zero depthNum is converted to 0
var depthNum = +0;
var actual = a.flat(depthNum);
depthNum = +0;
actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'positive zero depthNum');
// negative zero depthNum is converted to 0
var depthNum = -0;
var actual = a.flat(depthNum);
depthNum = -0;
actual = a.flat(depthNum);
assert(compareArray(actual, expected), 'negative zero depthNum');
// integral string depthNum is converted to an integer
var depthNum = '1';
var actual = a.flat(depthNum);
var expected = [1, 2]
depthNum = '1';
actual = a.flat(depthNum);
expected = [1, 2]
assert(compareArray(actual, expected), 'integral string depthNum');

View File

@ -14,19 +14,19 @@ assert.throws(TypeError, function() {
a.flat();
}, 'null value');
var a = [];
a = [];
a.constructor = 1;
assert.throws(TypeError, function() {
a.flat();
}, 'number value');
var a = [];
a = [];
a.constructor = 'string';
assert.throws(TypeError, function() {
a.flat();
}, 'string value');
var a = [];
a = [];
a.constructor = true;
assert.throws(TypeError, function() {
a.flat();

View File

@ -2,7 +2,6 @@
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-array.prototype.flat
es6id: 22.1.3
description: Property type and descriptor.
info: >
17 ECMAScript Standard Built-in Objects
@ -16,6 +15,8 @@ assert.sameValue(
'`typeof Array.prototype.flat` is `function`'
);
verifyNotEnumerable(Array.prototype, 'flat');
verifyWritable(Array.prototype, 'flat');
verifyConfigurable(Array.prototype, 'flat');
verifyProperty(Array.prototype, 'flat', {
enumerable: false,
writable: true,
configurable: true,
});

View File

@ -4,11 +4,23 @@
esid: sec-array.prototype.flat
description: >
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]
includes: [compareArray.js]
---*/
const getCalls = [], hasCalls = [];
const handler = {
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },

View File

@ -20,16 +20,16 @@ var a = getArgumentsObject(1, 2);
var actual = [].flatMap.call(a, double);
assert.compareArray(actual, [2, 4], 'arguments objects');
var a = {
a = {
length: 1,
0: 1,
};
var actual = [].flatMap.call(a, double);
actual = [].flatMap.call(a, double);
assert.compareArray(actual, [2], 'array-like objects');
var a = {
a = {
length: void 0,
0: 1,
};
var actual = [].flatMap.call(a, double);
actual = [].flatMap.call(a, double);
assert.compareArray(actual, [], 'array-like objects; undefined length');

View File

@ -14,6 +14,8 @@ assert.sameValue(
'The value of `Array.prototype.flatmap.length` is `1`'
);
verifyNotEnumerable(Array.prototype.flatMap, 'length');
verifyNotWritable(Array.prototype.flatMap, 'length');
verifyConfigurable(Array.prototype.flatMap, 'length');
verifyProperty(Array.prototype.flatMap, 'length', {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -14,6 +14,8 @@ assert.sameValue(
'The value of `Array.prototype.flatMap.name` is `"flatMap"`'
);
verifyNotEnumerable(Array.prototype.flatMap, 'name');
verifyNotWritable(Array.prototype.flatMap, 'name');
verifyConfigurable(Array.prototype.flatMap, 'name');
verifyProperty(Array.prototype.flatMap, 'name', {
enumerable: false,
writable: false,
configurable: true,
});

View File

@ -14,19 +14,19 @@ assert.throws(TypeError, function() {
a.flatMap();
}, 'null value');
var a = [];
a = [];
a.constructor = 1;
assert.throws(TypeError, function() {
a.flatMap();
}, 'number value');
var a = [];
a = [];
a.constructor = 'string';
assert.throws(TypeError, function() {
a.flatMap();
}, 'string value');
var a = [];
a = [];
a.constructor = true;
assert.throws(TypeError, function() {
a.flatMap();

View File

@ -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,
});

View File

@ -4,11 +4,23 @@
esid: sec-array.prototype.flatMap
description: >
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]
includes: [compareArray.js]
---*/
const getCalls = [], hasCalls = [];
const handler = {
get : function (t, p, r) { getCalls.push(p); return Reflect.get(t, p, r); },