Skip to content

Commit 9210c36

Browse files
committed
Prototype on cached type chain
While investigating chakra-core#2343, it was realized that when we set prototype, the type chain that we cache doesn't have same prototype. All the predecessors in the cached type chain before existing type of object still has oldPrototype and only the existing type has new prototype. Fix: Start with a type that has `newPrototype` object set because of which entire chain will have `newPrototype` object.
1 parent 507e4cb commit 9210c36

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lib/Runtime/Types/PathTypeHandler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ namespace Js
12291229
{
12301230
// The new type isn't shared yet. We will make it shared when the second instance attains it.
12311231
nextType = instance->DuplicateType();
1232+
// nextType's prototype and predecessorType's prototype can only be different here
1233+
// only for SetPrototype scenario where predecessorType is the cachedType with newPrototype
1234+
nextType->SetPrototype(predecessorType->GetPrototype());
12321235
nextType->typeHandler = nextPath;
12331236
markTypeAsShared ? nextType->SetIsLockedAndShared() : nextType->SetIsLocked();
12341237
}
@@ -1576,6 +1579,7 @@ namespace Js
15761579
SimplePathTypeHandler* newTypeHandler = SimplePathTypeHandler::New(scriptContext, scriptContext->GetLibrary()->GetRootPath(), 0, static_cast<PropertyIndex>(this->GetSlotCapacity()), this->GetInlineSlotCapacity(), this->GetOffsetOfInlineSlots(), true, true);
15771580

15781581
cachedDynamicType = instance->DuplicateType();
1582+
cachedDynamicType->SetPrototype(newPrototype);
15791583
cachedDynamicType->typeHandler = newTypeHandler;
15801584

15811585
// Make type locked, shared only if we are using cache
@@ -1661,8 +1665,7 @@ namespace Js
16611665
Assert(cachedDynamicType->GetTypeHandler()->GetOffsetOfInlineSlots() == GetOffsetOfInlineSlots());
16621666
Assert(cachedDynamicType->GetTypeHandler()->GetSlotCapacity() == this->GetSlotCapacity());
16631667
Assert(DynamicObject::IsTypeHandlerCompatibleForObjectHeaderInlining(this, cachedDynamicType->GetTypeHandler()));
1664-
1665-
cachedDynamicType->SetPrototype(newPrototype);
1668+
Assert(cachedDynamicType->GetPrototype() == newPrototype);
16661669
instance->ReplaceType(cachedDynamicType);
16671670
}
16681671

0 commit comments

Comments
 (0)