Skip to content

Commit

Permalink
[1.10>master] [MERGE #5582 @irinayat-MS] Replace literal nullptr with…
Browse files Browse the repository at this point in the history
… null var object in JavascriptStackWalker::GetThis

Merge pull request #5582 from irinayat-MS:nullThis

Fixes part of OS#18397663. We might get nullptr for "this" argument from DocumentContextBridge::_CreateBrowserObject and possibly in other cases. We now translate nullptr into a proper JS null object.

Also removed semantically unclear return bool (nobody was checking it anyway).
  • Loading branch information
Irina Yatsenko committed Aug 8, 2018
2 parents f253c90 + 4a6c0ec commit 5c60983
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 21 additions & 15 deletions lib/Runtime/Language/JavascriptStackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,20 @@ namespace Js
return FALSE;
}

bool JavascriptStackWalker::GetThis(Var* pVarThis, int moduleId) const
void JavascriptStackWalker::GetThis(Var* pVarThis, int moduleId) const
{
#if ENABLE_NATIVE_CODEGEN
if (inlinedFramesBeingWalked)
{
if (inlinedFrameWalker.GetArgc() == 0)
{
*pVarThis = JavascriptOperators::OP_GetThis(this->scriptContext->GetLibrary()->GetUndefined(), moduleId, scriptContext);
return false;
}

*pVarThis = inlinedFrameWalker.GetThisObject();
Assert(*pVarThis);

return true;
else
{
*pVarThis = inlinedFrameWalker.GetThisObject();
Assert(*pVarThis);
}
}
else
#endif
Expand All @@ -210,11 +209,16 @@ namespace Js
if (callInfo.Count == 0)
{
*pVarThis = JavascriptOperators::OP_GetThis(scriptContext->GetLibrary()->GetUndefined(), moduleId, scriptContext);
return false;
}
else
{
*pVarThis = this->GetThisFromFrame();
}
}

*pVarThis = this->GetThisFromFrame();
return (*pVarThis) != nullptr;
if (*pVarThis == nullptr)
{
*pVarThis = this->scriptContext->GetLibrary()->GetNull();
}
}

Expand Down Expand Up @@ -1188,14 +1192,17 @@ namespace Js
return FALSE;
}

bool JavascriptStackWalker::GetThis(Var* pThis, int moduleId, ScriptContext* scriptContext)
void JavascriptStackWalker::GetThis(Var* pThis, int moduleId, ScriptContext* scriptContext)
{
JavascriptStackWalker walker(scriptContext);
JavascriptFunction* caller;
return walker.GetCaller(&caller) && walker.GetThis(pThis, moduleId);
if (walker.GetCaller(&caller))
{
walker.GetThis(pThis, moduleId);
}
}

bool JavascriptStackWalker::GetThis(Var* pThis, int moduleId, JavascriptFunction* func, ScriptContext* scriptContext)
void JavascriptStackWalker::GetThis(Var* pThis, int moduleId, JavascriptFunction* func, ScriptContext* scriptContext)
{
JavascriptStackWalker walker(scriptContext);
JavascriptFunction* caller;
Expand All @@ -1204,10 +1211,9 @@ namespace Js
if (caller == func)
{
walker.GetThis(pThis, moduleId);
return true;
return;
}
}
return false;
}

// Try to see whether there is a top-most javascript frame, and if there is return true if it's native.
Expand Down
6 changes: 3 additions & 3 deletions lib/Runtime/Language/JavascriptStackWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ namespace Js
void SetCurrentFunction(JavascriptFunction * function);
CallInfo GetCallInfo(bool includeInlinedFrames = true) const;
CallInfo GetCallInfoFromPhysicalFrame() const;
bool GetThis(Var *pThis, int moduleId) const;
void GetThis(Var *pThis, int moduleId) const;
Js::Var * GetJavascriptArgs(bool boxArgsAndDeepCopy) const;
void **GetCurrentArgv() const;

Expand All @@ -244,8 +244,8 @@ namespace Js
// noinline, we want to use own stack frame.
static _NOINLINE BOOL GetCaller(_Out_opt_ JavascriptFunction** ppFunc, ScriptContext* scriptContext);
static _NOINLINE BOOL GetCaller(_Out_opt_ JavascriptFunction** ppFunc, uint32* byteCodeOffset, ScriptContext* scriptContext);
static _NOINLINE bool GetThis(Var* pThis, int moduleId, ScriptContext* scriptContext);
static _NOINLINE bool GetThis(Var* pThis, int moduleId, JavascriptFunction* func, ScriptContext* scriptContext);
static _NOINLINE void GetThis(Var* pThis, int moduleId, ScriptContext* scriptContext);
static _NOINLINE void GetThis(Var* pThis, int moduleId, JavascriptFunction* func, ScriptContext* scriptContext);

static bool IsDisplayCaller(JavascriptFunction* func);
bool GetDisplayCaller(_Out_opt_ JavascriptFunction ** ppFunc);
Expand Down

0 comments on commit 5c60983

Please sign in to comment.