-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch_remove_Array-group.diff
More file actions
161 lines (158 loc) · 5.14 KB
/
patch_remove_Array-group.diff
File metadata and controls
161 lines (158 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
diff --git a/js/src/builtin/Array.cpp b/js/src/builtin/Array.cpp
--- a/js/src/builtin/Array.cpp
+++ b/js/src/builtin/Array.cpp
@@ -4584,10 +4584,7 @@ static const JSFunctionSpec array_method
JS_SELF_HOSTED_FN("forEach", "ArrayForEach", 1, 0),
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),
-#endif
+
JS_SELF_HOSTED_FN("reduce", "ArrayReduce", 1, 0),
JS_SELF_HOSTED_FN("reduceRight", "ArrayReduceRight", 1, 0),
JS_SELF_HOSTED_FN("some", "ArraySome", 1, 0),
diff --git a/js/src/builtin/Array.js b/js/src/builtin/Array.js
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -271,142 +271,7 @@ function ArrayFilter(callbackfn /*, this
return A;
}
-#ifdef NIGHTLY_BUILD
-// Array Grouping proposal
-//
-// Array.prototype.group
-// https://tc39.es/proposal-array-grouping/#sec-array.prototype.group
-function ArrayGroup(callbackfn /*, thisArg*/) {
- /* Step 1. Let O be ? ToObject(this value). */
- var O = ToObject(this);
- /* Step 2. Let len be ? LengthOfArrayLike(O). */
- var len = ToLength(O.length);
-
- /* Step 3. If IsCallable(callbackfn) is false, throw a TypeError exception. */
- if (!IsCallable(callbackfn)) {
- ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
- }
-
- /* Step 5. Let groups be a new empty List. */
- // Not applicable in our implementation.
-
- /* Step 7. Let obj be ! OrdinaryObjectCreate(null). */
- var object = std_Object_create(null);
-
- var thisArg = arguments.length > 1 ? arguments[1] : undefined;
-
- /* Steps 4, 6. */
- for (var k = 0; k < len; k++) {
- /* Skip Step 6.a. Let Pk be ! ToString(𝔽(k)).
- *
- * k is coerced into a string through the property access. */
-
- /* Step 6.b. Let kValue be ? Get(O, Pk). */
- var kValue = O[k];
-
- /* Step 6.c.
- * Let propertyKey be ? ToPropertyKey(
- * ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »)).
- */
- var propertyKey = TO_PROPERTY_KEY(
- callContentFunction(callbackfn, thisArg, kValue, k, O)
- );
-
- /* Step 6.d. Perform ! AddValueToKeyedGroup(groups, propertyKey, kValue). */
- var elements = object[propertyKey];
- if (elements === undefined) {
- DefineDataProperty(object, propertyKey, [kValue]);
- } else {
- DefineDataProperty(elements, elements.length, kValue);
- }
- }
-
- /* Step 8. For each Record { [[Key]], [[Elements]] } g of groups, do
- * a. Let elements be ! CreateArrayFromList(g.[[Elements]]).
- * b. Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements).
- */
- // Not applicable in our implementation.
-
- /* Step 9. Return obj. */
- return object;
-}
-
-// Array Grouping proposal
-//
-// Array.prototype.groupToMap
-// https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap
-function ArrayGroupToMap(callbackfn /*, thisArg*/) {
- /* Step 1. Let O be ? ToObject(this value). */
- var O = ToObject(this);
-
- /* Step 2. Let len be ? LengthOfArrayLike(O). */
- var len = ToLength(O.length);
-
- /* Step 3.
- * If IsCallable(callbackfn) is false, throw a TypeError exception.
- */
- if (!IsCallable(callbackfn)) {
- ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
- }
-
- /* Skipping Step 5. Let groups be a new empty List.
- *
- * Intermediate object isn't necessary as we have direct access
- * to the map constructor and set/get methods.
- */
-
- /* Step 7. Let map be ! Construct(%Map%). */
- var C = GetBuiltinConstructor("Map");
- var map = new C();
-
- var thisArg = arguments.length > 1 ? arguments[1] : undefined;
-
- /* Combine Step 6. and Step 8.
- *
- * We have direct access to the map constructor and set/get methods.
- * We can treat these two loops as one, as there isn't a risk that user
- * polyfilling will impact the implementation.
- */
- for (var k = 0; k < len; k++) {
- /* Skipping Step 6.a. Let Pk be ! ToString(𝔽(k)).
- *
- * Value is coerced to String by property access in step 6.b.
- */
-
- /* Step 6.b. Let kValue be ? Get(O, Pk). */
- var kValue = O[k];
-
- /* Step 6.c.
- * Let key be ? Call(callbackfn, thisArg, « kValue, 𝔽(k), O »).
- */
- var key = callContentFunction(callbackfn, thisArg, kValue, k, O);
-
- /* Skipping Step 6.d. If key is -0𝔽, set key to +0𝔽.
- *
- * This step is performed by std_Map_set.
- */
-
- /* Step 8.c. Append entry as the last element of map.[[MapData]].
- *
- * We are not using an intermediate object to store the values.
- * So, this step applies it directly to the map object. Skips steps
- * 6.e (Perform ! AddValueToKeyedGroup(groups, key, kValue))
- * and 8.a-b as a result.
- */
- var elements = callFunction(std_Map_get, map, key);
- if (elements === undefined) {
- callFunction(std_Map_set, map, key, [kValue]);
- } else {
- DefineDataProperty(elements, elements.length, kValue);
- }
- }
-
- /* Step 9. Return map. */
- return map;
-}
-
-#endif
/* ES5 15.4.4.21. */
function ArrayReduce(callbackfn /*, initialValue*/) {