Skip to content

Commit

Permalink
Apease the typechecker
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Feb 1, 2025
1 parent 8bfcd61 commit b2c08f2
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 60 deletions.
4 changes: 2 additions & 2 deletions JS-Interpreters/ecmaref5/section 10/section_10.4.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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: */
Expand Down Expand Up @@ -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. */
Expand Down
2 changes: 2 additions & 0 deletions JS-Interpreters/ecmaref5/section 10/section_10.6.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions JS-Interpreters/ecmaref5/section 15/section_15.1.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions JS-Interpreters/ecmaref5/section 15/section_15.12.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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 "{}". */
Expand Down Expand Up @@ -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 := "[]";
Expand Down
9 changes: 6 additions & 3 deletions JS-Interpreters/ecmaref5/section 15/section_15.4.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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". */
Expand Down Expand Up @@ -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.;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down
90 changes: 44 additions & 46 deletions JS-Interpreters/ecmaref5/section 15/section_15.5.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
5 changes: 2 additions & 3 deletions JS-Interpreters/ecmaref5/section 15/section_15.6.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 4 additions & 2 deletions JS-Interpreters/ecmaref5/section 15/section_15.9_alt.esl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function DateConstructor(global, this, strict, args) {

if ((l_len(args) == 0))
return internalNewDateWithoutValue(prototype);

return internalNewDate(prototype, args);
}

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 4 additions & 2 deletions JS-Interpreters/ecmaref6/section 21/section_21.1.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 8 additions & 2 deletions JS-Interpreters/ecmaref6/section 22/section_22.1.esl
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit b2c08f2

Please sign in to comment.