@@ -205,6 +205,7 @@ V8ContextImpl::V8ContextImpl(V8IsolateImpl* pIsolateImpl, const StdString& name,
205205 m_hEnumeratorPropertyName = CreatePersistent (CreateString (StdString (L" enumerator" )));
206206 m_hDonePropertyName = CreatePersistent (CreateString (StdString (L" done" )));
207207 m_hValuePropertyName = CreatePersistent (CreateString (StdString (L" value" )));
208+ m_hCachePropertyName = CreatePersistent (CreateString (StdString (L" {545a4a94-f37d-44bb-9e1e-bf3ce730c7e4}" )));
208209 m_hAccessTokenName = CreatePersistent (CreateString (StdString (L" {cdc19e6e-5d80-4627-a605-bb4805f15086}" )));
209210
210211 v8::Local<v8::Function> hGetIteratorFunction;
@@ -738,6 +739,7 @@ V8ContextImpl::~V8ContextImpl()
738739 Dispose (m_hHostObjectTemplate);
739740 Dispose (m_hAccessToken);
740741 Dispose (m_hAccessTokenName);
742+ Dispose (m_hCachePropertyName);
741743 Dispose (m_hValuePropertyName);
742744 Dispose (m_hDonePropertyName);
743745 Dispose (m_hEnumeratorPropertyName);
@@ -1312,10 +1314,19 @@ void V8ContextImpl::GetHostObjectProperty(v8::Local<v8::Name> hKey, const v8::Pr
13121314 {
13131315 BEGIN_PULSE_VALUE_SCOPE (&pContextImpl->m_DisableHostObjectInterception , true )
13141316
1315- auto hNames = hHolder->GetOwnPropertyNames ( );
1316- for ( auto index = hNames-> Length (); index > 0 ; index-- )
1317+ auto hCache = hHolder->GetHiddenValue (pContextImpl-> m_hCachePropertyName );
1318+ if (!hCache. IsEmpty () )
13171319 {
1318- hHolder->Delete (hNames->Get (index - 1 ));
1320+ if (hCache->IsObject ())
1321+ {
1322+ auto hNames = hCache->ToObject ()->GetOwnPropertyNames ();
1323+ for (auto index = hNames->Length (); index > 0 ; index--)
1324+ {
1325+ hHolder->Delete (hNames->Get (index - 1 ));
1326+ }
1327+ }
1328+
1329+ hHolder->DeleteHiddenValue (pContextImpl->m_hCachePropertyName );
13191330 }
13201331
13211332 hHolder->SetHiddenValue (pContextImpl->m_hAccessTokenName , pContextImpl->m_hAccessToken );
@@ -1341,7 +1352,15 @@ void V8ContextImpl::GetHostObjectProperty(v8::Local<v8::Name> hKey, const v8::Pr
13411352 hResult = pContextImpl->ImportValue (HostObjectHelpers::GetProperty (::GetHostObject (info.Holder ()), StdString (hName), isCacheable));
13421353 if (isCacheable)
13431354 {
1344- hHolder->ForceSet (hName, hResult);
1355+ auto hCache = hHolder->GetHiddenValue (pContextImpl->m_hCachePropertyName );
1356+ if (hCache.IsEmpty () || !hCache->IsObject ())
1357+ {
1358+ hCache = pContextImpl->CreateObject ();
1359+ hHolder->SetHiddenValue (pContextImpl->m_hCachePropertyName , hCache);
1360+ }
1361+
1362+ hCache->ToObject ()->ForceSet (hName, hResult);
1363+ hHolder->ForceSet (hName, hResult, v8::DontEnum);
13451364 }
13461365
13471366 CALLBACK_RETURN (hResult);
0 commit comments