Skip to content

Commit

Permalink
Add promise.any
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwl03 committed Oct 9, 2019
1 parent 6b98ef8 commit 4294792
Show file tree
Hide file tree
Showing 14 changed files with 2,842 additions and 2,419 deletions.
1 change: 1 addition & 0 deletions lib/Runtime/Base/JnDirectFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ENTRY2(xor_, _u("xor"))
ENTRY(add)
ENTRY(all)
ENTRY(allSettled)
ENTRY(any)
ENTRY(anchor)
ENTRY(apply)
ENTRY(Array)
Expand Down
82 changes: 82 additions & 0 deletions lib/Runtime/Debug/TTSnapObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,88 @@ namespace TTD

//////////////////

Js::RecyclableObject* DoObjectInflation_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* snpObject, InflateMap* inflator)
{
const SnapPromiseAnyRejectElementFunctionInfo* aInfo = SnapObjectGetAddtlInfoAs<SnapPromiseAnyRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAnyRejectElementFunctionObject>(snpObject);
Js::ScriptContext* ctx = inflator->LookupScriptContext(snpObject->SnapType->ScriptContextLogId);

Js::JavascriptPromiseCapability* capabilities = InflatePromiseCapabilityInfo(&aInfo->Capabilities, ctx, inflator);

if (!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId))
{
Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingWrapper = ctx->GetLibrary()->CreateRemainingElementsWrapper_TTD(ctx, aInfo->RemainingElementsValue);
inflator->AddInflatedPromiseInfo(aInfo->RemainingElementsWrapperId, remainingWrapper);
}
Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* wrapper = inflator->LookupInflatedPromiseInfo<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId);

if (!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper>(aInfo->AlreadyCalledWrapperId))
{
Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyCalledWrapper = ctx->GetLibrary()->CreateAlreadyCalledWrapper_TTD(ctx, aInfo->AlreadyCalledValue);
inflator->AddInflatedPromiseInfo(aInfo->AlreadyCalledWrapperId, alreadyCalledWrapper);
}
Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyCalledWrapper = inflator->LookupInflatedPromiseInfo<Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper>(aInfo->AlreadyCalledWrapperId);

Js::RecyclableObject* values = inflator->LookupObject(aInfo->Values);

return ctx->GetLibrary()->CreatePromiseAnyRejectElementFunction_TTD(capabilities, aInfo->Index, wrapper, values, alreadyCalledWrapper);
}

//DoAddtlValueInstantiation is a nop
void EmitAddtlInfo_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* snpObject, FileWriter* writer)
{
SnapPromiseAnyRejectElementFunctionInfo* aInfo = SnapObjectGetAddtlInfoAs<SnapPromiseAnyRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAnyRejectElementFunctionObject>(snpObject);

writer->WriteKey(NSTokens::Key::entry, NSTokens::Separator::CommaSeparator);
NSSnapValues::EmitPromiseCapabilityInfo(&aInfo->Capabilities, writer, NSTokens::Separator::NoSeparator);

writer->WriteUInt32(NSTokens::Key::u32Val, aInfo->Index, NSTokens::Separator::CommaSeparator);
writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->RemainingElementsWrapperId, NSTokens::Separator::CommaSeparator);
writer->WriteUInt32(NSTokens::Key::u32Val, aInfo->RemainingElementsValue, NSTokens::Separator::CommaSeparator);

writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->AlreadyCalledWrapperId, NSTokens::Separator::CommaSeparator);
writer->WriteBool(NSTokens::Key::boolVal, aInfo->AlreadyCalledValue, NSTokens::Separator::CommaSeparator);

writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->Values, NSTokens::Separator::CommaSeparator);
}

void ParseAddtlInfo_SnapPromiseAnyRejectElementFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc)
{
SnapPromiseAnyRejectElementFunctionInfo* aInfo = alloc.SlabAllocateStruct<SnapPromiseAnyRejectElementFunctionInfo>();

reader->ReadKey(NSTokens::Key::entry, true);
NSSnapValues::ParsePromiseCapabilityInfo(&aInfo->Capabilities, false, reader, alloc);

aInfo->Index = reader->ReadUInt32(NSTokens::Key::u32Val, true);
aInfo->RemainingElementsWrapperId = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);
aInfo->RemainingElementsValue = reader->ReadUInt32(NSTokens::Key::u32Val, true);

