Skip to content

Commit 45a8241

Browse files
committed
Share types (i.e., allow PathTypeHandlers) for properties with non-standard attributes (non-writable, etc.). This change draws on Kount Veluri's work on behalf of native fields. It adds a wrinkle to the type path mechanism, replacing the PropertyId successor map key with a key that munges PropertyId and attributes. The way is paved for sharing types with getter/setters, deleted properties, and native values. When a property's attributes are changed/set, the type path is branched starting with the type that precedes the one that introduced the property.
1 parent 3825ee2 commit 45a8241

File tree

7 files changed

+1479
-271
lines changed

7 files changed

+1479
-271
lines changed

lib/Jsrt/JsrtExternalObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ JsrtExternalType::JsrtExternalType(Js::ScriptContext* scriptContext, JsFinalizeC
1313
Js::TypeIds_Object,
1414
scriptContext->GetLibrary()->GetObjectPrototype(),
1515
nullptr,
16-
Js::SimplePathTypeHandler::New(scriptContext, scriptContext->GetLibrary()->GetRootPath(), 0, 0, 0, true, true),
16+
Js::SimplePathTypeHandlerNoAttr::New(scriptContext, scriptContext->GetLibrary()->GetRootPath(), 0, 0, 0, true, true),
1717
true,
1818
true)
1919
, jsFinalizeCallback(finalizeCallback)

lib/Runtime/Debug/TTSnapObjects.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,6 @@ namespace TTD
403403

404404
if(snpObject->SnapType->HasNoEnumerableProperties != obj->GetDynamicType()->GetHasNoEnumerableProperties())
405405
{
406-
TTDAssert(!obj->GetDynamicType()->GetIsShared(), "This is shared so we are mucking something up.");
407-
408406
obj->GetDynamicType()->SetHasNoEnumerableProperties(snpObject->SnapType->HasNoEnumerableProperties);
409407
}
410408
}

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ namespace Js
425425

426426
#define INIT_SIMPLE_TYPE(field, typeId, prototype) \
427427
field = DynamicType::New(scriptContext, typeId, prototype, nullptr, \
428-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true)
428+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true)
429429

430430
INIT_SIMPLE_TYPE(activationObjectType, TypeIds_ActivationObject, nullValue);
431431
INIT_SIMPLE_TYPE(arrayType, TypeIds_Array, arrayPrototype);
@@ -523,7 +523,7 @@ namespace Js
523523

