зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 7e22fe4b498e (bug 1773471) for causing mochitest failures in test_xrayToJS.xhtml CLOSED TREE
This commit is contained in:
Родитель
0ce342241d
Коммит
d55e818499
|
@ -4379,8 +4379,8 @@ static const JSFunctionSpec array_methods[] = {
|
|||
JS_SELF_HOSTED_FN("map", "ArrayMap", 1, 0),
|
||||
JS_SELF_HOSTED_FN("filter", "ArrayFilter", 1, 0),
|
||||
#ifdef NIGHTLY_BUILD
|
||||
JS_SELF_HOSTED_FN("group", "ArrayGroup", 1, 0),
|
||||
JS_SELF_HOSTED_FN("groupToMap", "ArrayGroupToMap", 1, 0),
|
||||
JS_SELF_HOSTED_FN("groupBy", "ArrayGroupBy", 1, 0),
|
||||
JS_SELF_HOSTED_FN("groupByToMap", "ArrayGroupByToMap", 1, 0),
|
||||
#endif
|
||||
JS_SELF_HOSTED_FN("reduce", "ArrayReduce", 1, 0),
|
||||
JS_SELF_HOSTED_FN("reduceRight", "ArrayReduceRight", 1, 0),
|
||||
|
|
|
@ -233,7 +233,7 @@ function ArrayFilter(callbackfn/*, thisArg*/) {
|
|||
//
|
||||
// Array.prototype.groupBy
|
||||
// https://tc39.es/proposal-array-grouping/#sec-array.prototype.groupby
|
||||
function ArrayGroup(callbackfn/*, thisArg*/) {
|
||||
function ArrayGroupBy(callbackfn/*, thisArg*/) {
|
||||
/* Step 1. Let O be ? ToObject(this value). */
|
||||
var O = ToObject(this);
|
||||
|
||||
|
@ -295,9 +295,9 @@ function ArrayGroup(callbackfn/*, thisArg*/) {
|
|||
|
||||
// Array Grouping proposal
|
||||
//
|
||||
// Array.prototype.groupToMap
|
||||
// Array.prototype.groupByToMap
|
||||
// https://tc39.es/proposal-array-grouping/#sec-array.prototype.groupbymap
|
||||
function ArrayGroupToMap(callbackfn/*, thisArg*/) {
|
||||
function ArrayGroupByToMap(callbackfn/*, thisArg*/) {
|
||||
|
||||
/* Step 1. Let O be ? ToObject(this value). */
|
||||
var O = ToObject(this);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// |reftest| shell-option(--enable-array-grouping) skip-if(release_or_beta)
|
||||
|
||||
var BUGNUMBER = 1739648;
|
||||
var summary = "Implement Array.prototype.groupToMap || group";
|
||||
var summary = "Implement Array.prototype.groupByToMap || groupBy";
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
|
@ -17,8 +17,8 @@ function isNeg(x) {
|
|||
const expectedObj = { neg: [-Infinity, -2, -1, -0], pos: [0, 1, 2, Infinity] };
|
||||
Object.setPrototypeOf(expectedObj, null);
|
||||
|
||||
const groupedArray = a1.group(x => isNeg(x) ? 'neg' : 'pos');
|
||||
const mappedArray = a1.groupToMap(x => isNeg(x) ? 'neg' : 'pos');
|
||||
const groupedArray = a1.groupBy(x => isNeg(x) ? 'neg' : 'pos');
|
||||
const mappedArray = a1.groupByToMap(x => isNeg(x) ? 'neg' : 'pos');
|
||||
|
||||
assertEq(Object.getPrototypeOf(groupedArray), null)
|
||||
assertDeepEq(groupedArray, expectedObj);
|
||||
|
@ -28,23 +28,23 @@ function isNeg(x) {
|
|||
|
||||
const expectedObj2 = {"undefined": [1,2,3]}
|
||||
Object.setPrototypeOf(expectedObj2, null);
|
||||
assertDeepEq([1,2,3].group(() => {}), expectedObj2);
|
||||
assertDeepEq([].group(() => {}), Object.create(null));
|
||||
assertDeepEq(([1,2,3].groupToMap(() => {})).get(undefined), [1,2,3]);
|
||||
assertEq(([1,2,3].groupToMap(() => {})).size, 1);
|
||||
assertDeepEq([1,2,3].groupBy(() => {}), expectedObj2);
|
||||
assertDeepEq([].groupBy(() => {}), Object.create(null));
|
||||
assertDeepEq(([1,2,3].groupByToMap(() => {})).get(undefined), [1,2,3]);
|
||||
assertEq(([1,2,3].groupByToMap(() => {})).size, 1);
|
||||
|
||||
const negMappedArray = a1.groupToMap(x => isNeg(x) ? -0 : 0);
|
||||
const negMappedArray = a1.groupByToMap(x => isNeg(x) ? -0 : 0);
|
||||
assertDeepEq(negMappedArray.get(0), a1);
|
||||
assertDeepEq(negMappedArray.size, 1);
|
||||
|
||||
assertThrowsInstanceOf(() => [].group(undefined), TypeError);
|
||||
assertThrowsInstanceOf(() => [].group(null), TypeError);
|
||||
assertThrowsInstanceOf(() => [].group(0), TypeError);
|
||||
assertThrowsInstanceOf(() => [].group(""), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupToMap(undefined), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupToMap(null), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupToMap(0), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupToMap(""), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupBy(undefined), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupBy(null), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupBy(0), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupBy(""), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupByToMap(undefined), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupByToMap(null), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupByToMap(0), TypeError);
|
||||
assertThrowsInstanceOf(() => [].groupByToMap(""), TypeError);
|
||||
}
|
||||
|
||||
const array = [ 'test' ];
|
||||
|
@ -60,7 +60,7 @@ Object.defineProperty(Map.prototype, 4, {
|
|||
}
|
||||
});
|
||||
|
||||
const map1 = array.groupToMap(key => key.length);
|
||||
const map1 = array.groupByToMap(key => key.length);
|
||||
|
||||
assertEq('test', map1.get(4)[0])
|
||||
|
||||
|
@ -73,8 +73,8 @@ Object.defineProperty(Array.prototype, '4', {
|
|||
}
|
||||
});
|
||||
|
||||
const map2 = array.groupToMap(key => key.length);
|
||||
const arr = array.group(key => key.length);
|
||||
const map2 = array.groupByToMap(key => key.length);
|
||||
const arr = array.groupBy(key => key.length);
|
||||
|
||||
assertEq('test', map2.get(4)[0])
|
||||
assertEq('test', arr[4][0])
|
||||
|
@ -83,13 +83,13 @@ Object.defineProperty(Object.prototype, "foo", {
|
|||
get() { throw new Error("user observable object get"); },
|
||||
set(v) { throw new Error("user observable object set"); }
|
||||
});
|
||||
[1, 2, 3].group(() => 'foo');
|
||||
[1, 2, 3].groupBy(() => 'foo');
|
||||
|
||||
// Ensure property key is correctly accessed
|
||||
count = 0;
|
||||
p = [1].group(() => ({ toString() { count++; return 10 } }));
|
||||
p = [1].groupBy(() => ({ toString() { count++; return 10 } }));
|
||||
assertEq(count, 1);
|
||||
[1].groupToMap(() => ({ toString() { count++; return 10 } }));
|
||||
[1].groupByToMap(() => ({ toString() { count++; return 10 } }));
|
||||
assertEq(count, 1);
|
||||
|
||||
reportCompare(0, 0);
|
||||
|
|
Загрузка…
Ссылка в новой задаче