Skip to content

Commit

Permalink
Reduce l_nth references
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Feb 14, 2025
1 parent e5d8fa5 commit cc6c093
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 53 deletions.
24 changes: 8 additions & 16 deletions JS-Interpreters/ecmaref6/section 18/section_18.esl
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ function GlobalObjectIsNaN(globalObject, this, NewTarget, strict, params) {
* When the isFinite function is called with one argument x, the following steps are taken:
*/
function GlobalObjectIsFinite(globalObject, this, NewTarget, strict, params) {
num := l_nth(params, 0);
num := hd params;
/* Returns false if the argument coerces to NaN, +Infinity, or -Infinity, and otherwise returns true. */

/* 1. Let num be ToNumber(number). */
num := ToNumber(num);
/* 2. ReturnIfAbrupt(num). */
@ReturnIfAbrupt(num);
/* 3. If num is NaN, +∞, or −∞, return false. */
if ((is_NaN (num)) ||| (num == Infinity) ||| (num == -Infinity))
if ((is_NaN(num)) ||| (num == Infinity) ||| (num == -Infinity))
return false;
/* 4. Otherwise, return true. */
return true;
Expand Down Expand Up @@ -366,8 +366,8 @@ function containsInvalidDigit(str, radix) {

while (i < str_len) {
char := s_nth_u(str, i);
index := indexOfChar(char);
if (index == -1 ||| index >= radixInt)
index := to_char_code_u(char) - to_char_code("0");
if (index >= radixInt)
return true;
i:= i + 1;
}
Expand Down Expand Up @@ -404,22 +404,14 @@ function isSpaceCharacter(c) {
"\u{2001}", "\u{2002}", "\u{2003}", "\u{2004}", "\u{2005}", "\u{2006}", "\u{2007}",
"\u{2008}", "\u{2009}", "\u{200A}", "\u{202F}", "\u{205F}", "\u{3000}", "\n", "\r",
"\u{2028}", "\u{2029}"];
foreach (s : spaces)
if (s == c)
return true;
return false;
return in_list(c, spaces);
}

function indexOfChar(char) {
chars := [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
];
chars := "0123456789abcdefghijklmnopqrstuvwxyz";
i := 0;

while (i < 36) {
if (to_lower_case(char) == l_nth(chars, i))
if (to_lower_case(char) == s_nth(chars, i))
return i;
i := i + 1;
}
Expand All @@ -434,7 +426,7 @@ function mathIntegerOf(str, radix) {

while (i > 0) {
char := s_nth_u(str, i - 1);
charValue := indexOfChar(char);
charValue := to_char_code_u(char) - to_char_code("0");
value := value + ((radix ** (int_to_float (str_len - i))) * (int_to_float charValue));
i := i - 1;
}
Expand Down
30 changes: 15 additions & 15 deletions JS-Interpreters/ecmaref6/section 21/section_21.1.esl
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function StringPrototypecharAt(global, this, NewTarget, strict, args) {
function StringPrototypecharCodeAt(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
pos := l_nth(args, 0);
pos := hd args;
else
pos := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand All @@ -562,7 +562,7 @@ function StringPrototypecharCodeAt(global, this, NewTarget, strict, args) {
function StringPrototypecodePointAt(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
pos := l_nth(args, 0);
pos := hd args;
else
pos := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -626,7 +626,7 @@ function StringPrototypeconcat(global, this, NewTarget, strict, args) {
function StringPrototypeendsWith(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
searchString := l_nth(args, 0);
searchString := hd args;
else
searchString := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -686,7 +686,7 @@ function StringPrototypeendsWith(global, this, NewTarget, strict, args) {
function StringPrototypeincludes(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
searchString := l_nth(args, 0);
searchString := hd args;
else
searchString := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -749,7 +749,7 @@ function includes(S, searchStr, start, searchLength, len) {
function StringPrototypeindexOf(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
searchString := l_nth(args, 0);
searchString := hd args;
else
searchString := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -804,7 +804,7 @@ function StringPrototypeindexOf(global, this, NewTarget, strict, args) {
function StringPrototypelastIndexOf(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
searchString := l_nth(args, 0);
searchString := hd args;
else
searchString := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -868,7 +868,7 @@ function StringPrototypelastIndexOf(global, this, NewTarget, strict, args) {
function StringPrototypelocaleCompare(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
that := l_nth(args, 0);
that := hd args;
else
that := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -921,7 +921,7 @@ function StringPrototypelocaleCompare(global, this, NewTarget, strict, args) {
function StringPrototypeMatch(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
regexp := l_nth(args, 0);
regexp := hd args;
else
regexp := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -969,7 +969,7 @@ function StringPrototypeMatch(global, this, NewTarget, strict, args) {
function StringPrototypenormalize(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
form := l_nth(args, 0);
form := hd args;
else
form := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -998,7 +998,7 @@ function StringPrototypenormalize(global, this, NewTarget, strict, args) {
function StringPrototyperepeat(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
count := l_nth(args, 0);
count := hd args;
else
count := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -1279,7 +1279,7 @@ function GetSubstitution(matched, str, position, captures, replacement, global,
function StringPrototypeSearch(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
regexp := l_nth(args, 0);
regexp := hd args;
else
regexp := 'undefined;
/* 1. Let O be RequireObjectCoercible(this value). */
Expand Down Expand Up @@ -1313,7 +1313,7 @@ function StringPrototypeSearch(global, this, NewTarget, strict, args) {
function StringPrototypeSlice(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
start := l_nth(args, 0);
start := hd args;
else
start := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -1370,7 +1370,7 @@ function StringPrototypeSlice(global, this, NewTarget, strict, args) {
function StringPrototypeSplit(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
separator := l_nth(args, 0);
separator := hd args;
else
separator := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -1533,7 +1533,7 @@ function SplitMatch(S, q, R) {
function StringPrototypestartsWith(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
searchString := l_nth(args, 0);
searchString := hd args;
else
searchString := 'undefined;
if (n_args >= 2)
Expand Down Expand Up @@ -1588,7 +1588,7 @@ function StringPrototypestartsWith(global, this, NewTarget, strict, args) {
function StringPrototypesubstring(global, this, NewTarget, strict, args) {
n_args := l_len(args);
if (n_args >= 1)
start := l_nth(args, 0);
start := hd args;
else
start := 'undefined;
if (n_args >= 2)
Expand Down
36 changes: 18 additions & 18 deletions JS-Interpreters/ecmaref6/section 22/section_22.2.esl
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ function TypedArrayConstructorBuffer(global, this, NewTarget, strict, buffer, by
* mapfn and thisArg, the following steps are taken:
*/
function TypedArrayFromMethod(global, this, NewTarget, strict, args) {
source := l_nth(args, 0);
source := hd args;
mapfn := getOptionalParam(args, 1);
thisArg := getOptionalParam(args, 2);
/* 1. Let C be the this value. */
Expand Down Expand Up @@ -1146,7 +1146,7 @@ function getTypedArrayByteOffset(global, this, NewTarget, strict, args) {
function TypedArrayCopyWithin(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
target := l_nth(args, 0);
target := hd args;
start := l_nth(args, 1);
end := getOptionalParam(args, 2);
/* 1. Let O be ToObject(this value). */
Expand Down Expand Up @@ -1349,7 +1349,7 @@ function TypedArrayEntries(global, this, NewTarget, strict, args) {
function TypedArrayEvery(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
callbackfn := l_nth(args, 0);
callbackfn := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -1433,7 +1433,7 @@ function TypedArrayEvery(global, this, NewTarget, strict, args) {
function TypedArrayFill(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
value := l_nth(args, 0);
value := hd args;
start := getOptionalParam(args, 1);
end := getOptionalParam(args, 2);
if (start == null) /* shouldn't optional arguments that are not passed default to 'undefined *??* */
Expand Down Expand Up @@ -1500,7 +1500,7 @@ function TypedArrayFill(global, this, NewTarget, strict, args) {
* steps are taken:
*/
function TypedArrayFilter(global, this, NewTarget, strict, args) {
callbackfn := l_nth(args, 0);
callbackfn := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be the this value. */
O := this;
Expand Down Expand Up @@ -1625,7 +1625,7 @@ function TypedArrayFilter(global, this, NewTarget, strict, args) {
function TypedArrayFind(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
predicate := l_nth(args, 0);
predicate := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -1724,7 +1724,7 @@ function TypedArrayFind(global, this, NewTarget, strict, args) {
function TypedArrayFindIndex(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
predicate := l_nth(args, 0);
predicate := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -1814,7 +1814,7 @@ function TypedArrayFindIndex(global, this, NewTarget, strict, args) {
function TypedArrayForEach(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
callbackfn := l_nth(args, 0);
callbackfn := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -1903,7 +1903,7 @@ function TypedArrayForEach(global, this, NewTarget, strict, args) {
function TypedArrayIndexOf(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
searchElement := l_nth(args, 0);
searchElement := hd args;
fromIndex := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -1994,7 +1994,7 @@ function TypedArrayIndexOf(global, this, NewTarget, strict, args) {
function TypedArrayJoin(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
separator := l_nth(args, 0);
separator := hd args;
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
/* 2. ReturnIfAbrupt(O). */
Expand Down Expand Up @@ -2103,7 +2103,7 @@ function TypedArrayKeys(global, this, NewTarget, strict, args) {
function TypedArrayLastIndexOf(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
searchElement := l_nth(args, 0);
searchElement := hd args;
fromIndex := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -2196,7 +2196,7 @@ function getTypedArrayLength(global, this, NewTarget, strict, args) {
* are taken:
*/
function TypedArrayMap(global, this, NewTarget, strict, args) {
callbackfn := l_nth(args, 0);
callbackfn := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be the this value. */
O := this;
Expand Down Expand Up @@ -2309,7 +2309,7 @@ function TypedArrayReduce(global, this, NewTarget, strict, args) {
accumulator := null;
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
callbackfn := l_nth(args, 0);
callbackfn := hd args;
initialValue := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -2443,7 +2443,7 @@ function TypedArrayReduceRight(global, this, NewTarget, strict, args) {
accumulator := null;
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);
callbackfn := l_nth(args, 0);
callbackfn := hd args;
initialValue := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -2645,7 +2645,7 @@ function TypedArrayReverse(global, this, NewTarget, strict, args) {
* The length property of the set method is 1.
*/
function TypedArraySet(global, this, NewTarget, strict, args) {
array := l_nth(args, 0);
array := hd args;
offset := getOptionalParam(args, 1);
if (offset == null)
offset := 'undefined;
Expand Down Expand Up @@ -2873,7 +2873,7 @@ function TypedArraySetTypedArray(global, this, strict, typedArray, offset) {
* following steps are taken:
*/
function TypedArraySlice(global, this, NewTarget, strict, args) {
start := l_nth(args, 0);
start := hd args;
end := l_nth(args, 1);
/* 1. Let O be the this value. */
O := this;
Expand Down Expand Up @@ -3046,7 +3046,7 @@ function TypedArraySome(global, this, NewTarget, strict, args) {
valid := ValidateTypedArray(this);
@ReturnIfAbrupt(valid);

callbackfn := l_nth(args, 0);
callbackfn := hd args;
thisArg := getOptionalParam(args, 1);
/* 1. Let O be ToObject(this value). */
O := ToObject(this);
Expand Down Expand Up @@ -3117,7 +3117,7 @@ function TypedArraySome(global, this, NewTarget, strict, args) {
* sort function. These steps are used instead of the entry steps in 22.1.3.24:
*/
function TypedArraySort(global, this, NewTarget, strict, args) {
comparefn := l_nth(args, 0);
comparefn := hd args;
/* 1. Let obj be the this value as the argument. */
obj := this;
/* 2. Let buffer be ValidateTypedArray(obj). */
Expand Down
8 changes: 4 additions & 4 deletions JS-Interpreters/ecmaref6/section 23/section_23.3.esl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function WeakMapConstructor(global, this, NewTarget, strict, items) {

/* 23.3.3.2 WeakMap.prototype.delete ( key ) */
function weakMapDeleteObject(global, this, NewTarget, strict, args) {
key := l_nth(args, 0);
key := hd args;

/* 1. Let M be the this value. */
M := this;
Expand Down Expand Up @@ -263,7 +263,7 @@ function weakMapDeleteObject(global, this, NewTarget, strict, args) {

/* 23.3.3.3 WeakMap.prototype.get ( key ) */
function weakMapGetObject(global, this, NewTarget, strict, args) {
key := l_nth(args, 0);
key := hd args;

/* 1. Let M be the this value. */
M := this;
Expand Down Expand Up @@ -291,7 +291,7 @@ function weakMapGetObject(global, this, NewTarget, strict, args) {

/* 23.3.3.4 WeakMap.prototype.has ( key ) */
function weakMapHasObject(global, this, NewTarget, strict, args) {
key := l_nth(args, 0);
key := hd args;

/* 1. Let M be the this value. */
M := this;
Expand All @@ -318,7 +318,7 @@ function weakMapHasObject(global, this, NewTarget, strict, args) {

/* 23.3.3.5 WeakMap.prototype.set ( key , value ) */
function weakMapSetObject(global, this, NewTarget, strict, args) {
key := l_nth(args, 0);
key := hd args;
value := l_nth(args, 1);

/* 1. Let M be the this value. */
Expand Down

0 comments on commit cc6c093

Please sign in to comment.