524524
// Initialize Date types
525525
dateType = DynamicType::New(scriptContext, TypeIds_Date, datePrototype, nullptr,
526-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
526+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
527527
variantDateType = StaticType::New(scriptContext, TypeIds_VariantDate, nullValue, nullptr);
528528

529529
anonymousFunctionTypeHandler = NullTypeHandler<false>::GetDefaultInstance();
@@ -566,7 +566,7 @@ namespace Js
566566
else
567567
{
568568
boundFunctionType = DynamicType::New(scriptContext, TypeIds_Function, functionPrototype, BoundFunction::NewInstance,
569-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
569+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
570570
}
571571
crossSiteDeferredPrototypeFunctionType = CreateDeferredPrototypeFunctionTypeNoProfileThunk(
572572
scriptContext->CurrentCrossSiteThunk, true /*isShared*/);
@@ -627,8 +627,8 @@ namespace Js
627627
// Initialize Object types
628628
for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
629629
{
630-
SimplePathTypeHandler * typeHandler =
631-
SimplePathTypeHandler::New(
630+
SimplePathTypeHandlerNoAttr * typeHandler =
631+
SimplePathTypeHandlerNoAttr::New(
632632
scriptContext,
633633
this->GetRootPath(),
634634
0,
@@ -641,8 +641,8 @@ namespace Js
641641
}
642642
for (int16 i = 0; i < PreInitializedObjectTypeCount; i++)
643643
{
644-
SimplePathTypeHandler * typeHandler =
645-
SimplePathTypeHandler::New(
644+
SimplePathTypeHandlerNoAttr * typeHandler =
645+
SimplePathTypeHandlerNoAttr::New(
646646
scriptContext,
647647
this->GetRootPath(),
648648
0,
@@ -655,15 +655,15 @@ namespace Js
655655
DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr, typeHandler, true, true);
656656
}
657657

658-
SimplePathTypeHandler * typeHandler = SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
658+
SimplePathTypeHandlerNoAttr * typeHandler = SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
659659
nullPrototypeObjectType = DynamicType::New(scriptContext, TypeIds_Object, nullValue, nullptr, typeHandler, true, true);
660660

661661
// Initialize regex types
662662
TypePath *const regexResultPath = TypePath::New(recycler);
663663
regexResultPath->Add(BuiltInPropertyRecords::input);
664664
regexResultPath->Add(BuiltInPropertyRecords::index);
665665
regexResultType = DynamicType::New(scriptContext, TypeIds_Array, arrayPrototype, nullptr,
666-
SimplePathTypeHandler::New(scriptContext, regexResultPath, regexResultPath->GetPathLength(), JavascriptRegularExpressionResult::InlineSlotCount, sizeof(JavascriptArray), true, true), true, true);
666+
SimplePathTypeHandlerNoAttr::New(scriptContext, regexResultPath, regexResultPath->GetPathLength(), JavascriptRegularExpressionResult::InlineSlotCount, sizeof(JavascriptArray), true, true), true, true);
667667

668668
// Initialize string types
669669
// static type is handled under StringCache.h
@@ -673,33 +673,33 @@ namespace Js
673673
throwErrorObjectType = StaticType::New(scriptContext, TypeIds_Undefined, nullValue, ThrowErrorObject::DefaultEntryPoint);
674674

675675
mapType = DynamicType::New(scriptContext, TypeIds_Map, mapPrototype, nullptr,
676-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
676+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
677677

678678
setType = DynamicType::New(scriptContext, TypeIds_Set, setPrototype, nullptr,
679-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
679+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
680680

681681
weakMapType = DynamicType::New(scriptContext, TypeIds_WeakMap, weakMapPrototype, nullptr,
682-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
682+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
683683

684684
weakSetType = DynamicType::New(scriptContext, TypeIds_WeakSet, weakSetPrototype, nullptr,
685-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
685+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
686686

687687
TypePath *const iteratorResultPath = TypePath::New(recycler);
688688
iteratorResultPath->Add(BuiltInPropertyRecords::value);
689689
iteratorResultPath->Add(BuiltInPropertyRecords::done);
690690
iteratorResultType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
691-
SimplePathTypeHandler::New(scriptContext, iteratorResultPath, iteratorResultPath->GetPathLength(), 2, sizeof(DynamicObject), true, true), true, true);
691+
SimplePathTypeHandlerNoAttr::New(scriptContext, iteratorResultPath, iteratorResultPath->GetPathLength(), 2, sizeof(DynamicObject), true, true), true, true);
692692

693693
arrayIteratorType = DynamicType::New(scriptContext, TypeIds_ArrayIterator, arrayIteratorPrototype, nullptr,
694-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
694+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
695695
mapIteratorType = DynamicType::New(scriptContext, TypeIds_MapIterator, mapIteratorPrototype, nullptr,
696-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
696+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
697697
setIteratorType = DynamicType::New(scriptContext, TypeIds_SetIterator, setIteratorPrototype, nullptr,
698-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
698+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
699699
stringIteratorType = DynamicType::New(scriptContext, TypeIds_StringIterator, stringIteratorPrototype, nullptr,
700-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
700+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
701701
listIteratorType = DynamicType::New(scriptContext, TypeIds_ListIterator, iteratorPrototype, nullptr,
702-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
702+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
703703

704704
if (config->IsES6GeneratorsEnabled())
705705
{
@@ -711,10 +711,10 @@ namespace Js
711711

712712
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
713713
debugDisposableObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
714-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
714+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
715715

716716
debugFuncExecutorInDisposeObjectType = DynamicType::New(scriptContext, TypeIds_Object, objectPrototype, nullptr,
717-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
717+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
718718
#endif
719719
}
720720

@@ -2711,8 +2711,8 @@ namespace Js
27112711
DeferredTypeHandler<InitializeRegexPrototype, DefaultDeferredTypeFilter, true>::GetDefaultInstance()));
27122712
}
27132713

2714-
SimplePathTypeHandler *typeHandler =
2715-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
2714+
SimplePathTypeHandlerNoAttr *typeHandler =
2715+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true);
27162716
// See JavascriptRegExp::IsWritable for property writability
27172717
if (!scriptConfig->IsES6RegExPrototypePropertiesEnabled())
27182718
{
@@ -6860,7 +6860,7 @@ namespace Js
68606860
}
68616861
oldCachedType = dynamicType;
68626862
#endif
6863-
SimplePathTypeHandler* typeHandler = SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, requestedInlineSlotCapacity, offsetOfInlineSlots, true, true);
6863+
SimplePathTypeHandlerNoAttr* typeHandler = SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, requestedInlineSlotCapacity, offsetOfInlineSlots, true, true);
68646864
dynamicType = DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint, typeHandler, true, true);
68656865

68666866
if (useCache)
@@ -6890,7 +6890,7 @@ namespace Js
68906890
DynamicType* JavascriptLibrary::CreateObjectTypeNoCache(RecyclableObject* prototype, Js::TypeId typeId)
68916891
{
68926892
return DynamicType::New(scriptContext, typeId, prototype, RecyclableObject::DefaultEntryPoint,
6893-
SimplePathTypeHandler::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
6893+
SimplePathTypeHandlerNoAttr::New(scriptContext, this->GetRootPath(), 0, 0, 0, true, true), true, true);
68946894
}
68956895

68966896
DynamicType* JavascriptLibrary::CreateObjectType(RecyclableObject* prototype, uint16 requestedInlineSlotCapacity)

lib/Runtime/Types/DynamicObject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ namespace Js
6969
friend class JavascriptNativeArray; // for xplat offsetof field access
7070
friend class JavascriptOperators; // for ReplaceType
7171
friend class PathTypeHandlerBase; // for ReplaceType
72+
friend class SimplePathTypeHandlerNoAttr;
73+
friend class SimplePathTypeHandlerWithAttr;
74+
friend class PathTypeHandlerNoAttr;
7275
friend class JavascriptLibrary; // for ReplaceType
7376
friend class ScriptFunction; // for ReplaceType;
7477
friend class JSON::JSONParser; //for ReplaceType

0 commit comments

Comments
 (0)