aInfo->AlreadyCalledWrapperId = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);
aInfo->AlreadyCalledValue = reader->ReadBool(NSTokens::Key::boolVal, true);

aInfo->Values = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);

SnapObjectSetAddtlInfoAs<SnapPromiseAnyRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAnyRejectElementFunctionObject>(snpObject, aInfo);
}

#if ENABLE_SNAPSHOT_COMPARE
void AssertSnapEquiv_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap)
{
SnapPromiseAnyRejectElementFunctionInfo* aInfo1 = SnapObjectGetAddtlInfoAs<SnapPromiseAnyRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAnyRejectElementFunctionObject>(sobj1);
SnapPromiseAnyRejectElementFunctionInfo* aInfo2 = SnapObjectGetAddtlInfoAs<SnapPromiseAnyRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAnyRejectElementFunctionObject>(sobj2);

NSSnapValues::AssertSnapEquiv(&aInfo1->Capabilities, &aInfo2->Capabilities, compareMap);

compareMap.DiagnosticAssert(aInfo1->Index == aInfo2->Index);
compareMap.DiagnosticAssert(aInfo1->RemainingElementsValue == aInfo2->RemainingElementsValue);
compareMap.DiagnosticAssert(aInfo1->AlreadyCalledValue == aInfo2->AlreadyCalledValue);

compareMap.CheckConsistentAndAddPtrIdMapping_Special(aInfo1->Values, aInfo2->Values, _u("values"));

compareMap.CheckConsistentAndAddPtrIdMapping_NoEnqueue(aInfo1->RemainingElementsWrapperId, aInfo2->RemainingElementsWrapperId);
compareMap.CheckConsistentAndAddPtrIdMapping_NoEnqueue(aInfo1->AlreadyCalledWrapperId, aInfo2->AlreadyCalledWrapperId);
}
#endif

Js::RecyclableObject* DoObjectInflation_SnapBoxedValue(const SnapObject* snpObject, InflateMap* inflator)
{
//Boxed values are not too common and have special internal state so it seems easiest to always re-create them.
Expand Down
25 changes: 25 additions & 0 deletions lib/Runtime/Debug/TTSnapObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,31 @@ namespace TTD
void AssertSnapEquiv_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap);
#endif

////
// AnyRejectElementFunctionObject Info
struct SnapPromiseAnyRejectElementFunctionInfo
{
NSSnapValues::SnapPromiseCapabilityInfo Capabilities;
uint32 Index;

TTD_PTR_ID RemainingElementsWrapperId;
uint32 RemainingElementsValue;

TTD_PTR_ID AlreadyCalledWrapperId;
bool AlreadyCalledValue;

TTD_PTR_ID Values;
};

Js::RecyclableObject* DoObjectInflation_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* snpObject, InflateMap* inflator);
//DoAddtlValueInstantiation is a nop
void EmitAddtlInfo_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* snpObject, FileWriter* writer);
void ParseAddtlInfo_SnapPromiseAnyRejectElementFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc);

#if ENABLE_SNAPSHOT_COMPARE
void AssertSnapEquiv_SnapPromiseAnyRejectElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap);
#endif

//////////////////

////
Expand Down
1 change: 1 addition & 0 deletions lib/Runtime/Debug/TTSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ namespace TTD
SnapPromiseReactionTaskFunctionObject,
SnapPromiseAllResolveElementFunctionObject,
SnapPromiseAllSettledResolveOrRejectElementFunctionObject,
SnapPromiseAnyRejectElementFunctionObject,
SnapGeneratorFunction,
SnapGeneratorVirtualScriptFunction,
SnapAsyncFunction,
Expand Down
Loading

0 comments on commit 4294792

Please sign in to comment.