@@ -252,7 +252,24 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
252252 threadContext->MapIsInstInlineCaches ([threadContext, object](const Js::Var function, Js::IsInstInlineCache* inlineCacheList) {
253253 Assert (inlineCacheList != nullptr );
254254
255- // ToDo: Check for changed "function"
255+ JavascriptFunction* jsFunction = VarTo<JavascriptFunction>(function);
256+
257+ // Check if cached function type is same as the old prototype
258+ bool clearCurrentCacheList = jsFunction->GetType () == object->GetType ();
259+ if (!clearCurrentCacheList)
260+ {
261+ // Check if function prototype contains old prototype
262+ JavascriptOperators::MapObjectAndPrototypes<true >(jsFunction->GetPrototype (), [&](RecyclableObject* obj)
263+ {
264+ if (object->GetType () == obj->GetType ())
265+ clearCurrentCacheList = true ;
266+ });
267+ }
268+ if (clearCurrentCacheList)
269+ {
270+ threadContext->InvalidateIsInstInlineCachesForFunction (function);
271+ return ;
272+ }
256273
257274 Js::IsInstInlineCache* curInlineCache;
258275 Js::IsInstInlineCache* nextInlineCache;
@@ -261,12 +278,15 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
261278 // Stash away the next cache before we potentially zero out current one
262279 nextInlineCache = curInlineCache->next ;
263280
264- bool clearCurrentCache = false ;
265- JavascriptOperators::MapObjectAndPrototypes<true >(curInlineCache->type ->GetPrototype (), [&](RecyclableObject* obj)
266- {
267- if (object->GetType () == obj->GetType ())
268- clearCurrentCache = true ;
269- });
281+ bool clearCurrentCache = curInlineCache->type == object->GetType ();
282+ if (!clearCurrentCache) {
283+ // Check if function prototype contains old prototype
284+ JavascriptOperators::MapObjectAndPrototypes<true >(curInlineCache->type ->GetPrototype (), [&](RecyclableObject* obj)
285+ {
286+ if (object->GetType () == obj->GetType ())
287+ clearCurrentCache = true ;
288+ });
289+ }
270290
271291 if (clearCurrentCache)
272292 {
0 commit comments