@@ -252,7 +252,24 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
252
252
threadContext->MapIsInstInlineCaches ([threadContext, object](const Js::Var function, Js::IsInstInlineCache* inlineCacheList) {
253
253
Assert (inlineCacheList != nullptr );
254
254
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
+ }
256
273
257
274
Js::IsInstInlineCache* curInlineCache;
258
275
Js::IsInstInlineCache* nextInlineCache;
@@ -261,12 +278,15 @@ BOOL JavascriptObject::ChangePrototype(RecyclableObject* object, RecyclableObjec
261
278
// Stash away the next cache before we potentially zero out current one
262
279
nextInlineCache = curInlineCache->next ;
263
280
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
+ }
270
290
271
291
if (clearCurrentCache)
272
292
{
0 commit comments