Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add promise.any #6301

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/ch/DbgController.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var controllerObj = (function () {
"WeakSet",
"WebAssembly",
"WScript",
"AggregateError"
].forEach(function (name) {
filter[name] = 1;
});
Expand Down
1 change: 1 addition & 0 deletions lib/Parser/ParserCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum ErrorTypeEnum
kjstSyntaxError,
kjstTypeError,
kjstURIError,
kjstAggregateError,
kjstWebAssemblyCompileError,
kjstWebAssemblyRuntimeError,
kjstWebAssemblyLinkError,
Expand Down
3 changes: 3 additions & 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 Expand Up @@ -408,6 +409,8 @@ ENTRY(unknown)
ENTRY(unscopables)
ENTRY(unshift)
ENTRY(URIError)
ENTRY(AggregateError)
ENTRY(errors)
ENTRY(UTC)
ENTRY(valueOf)
ENTRY(values)
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
13 changes: 13 additions & 0 deletions lib/Runtime/Language/JavascriptOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,19 @@ using namespace Js;
return TRUE;
}

JavascriptArray* JavascriptOperators::IterableToList(RecyclableObject* items, ScriptContext* scriptContext) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see this is only used once, could you just do the steps inline without making a new method for it?

Assert(items);

RecyclableObject* iterator = JavascriptOperators::GetIterator(items, scriptContext);
JavascriptArray* values = scriptContext->GetLibrary()->CreateArray(0);
JavascriptOperators::DoIteratorStepAndValue(iterator, scriptContext, [&](Var next)
{
JavascriptArray::Push(scriptContext, values, next);
});

return values;
}

#if DBG
BOOL JavascriptOperators::IsPropertyObject(RecyclableObject * instance)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Runtime/Language/JavascriptOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ namespace Js
static BOOL GetProperty(Var instance, RecyclableObject* propertyObject, PropertyId propertyId, Var* value, ScriptContext* requestContext, PropertyValueInfo* info = NULL);
static BOOL GetPropertyObject(Var instance, ScriptContext * scriptContext, RecyclableObject** propertyObject);

static JavascriptArray* IterableToList(RecyclableObject* items, ScriptContext* scriptContext);

static bool GetPropertyObjectForElementAccess(
_In_ Var instance,
_In_ Var index,
Expand Down
Loading