Skip to content

Commit

Permalink
Handle the case of host initializing the GlobalObject before calling …
Browse files Browse the repository at this point in the history
…to set the secure host object
  • Loading branch information
boingoing committed Jul 13, 2019
1 parent c90bd3d commit 449c647
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/Runtime/Library/GlobalObject.cpp
Expand Up @@ -58,15 +58,25 @@ using namespace Js;
{
HRESULT hr = S_OK;

this->directHostObject = hostObject;
this->secureDirectHostObject = secureDirectHostObject;

BEGIN_TRANSLATE_OOM_TO_HRESULT_NESTED
{
// In fastDOM scenario, we should use the host object to lookup the prototype.
this->SetPrototype(library->GetNull());

// Host can call to set the direct host object after the GlobalObject has been initialized but
// before user script has run. (This happens even before the previous call to SetPrototype)
// If that happens, we'll need to update the 'globalThis' property to point to the secure
// host object so that we don't hand a reference to the bare GlobalObject out to user script.
if (this->GetScriptContext()->GetConfig()->IsESGlobalThisEnabled())
{
this->SetProperty(PropertyIds::globalThis, this->ToThis(), PropertyOperation_None, nullptr);
}
}
END_TRANSLATE_OOM_TO_HRESULT(hr)

this->directHostObject = hostObject;
this->secureDirectHostObject = secureDirectHostObject;
return hr;
}

Expand Down

0 comments on commit 449c647

Please sign in to comment.