Skip to content

Commit 449c647

Browse files
committed
Handle the case of host initializing the GlobalObject before calling to set the secure host object
1 parent c90bd3d commit 449c647

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,25 @@ using namespace Js;
5858
{
5959
HRESULT hr = S_OK;
6060

61+
this->directHostObject = hostObject;
62+
this->secureDirectHostObject = secureDirectHostObject;
63+
6164
BEGIN_TRANSLATE_OOM_TO_HRESULT_NESTED
6265
{
6366
// In fastDOM scenario, we should use the host object to lookup the prototype.
6467
this->SetPrototype(library->GetNull());
68+
69+
// Host can call to set the direct host object after the GlobalObject has been initialized but
70+
// before user script has run. (This happens even before the previous call to SetPrototype)
71+
// If that happens, we'll need to update the 'globalThis' property to point to the secure
72+
// host object so that we don't hand a reference to the bare GlobalObject out to user script.
73+
if (this->GetScriptContext()->GetConfig()->IsESGlobalThisEnabled())
74+
{
75+
this->SetProperty(PropertyIds::globalThis, this->ToThis(), PropertyOperation_None, nullptr);
76+
}
6577
}
6678
END_TRANSLATE_OOM_TO_HRESULT(hr)
6779

68-
this->directHostObject = hostObject;
69-
this->secureDirectHostObject = secureDirectHostObject;
7080
return hr;
7181
}
7282

0 commit comments

Comments
 (0)