diff --git a/js/src/builtin/Array.js b/js/src/builtin/Array.js index 9d68012f0b9b..65f4b6d658e8 100644 --- a/js/src/builtin/Array.js +++ b/js/src/builtin/Array.js @@ -1324,63 +1324,64 @@ SetIsInlinableLargeFunction(ArrayAt); // https://github.com/tc39/proposal-change-array-by-copy // Array.prototype.toReversed() function ArrayToReversed() { - /* Step 1. Let O be ? ToObject(this value). */ + // Step 1. Let O be ? ToObject(this value). var O = ToObject(this); - /* Step 2. Let len be ? LengthOfArrayLike(O). */ + // Step 2. Let len be ? LengthOfArrayLike(O). var len = ToLength(O.length); - /* Step 3. Let A be ArrayCreate(𝔽(len)). */ + // Step 3. Let A be ArrayCreate(𝔽(len)). var A = std_Array(len); - /* Step 4. Let k be 0. */ - /* Step 5. Repeat, while k < len, */ + // Step 4. Let k be 0. + // Step 5. Repeat, while k < len, for (var k = 0; k < len; k++) { - /* Step 5a. Let from be ! ToString(𝔽(len - k - 1)). */ + // Step 5.a. Let from be ! ToString(𝔽(len - k - 1)). var from = len - k - 1; - /* Skip Step 5b. Let Pk be ToString(𝔽(k)). - * k is coerced into a string through the property access. */ - /* Step 5c. Let fromValue be ? Get(O, from). */ + + // Skip Step 5.b. Let Pk be ToString(𝔽(k)). + // k is coerced into a string through the property access. + + // Step 5.c. Let fromValue be ? Get(O, from). var fromValue = O[from]; - /* Step 5d. Perform ! CreateDataPropertyOrThrow(A, 𝔽(k), fromValue. */ + + // Step 5.d. Perform ! CreateDataPropertyOrThrow(A, 𝔽(k), fromValue). DefineDataProperty(A, k, fromValue); } - /* Step 6. Return A. */ + // Step 6. Return A. return A; } // https://github.com/tc39/proposal-change-array-by-copy // Array.prototype.toSorted() function ArrayToSorted(comparefn) { - /* Step 1. If comparefn is not undefined and IsCallable(comparefn) is - * false, throw a TypeError exception. - */ + // Step 1. If comparefn is not undefined and IsCallable(comparefn) is + // false, throw a TypeError exception. if (comparefn !== undefined && !IsCallable(comparefn)) { ThrowTypeError(JSMSG_BAD_TOSORTED_ARG); } - /* Step 2. Let O be ? ToObject(this value). */ + // Step 2. Let O be ? ToObject(this value). var O = ToObject(this); - /* Step 3. Let len be ? LengthOfArrayLike(O) */ + // Step 3. Let len be ? LengthOfArrayLike(O). var len = ToLength(O.length); - /* Step 4. Let A be ? ArrayCreate(𝔽(len)). */ + // Step 4. Let A be ? ArrayCreate(𝔽(len)). var items = std_Array(len); - /* We depart from steps 5-8 of the spec for performance reasons, as - * following the spec would require copying the input array twice. - * Instead, we create a new array that replaces holes with undefined, - * and sort this array. - */ + // We depart from steps 5-8 of the spec for performance reasons, as + // following the spec would require copying the input array twice. + // Instead, we create a new array that replaces holes with undefined, + // and sort this array. for (var k = 0; k < len; k++) { DefineDataProperty(items, k, O[k]); } callFunction(ArraySort, items, comparefn); - /* Step 9. Return A */ + // Step 9. Return A. return items; } @@ -1389,13 +1390,13 @@ function ArrayToSorted(comparefn) { // https://github.com/tc39/proposal-array-find-from-last // Array.prototype.findLast ( predicate, thisArg ) function ArrayFindLast(predicate /*, thisArg*/) { - /* Steps 1. */ + // Step 1. var O = ToObject(this); - /* Steps 2. */ + // Step 2. var len = ToLength(O.length); - /* Step 3. */ + // Step 3. if (arguments.length === 0) { ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "Array.prototype.findLast"); } @@ -1403,32 +1404,33 @@ function ArrayFindLast(predicate /*, thisArg*/) { ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate)); } - var T = arguments.length > 1 ? arguments[1] : undefined; + var thisArg = arguments.length > 1 ? arguments[1] : undefined; - /* Step 4-5. */ + // Steps 4-5. for (var k = len - 1; k >= 0; k--) { - /* Steps 5.a-b. */ + // Steps 5.a-b. var kValue = O[k]; - /* Steps 5.c-d. */ - if (callContentFunction(predicate, T, kValue, k, O)) { + + // Steps 5.c-d. + if (callContentFunction(predicate, thisArg, kValue, k, O)) { return kValue; } } - /* Step 6. */ + // Step 6. return undefined; } // https://github.com/tc39/proposal-array-find-from-last // Array.prototype.findLastIndex ( predicate, thisArg ) function ArrayFindLastIndex(predicate /*, thisArg*/) { - /* Steps 1. */ + // Step 1. var O = ToObject(this); - /* Steps 2. */ + // Steps 2. var len = ToLength(O.length); - /* Step 3. */ + // Step 3. if (arguments.length === 0) { ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "Array.prototype.findLastIndex"); } @@ -1436,18 +1438,19 @@ function ArrayFindLastIndex(predicate /*, thisArg*/) { ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate)); } - var T = arguments.length > 1 ? arguments[1] : undefined; + var thisArg = arguments.length > 1 ? arguments[1] : undefined; - /* Step 4-5. */ + // Steps 4-5. for (var k = len - 1; k >= 0; k--) { - /* Steps 5.a-b. */ + // Steps 5.a-b. var kValue = O[k]; - /* Steps 5.c-d. */ - if (callContentFunction(predicate, T, kValue, k, O)) { + + // Steps 5.c-d. + if (callContentFunction(predicate, thisArg, kValue, k, O)) { return k; } } - /* Step 6. */ + // Step 6. return -1; }