From b2c08f2c71bc18553c9989f59eee7f00e38e6ccb Mon Sep 17 00:00:00 2001 From: Filipe Marques Date: Sat, 1 Feb 2025 13:40:11 +0000 Subject: [PATCH] Apease the typechecker --- .../ecmaref5/section 10/section_10.4.esl | 4 +- .../ecmaref5/section 10/section_10.6.esl | 2 + .../ecmaref5/section 15/section_15.1.esl | 1 + .../ecmaref5/section 15/section_15.12.esl | 2 + .../ecmaref5/section 15/section_15.4.esl | 9 +- .../ecmaref5/section 15/section_15.5.esl | 90 +++++++++---------- .../ecmaref5/section 15/section_15.6.esl | 5 +- .../ecmaref5/section 15/section_15.9_alt.esl | 6 +- .../ecmaref6/section 21/section_21.1.esl | 6 +- .../ecmaref6/section 22/section_22.1.esl | 10 ++- 10 files changed, 75 insertions(+), 60 deletions(-) diff --git a/JS-Interpreters/ecmaref5/section 10/section_10.4.esl b/JS-Interpreters/ecmaref5/section 10/section_10.4.esl index 137283fdbf..4f1f41b255 100644 --- a/JS-Interpreters/ecmaref5/section 10/section_10.4.esl +++ b/JS-Interpreters/ecmaref5/section 10/section_10.4.esl @@ -14,7 +14,7 @@ function EnteringGlobalCode(program) { /* 10.4.1 Entering Global Code */ if ("optimised" in_obj program &&& program.optimised == true) globalObject := optimizeInitGlobalObject(program.strict); - else + else globalObject := initGlobalObject(program.strict); /* The following steps are performed when control enters the execution context for global code: */ @@ -49,11 +49,11 @@ function InitialGlobalExecutionContext(globalObject, program) { /* 10.4.2 Entering Eval Code */ function EnteringEvalCode(evalCode, ref, callingExecCtx) { evalCode.strict := isStrictModeCode(evalCode, callingExecCtx); - /* The following steps are performed when control enters the execution context for eval code: */ /* 1. If there is no calling context or if the eval code is not being evaluated by a direct call (15.1.2.1.1) to the eval function then, */ + evalExecCtx := 'undefined; if (!isDirectCall(ref, callingExecCtx)) { /* a. Initialise the execution context as if it was a global execution context using the eval code as C as described in 10.4.1.1. */ diff --git a/JS-Interpreters/ecmaref5/section 10/section_10.6.esl b/JS-Interpreters/ecmaref5/section 10/section_10.6.esl index dd26d1a2f7..e91306775f 100644 --- a/JS-Interpreters/ecmaref5/section 10/section_10.6.esl +++ b/JS-Interpreters/ecmaref5/section 10/section_10.6.esl @@ -241,6 +241,7 @@ function ArgumentsObjectDelete(argumentsObject, P, Throw) { /* Auxiliary functions */ function makeArgGetterLetBodyAuxFunction(name) { + body := 'undefined; body := lambda (scope, this, strict, args) [name] { envRec := getEnvironmentRecord(scope); val := getBindingValue(envRec, name); @@ -255,6 +256,7 @@ function makeArgSetterLetParamAuxFunction(name) { } function makeArgSetterLetBodyAuxFunction(name, param) { + body := 'undefined; body := lambda (scope, this, strict, args) [name] { param := l_nth(args, 0); envRec := getEnvironmentRecord(scope); diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.1.esl b/JS-Interpreters/ecmaref5/section 15/section_15.1.esl index 9292f31b11..5c118c838a 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.1.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.1.esl @@ -325,6 +325,7 @@ function parseAsProgram(progStr, strict) { } function optimizeInitGlobalObject(strict) { + loc_global := 'undefined; if ((typeof (strict) == "bool") &&& strict) loc_global := extern loadInitialHeap("globalHeap_strict.json"); else diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.12.esl b/JS-Interpreters/ecmaref5/section 15/section_15.12.esl index c7037398d7..67dac29f11 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.12.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.12.esl @@ -950,6 +950,7 @@ function JO(value, stack, indent, gap, PropertyList, ReplacerFunction, space) { } i := i + 1; } + final := ""; /* 9. If partial is empty, then */ if ((l_len(partial)) == 0) { /* a. Let final be "{}". */ @@ -1038,6 +1039,7 @@ function JA(value, stack, indent, gap, PropertyList, ReplacerFunction, space) { index := index + 1.; } /* 9. If partial is empty ,then */ + final := ""; if ((l_len(partial)) == 0) { /* a. Let final be "[]". */ final := "[]"; diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.4.esl b/JS-Interpreters/ecmaref5/section 15/section_15.4.esl index 19747ec894..f85b24e407 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.4.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.4.esl @@ -427,6 +427,7 @@ function arrayToString(global, this, strict, args) { function arrayToLocaleString(global, this, strict, args) { /* 1. Let O be the result of calling ToObject passing the this value as the argument. */ + R := ""; O := ToObject(this); /* 2. Let arrayLen be the result of calling the [[Get]] internal method of array with argument "length". */ @@ -646,9 +647,9 @@ function arrayJoin(global, this, strict, args) { element0 := {O.Get}(O, "0"); /* 8. If element0 is undefined or null, let R be the empty String; otherwise, Let R be ToString(element0). */ - if ((element0 == 'undefined) || (element0 == 'null)) - R := ""; - else + + R := ""; + if ((element0 != 'undefined) &&& (element0 != 'null)) R := ToString(element0); /* 9. Let k be 1. */ k := 1.; @@ -2156,6 +2157,7 @@ function arrayReduce(global, this, strict, args) { throw TypeErrorConstructorInternal(); /* 6. Let k be 0. */ k := 0.; + accumulator := 'undefined; /* 7. If initialValue is present, then */ if (initialValue != null) { /* a. Set accumulator to initialValue. */ @@ -2273,6 +2275,7 @@ function arrayReduceRight(global, this, strict, args) { /* 6. Let k be len-1. */ k := len - 1.; /* 7. If initialValue is present, then */ + accumulator := 'undefined; if (initialValue != null) { /* a. Set accumulator to initialValue. */ accumulator := initialValue; diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.5.esl b/JS-Interpreters/ecmaref5/section 15/section_15.5.esl index c94187663e..21ff4abf7c 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.5.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.5.esl @@ -665,55 +665,53 @@ function StringPrototypeMatch(global, this, strict, args) { return {exec.Call}(null, null, exec, rx, [S]); } /* 8. Else, global is true */ - else { - /* a. Call the [[Put]] internal method of rx with arguments "lastIndex" and 0. */ - {rx.Put}(rx, "lastIndex", 0., true); - /* b. Let A be a new array created as if by the expression new Array() - where Array is the standard built-in constructor with that name. */ - A := ArrayConstructor(global, this, strict, []); - /* c. Let previousLastIndex be 0. */ - previousLastIndex := 0.; - /* d. Let n be 0. */ - n := 0.; - /* e. Let lastMatch be true. */ - lastMatch := true; - /* f. Repeat, while lastMatch is true */ - while (lastMatch == true) { - /* i. Let result be the result of calling the [[Call]] internal method - of exec with rx as the this value and argument list containing S. */ - result := {exec.Call}(null, null, exec, rx, [S]); - /* ii. If result is null, then set lastMatch to false. */ - if (result == 'null) { - lastMatch := false; + /* a. Call the [[Put]] internal method of rx with arguments "lastIndex" and 0. */ + {rx.Put}(rx, "lastIndex", 0., true); + /* b. Let A be a new array created as if by the expression new Array() + where Array is the standard built-in constructor with that name. */ + A := ArrayConstructor(global, this, strict, []); + /* c. Let previousLastIndex be 0. */ + previousLastIndex := 0.; + /* d. Let n be 0. */ + n := 0.; + /* e. Let lastMatch be true. */ + lastMatch := true; + /* f. Repeat, while lastMatch is true */ + while (lastMatch == true) { + /* i. Let result be the result of calling the [[Call]] internal method + of exec with rx as the this value and argument list containing S. */ + result := {exec.Call}(null, null, exec, rx, [S]); + /* ii. If result is null, then set lastMatch to false. */ + if (result == 'null) { + lastMatch := false; + } + /* iii. Else, result is not null */ + else { + /* 1. Let thisIndex be the result of calling the [[Get]] internal + method of rx with argument "lastIndex". */ + thisIndex := {rx.Get}(rx, "lastIndex"); + /* 2. If thisIndex == previousLastIndex then */ + if (thisIndex == previousLastIndex) { + /* a. Call the [[Put]] internal method of rx with arguments + "lastIndex" and thisIndex+1. */ + {rx.Put}(rx, "lastIndex", thisIndex + 1.); + /* b. Set previousLastIndex to thisIndex+1. */ + previousLastIndex := thisIndex + 1.; } - /* iii. Else, result is not null */ + /* 3. Else, set previousLastIndex to thisIndex. */ else { - /* 1. Let thisIndex be the result of calling the [[Get]] internal - method of rx with argument "lastIndex". */ - thisIndex := {rx.Get}(rx, "lastIndex"); - /* 2. If thisIndex == previousLastIndex then */ - if (thisIndex == previousLastIndex) { - /* a. Call the [[Put]] internal method of rx with arguments - "lastIndex" and thisIndex+1. */ - {rx.Put}(rx, "lastIndex", thisIndex + 1.); - /* b. Set previousLastIndex to thisIndex+1. */ - previousLastIndex := thisIndex + 1.; - } - /* 3. Else, set previousLastIndex to thisIndex. */ - else { - previousLastIndex := thisIndex; - } - /* 4. Let matchStr be the result of calling the [[Get]] internal - method of result with argument "0". */ - matchStr := {result.Get}(result, "0"); - /* 5. Call the [[DefineOwnProperty]] internal method of A with - arguments ToString(n), the Property Descriptor {[[Value]]: matchStr, - [[Writable]]: true, [[Enumerable]]: true, [[configurable]]: true}, and false. */ - descriptorMatchStr := newDataPropertyDescriptorFull(matchStr, true, true, true); - {A.DefineOwnProperty}(A, ToString(n), descriptorMatchStr, false); - /* 6. Increment n. */ - n := n + 1.; + previousLastIndex := thisIndex; } + /* 4. Let matchStr be the result of calling the [[Get]] internal + method of result with argument "0". */ + matchStr := {result.Get}(result, "0"); + /* 5. Call the [[DefineOwnProperty]] internal method of A with + arguments ToString(n), the Property Descriptor {[[Value]]: matchStr, + [[Writable]]: true, [[Enumerable]]: true, [[configurable]]: true}, and false. */ + descriptorMatchStr := newDataPropertyDescriptorFull(matchStr, true, true, true); + {A.DefineOwnProperty}(A, ToString(n), descriptorMatchStr, false); + /* 6. Increment n. */ + n := n + 1.; } } /* g. If n == 0, then return null. */ diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.6.esl b/JS-Interpreters/ecmaref5/section 15/section_15.6.esl index 45d3b73297..3d31d4c88a 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.6.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.6.esl @@ -125,9 +125,8 @@ function BooleanPrototypeValueOf(globalObject, this, strict, params) { /* 1. Let B be the this value. */ B := this; /* 2. If Type(B) is Boolean, then let b be B. */ - if (Type(B) == "Boolean") { - b := B; - } else { + b := B; + if (Type(B) != "Boolean") { /* 3. Else if Type(B) is Object and the value of the [[Class]] internal property of B is "Boolean", then let b be the value of the [[PrimitiveValue]] internal property of B. */ if ((Type(B) == "Object") &&& (getInternalProperty(B, "Class") == "Boolean")) diff --git a/JS-Interpreters/ecmaref5/section 15/section_15.9_alt.esl b/JS-Interpreters/ecmaref5/section 15/section_15.9_alt.esl index aa983dd5a7..0f8d1e5c7d 100644 --- a/JS-Interpreters/ecmaref5/section 15/section_15.9_alt.esl +++ b/JS-Interpreters/ecmaref5/section 15/section_15.9_alt.esl @@ -508,7 +508,7 @@ function DateConstructor(global, this, strict, args) { if ((l_len(args) == 0)) return internalNewDateWithoutValue(prototype); - + return internalNewDate(prototype, args); } @@ -570,7 +570,7 @@ function dateConstructorMultipleArgs(global, this, strict, args) { /* d. ReturnIfAbrupt(m). */ @ReturnIfAbrupt(m); /* e. If date is supplied, let dt be ToNumber(date); else let dt be 1. */ - if (date != null) dt := ToNumber(date); else dt := 1.; + if (date != null) dt := ToNumber(date); else dt := 1.; /* f. ReturnIfAbrupt(dt). */ @ReturnIfAbrupt(dt); /* g. If hours is supplied, let h be ToNumber(hours); else let h be 0. */ @@ -1882,6 +1882,7 @@ function internalNewDate(datePrototypeObject, args) { function internalNewDateWithValue(datePrototypeObject, value) { /* The [[Prototype]] internal property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1). */ + newlyConstructedObject := NewECMAScriptObject(); setInternalProperty(newlyConstructedObject, "Prototype", datePrototypeObject); /* The [[Class]] internal property of the newly constructed object is set to "Date". */ setInternalProperty(newlyConstructedObject, "Class", "Date"); @@ -1911,6 +1912,7 @@ function internalNewDateWithValue(datePrototypeObject, value) { function internalNewDateWithoutValue(datePrototypeObject) { /* The [[Prototype]] internal property of the newly constructed object is set to the original Date prototype object, the one that is the initial value of Date.prototype (15.9.4.1). */ + newlyConstructedObject := NewECMAScriptObject(); setInternalProperty(newlyConstructedObject, "Prototype", datePrototypeObject); /* The [[Class]] internal property of the newly constructed object is set to "Date". */ setInternalProperty(newlyConstructedObject, "Class", "Date"); diff --git a/JS-Interpreters/ecmaref6/section 21/section_21.1.esl b/JS-Interpreters/ecmaref6/section 21/section_21.1.esl index 051ecde34d..115fbc5b8a 100644 --- a/JS-Interpreters/ecmaref6/section 21/section_21.1.esl +++ b/JS-Interpreters/ecmaref6/section 21/section_21.1.esl @@ -1091,8 +1091,10 @@ function StringPrototypeReplace(global, this, NewTarget, strict, args) { code units of string, replStr, and the trailing substring of string starting at index tailPos. If pos is 0, the first element of the concatenation will be the empty String. */ - if (pos > 0.) first := substring(str, 0., pos); else first := ""; - last := substring(str, tailPos, int_to_float(s_len_u (str))); + first := ""; + if (pos > 0.) + first := substring(str, 0., pos); + last := substring(str, tailPos, int_to_float(s_len_u(str))); newString := first; newString := s_concat([newString, replStr]); newString := s_concat([newString, last]); diff --git a/JS-Interpreters/ecmaref6/section 22/section_22.1.esl b/JS-Interpreters/ecmaref6/section 22/section_22.1.esl index 66ba903309..f35c087cb5 100644 --- a/JS-Interpreters/ecmaref6/section 22/section_22.1.esl +++ b/JS-Interpreters/ecmaref6/section 22/section_22.1.esl @@ -1774,7 +1774,9 @@ function arrayJoin(global, this, NewTarget, strict, args) { element0 := Get(O, "0"); @ReturnIfAbrupt(element0); /* 10. If element0 is undefined or null, let R be the empty String; otherwise, Let R be ToString(element0). */ - if ((element0 == 'undefined) || (element0 == 'null)) R := ""; else R := ToString(element0); + R := ""; + if ((element0 != 'undefined) &&& (element0 != 'null)) + R := ToString(element0); /* 11. ReturnIfAbrupt(R). */ @ReturnIfAbrupt(R); /* 12. Let k be 1. */ @@ -2975,7 +2977,11 @@ function arraySplice(global, this, NewTarget, strict, args) { /* 6. ReturnIfAbrupt(relativeStart). */ @ReturnIfAbrupt(relativeStart); /* 7. If relativeStart is negative, let actualStart be max((len + relativeStart),0); else let actualStart be min(relativeStart, len). */ - if (relativeStart < 0.) actualStart := max((len + relativeStart), 0.); else actualStart := min(relativeStart, len); + actualStart := 0.; + if (relativeStart < 0.) + actualStart := max((len + relativeStart), 0.); + else + actualStart := min(relativeStart, len); n_args := l_len(args); /* 8. If the number of actual arguments is 0, then */