Skip to content

Commit 67d5ea7

Browse files
committed
Correctly set flag indicating a function has references to this symbol
`IsArgSaveRequired` depends on the flag that the function has references to `this` (amongst other conditions) to determine if we need to spill arguments to stack on x64. Since this flag is not set correctly, sometimes we end up not spilling arguments, and therefore have incorrect argument values. Also remove previously unreachable code due to the flag not being set.
1 parent de37cbe commit 67d5ea7

File tree

3 files changed

+2
-42
lines changed

3 files changed

+2
-42
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ void ByteCodeGenerator::LoadAllConstants(FuncInfo *funcInfo)
19671967
{
19681968
if (funcInfo->GetThisSymbol())
19691969
{
1970-
byteCodeFunction->MapAndSetThisRegisterForEventHandler(funcInfo->GetThisSymbol()->GetLocation());
1970+
byteCodeFunction->MapAndSetThisRegisterForEventHandler(funcInfo->GetThisSymbol()->GetLocation());
19711971
}
19721972
// The environment is the namespace hierarchy starting with "this".
19731973
Assert(!funcInfo->RegIsConst(funcInfo->GetEnvRegister()));

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,7 @@ void AddVarsToScope(ParseNode *vars, ByteCodeGenerator *byteCodeGenerator)
23942394
if (sym->IsThis())
23952395
{
23962396
funcInfo->SetThisSymbol(sym);
2397+
funcInfo->GetParsedFunctionBody()->SetHasThis(true);
23972398
}
23982399
else if (sym->IsNewTarget())
23992400
{

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -686,47 +686,6 @@ using namespace Js;
686686
pfuncScript->GetFunctionProxy()->EnsureDeserialized();
687687
}
688688

689-
if (pfuncScript->GetFunctionBody()->GetHasThis())
690-
{
691-
// The eval expression refers to "this"
692-
if (args.Info.Flags & CallFlags_ExtraArg)
693-
{
694-
JavascriptFunction* pfuncCaller = nullptr;
695-
// If we are non-hidden call to eval then look for the "this" object in the frame display if the caller is a lambda else get "this" from the caller's frame.
696-
697-
bool successful = false;
698-
if (JavascriptStackWalker::GetCaller(&pfuncCaller, scriptContext))
699-
{
700-
FunctionInfo* functionInfo = pfuncCaller->GetFunctionInfo();
701-
if (functionInfo != nullptr && (functionInfo->IsLambda() || functionInfo->IsClassConstructor()))
702-
{
703-
Var defaultInstance = (moduleID == kmodGlobal) ? JavascriptOperators::OP_LdRoot(scriptContext)->ToThis() : (Var)JavascriptOperators::GetModuleRoot(moduleID, scriptContext);
704-
varThis = JavascriptOperators::OP_GetThisScoped(environment, defaultInstance, scriptContext);
705-
if (!strictMode)
706-
{
707-
UpdateThisForEval(varThis, moduleID, scriptContext);
708-
}
709-
successful = true;
710-
}
711-
}
712-
713-
if (!successful)
714-
{
715-
JavascriptStackWalker::GetThis(&varThis, moduleID, scriptContext);
716-
if (!strictMode)
717-
{
718-
UpdateThisForEval(varThis, moduleID, scriptContext);
719-
}
720-
}
721-
}
722-
else
723-
{
724-
// The expression, which refers to "this", is evaluated by an indirect eval.
725-
// Set "this" to the current module root.
726-
varThis = JavascriptOperators::OP_GetThis(scriptContext->GetLibrary()->GetUndefined(), moduleID, scriptContext);
727-
}
728-
}
729-
730689
if (pfuncScript->HasSuperReference())
731690
{
732691
// Indirect evals cannot have a super reference.

0 commit comments

Comments
 (0)