Skip to content

Commit 6359ad7

Browse files
committed
[MERGE #6138 @boingoing] Implement Promise.allSettled
Merge pull request #6138 from boingoing:promiseallsettled Implement Promise.allSettled This is now in Stage 3 and supported in V8 and JSC. See spec: https://tc39.github.io/proposal-promise-allSettled/ Fixes: #6056
2 parents c83d26c + 42c894d commit 6359ad7

22 files changed

+21878
-21209
lines changed

lib/Runtime/Base/JnDirectFields.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ ENTRY2(or_, _u("or"))
8686
ENTRY2(xor_, _u("xor"))
8787
ENTRY(add)
8888
ENTRY(all)
89+
ENTRY(allSettled)
8990
ENTRY(anchor)
9091
ENTRY(apply)
9192
ENTRY(Array)
@@ -157,6 +158,7 @@ ENTRY(from)
157158
ENTRY(fromCharCode)
158159
ENTRY(fromCodePoint)
159160
ENTRY(fromEntries)
161+
ENTRY(fulfilled)
160162
ENTRY(function)
161163
ENTRY(Function)
162164
ENTRY(getDate)
@@ -309,12 +311,14 @@ ENTRY(push)
309311
ENTRY(race)
310312
ENTRY(RangeError)
311313
ENTRY(raw)
314+
ENTRY(reason)
312315
ENTRY(reduce)
313316
ENTRY(reduceRight)
314317
ENTRY(ReferenceError)
315318
ENTRY(Reflect)
316319
ENTRY(RegExpError)
317320
ENTRY(reject)
321+
ENTRY(rejected)
318322
ENTRY(replace)
319323
ENTRY(resolve)
320324
ENTRY2(return_, _u("return")) // "return" cannot be an identifier in C++ so using "return_" instead
@@ -353,6 +357,7 @@ ENTRY(splice)
353357
ENTRY(split)
354358
ENTRY(SQRT1_2)
355359
ENTRY(SQRT2)
360+
ENTRY(status)
356361
ENTRY(strike)
357362
ENTRY(string)
358363
ENTRY(String)

lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
//-------------------------------------------------------------------------------------------------------
55
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.
66

7-
// {3EDF890E-55F9-4646-A9AC-53127700D405}
7+
// {2734B2C7-9500-45AF-AAA6-FABB7B9C3F81}
88
const GUID byteCodeCacheReleaseFileVersion =
9-
{ 0x3EDF890E, 0x55F9, 0x4646,{ 0xA9, 0xAC, 0x53, 0x12, 0x77, 0x00, 0xD4, 0x05 } };
9+
{ 0x2734b2c7, 0x9500, 0x45af, { 0xaa, 0xa6, 0xfa, 0xbb, 0x7b, 0x9c, 0x3f, 0x81 } };

lib/Runtime/Debug/TTSnapObjects.cpp

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ namespace TTD
13091309

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

1312-
if(!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId))
1312+
if (!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId))
13131313
{
13141314
Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingWrapper = ctx->GetLibrary()->CreateRemainingElementsWrapper_TTD(ctx, aInfo->RemainingElementsValue);
13151315
inflator->AddInflatedPromiseInfo(aInfo->RemainingElementsWrapperId, remainingWrapper);
@@ -1376,6 +1376,95 @@ namespace TTD
13761376

13771377
//////////////////
13781378

1379+
////
1380+
//AllSettledResolveOrRejectElementFunctionObject Info
1381+
Js::RecyclableObject* DoObjectInflation_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* snpObject, InflateMap* inflator)
1382+
{
1383+
const SnapPromiseAllSettledResolveOrRejectElementFunctionInfo* aInfo = SnapObjectGetAddtlInfoAs<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAllSettledResolveOrRejectElementFunctionObject>(snpObject);
1384+
Js::ScriptContext* ctx = inflator->LookupScriptContext(snpObject->SnapType->ScriptContextLogId);
1385+
1386+
Js::JavascriptPromiseCapability* capabilities = InflatePromiseCapabilityInfo(&aInfo->Capabilities, ctx, inflator);
1387+
1388+
if(!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId))
1389+
{
1390+
Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* remainingWrapper = ctx->GetLibrary()->CreateRemainingElementsWrapper_TTD(ctx, aInfo->RemainingElementsValue);
1391+
inflator->AddInflatedPromiseInfo(aInfo->RemainingElementsWrapperId, remainingWrapper);
1392+
}
1393+
Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper* wrapper = inflator->LookupInflatedPromiseInfo<Js::JavascriptPromiseAllResolveElementFunctionRemainingElementsWrapper>(aInfo->RemainingElementsWrapperId);
1394+
1395+
if (!inflator->IsPromiseInfoDefined<Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper>(aInfo->AlreadyCalledWrapperId))
1396+
{
1397+
Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyCalledWrapper = ctx->GetLibrary()->CreateAlreadyCalledWrapper_TTD(ctx, aInfo->AlreadyCalledValue);
1398+
inflator->AddInflatedPromiseInfo(aInfo->AlreadyCalledWrapperId, alreadyCalledWrapper);
1399+
}
1400+
Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper* alreadyCalledWrapper = inflator->LookupInflatedPromiseInfo<Js::JavascriptPromiseResolveOrRejectFunctionAlreadyResolvedWrapper>(aInfo->AlreadyCalledWrapperId);
1401+
1402+
Js::RecyclableObject* values = inflator->LookupObject(aInfo->Values);
1403+
1404+
return ctx->GetLibrary()->CreatePromiseAllSettledResolveOrRejectElementFunction_TTD(capabilities, aInfo->Index, wrapper, values, alreadyCalledWrapper, aInfo->IsRejecting);
1405+
}
1406+
1407+
void EmitAddtlInfo_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* snpObject, FileWriter* writer)
1408+
{
1409+
SnapPromiseAllSettledResolveOrRejectElementFunctionInfo* aInfo = SnapObjectGetAddtlInfoAs<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAllSettledResolveOrRejectElementFunctionObject>(snpObject);
1410+
1411+
writer->WriteKey(NSTokens::Key::entry, NSTokens::Separator::CommaSeparator);
1412+
NSSnapValues::EmitPromiseCapabilityInfo(&aInfo->Capabilities, writer, NSTokens::Separator::NoSeparator);
1413+
1414+
writer->WriteUInt32(NSTokens::Key::u32Val, aInfo->Index, NSTokens::Separator::CommaSeparator);
1415+
writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->RemainingElementsWrapperId, NSTokens::Separator::CommaSeparator);
1416+
writer->WriteUInt32(NSTokens::Key::u32Val, aInfo->RemainingElementsValue, NSTokens::Separator::CommaSeparator);
1417+
1418+
writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->AlreadyCalledWrapperId, NSTokens::Separator::CommaSeparator);
1419+
writer->WriteBool(NSTokens::Key::boolVal, aInfo->AlreadyCalledValue, NSTokens::Separator::CommaSeparator);
1420+
1421+
writer->WriteBool(NSTokens::Key::boolVal, aInfo->IsRejecting, NSTokens::Separator::CommaSeparator);
1422+
writer->WriteAddr(NSTokens::Key::ptrIdVal, aInfo->Values, NSTokens::Separator::CommaSeparator);
1423+
}
1424+
1425+
void ParseAddtlInfo_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc)
1426+
{
1427+
SnapPromiseAllSettledResolveOrRejectElementFunctionInfo* aInfo = alloc.SlabAllocateStruct<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo>();
1428+
1429+
reader->ReadKey(NSTokens::Key::entry, true);
1430+
NSSnapValues::ParsePromiseCapabilityInfo(&aInfo->Capabilities, false, reader, alloc);
1431+
1432+
aInfo->Index = reader->ReadUInt32(NSTokens::Key::u32Val, true);
1433+
aInfo->RemainingElementsWrapperId = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);
1434+
aInfo->RemainingElementsValue = reader->ReadUInt32(NSTokens::Key::u32Val, true);
1435+
1436+
aInfo->AlreadyCalledWrapperId = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);
1437+
aInfo->AlreadyCalledValue = reader->ReadBool(NSTokens::Key::boolVal, true);
1438+
1439+
aInfo->IsRejecting = reader->ReadBool(NSTokens::Key::boolVal, true);
1440+
aInfo->Values = reader->ReadAddr(NSTokens::Key::ptrIdVal, true);
1441+
1442+
SnapObjectSetAddtlInfoAs<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAllSettledResolveOrRejectElementFunctionObject>(snpObject, aInfo);
1443+
}
1444+
1445+
1446+
#if ENABLE_SNAPSHOT_COMPARE
1447+
void AssertSnapEquiv_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap)
1448+
{
1449+
SnapPromiseAllSettledResolveOrRejectElementFunctionInfo* aInfo1 = SnapObjectGetAddtlInfoAs<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAllSettledResolveOrRejectElementFunctionObject>(sobj1);
1450+
SnapPromiseAllSettledResolveOrRejectElementFunctionInfo* aInfo2 = SnapObjectGetAddtlInfoAs<SnapPromiseAllSettledResolveOrRejectElementFunctionInfo*, SnapObjectType::SnapPromiseAllSettledResolveOrRejectElementFunctionObject>(sobj2);
1451+
1452+
NSSnapValues::AssertSnapEquiv(&aInfo1->Capabilities, &aInfo2->Capabilities, compareMap);
1453+
1454+
compareMap.DiagnosticAssert(aInfo1->Index == aInfo2->Index);
1455+
compareMap.DiagnosticAssert(aInfo1->RemainingElementsValue == aInfo2->RemainingElementsValue);
1456+
compareMap.DiagnosticAssert(aInfo1->AlreadyCalledValue == aInfo2->AlreadyCalledValue);
1457+
compareMap.DiagnosticAssert(aInfo1->IsRejecting == aInfo2->IsRejecting);
1458+
1459+
compareMap.CheckConsistentAndAddPtrIdMapping_Special(aInfo1->Values, aInfo2->Values, _u("values"));
1460+
1461+
compareMap.CheckConsistentAndAddPtrIdMapping_NoEnqueue(aInfo1->RemainingElementsWrapperId, aInfo2->RemainingElementsWrapperId);
1462+
compareMap.CheckConsistentAndAddPtrIdMapping_NoEnqueue(aInfo1->AlreadyCalledWrapperId, aInfo2->AlreadyCalledWrapperId);
1463+
}
1464+
#endif
1465+
1466+
//////////////////
1467+
13791468
Js::RecyclableObject* DoObjectInflation_SnapBoxedValue(const SnapObject* snpObject, InflateMap* inflator)
13801469
{
13811470
//Boxed values are not too common and have special internal state so it seems easiest to always re-create them.

lib/Runtime/Debug/TTSnapObjects.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,33 @@ namespace TTD
457457
void AssertSnapEquiv_SnapPromiseAllResolveElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap);
458458
#endif
459459

460+
////
461+
//AllSettledResolveOrRejectElementFunctionObject Info
462+
struct SnapPromiseAllSettledResolveOrRejectElementFunctionInfo
463+
{
464+
NSSnapValues::SnapPromiseCapabilityInfo Capabilities;
465+
uint32 Index;
466+
467+
TTD_PTR_ID RemainingElementsWrapperId;
468+
uint32 RemainingElementsValue;
469+
470+
TTD_PTR_ID AlreadyCalledWrapperId;
471+
bool AlreadyCalledValue;
472+
473+
bool IsRejecting;
474+
475+
TTD_PTR_ID Values;
476+
};
477+
478+
Js::RecyclableObject* DoObjectInflation_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* snpObject, InflateMap* inflator);
479+
//DoAddtlValueInstantiation is a nop
480+
void EmitAddtlInfo_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* snpObject, FileWriter* writer);
481+
void ParseAddtlInfo_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(SnapObject* snpObject, FileReader* reader, SlabAllocator& alloc);
482+
483+
#if ENABLE_SNAPSHOT_COMPARE
484+
void AssertSnapEquiv_SnapPromiseAllSettledResolveOrRejectElementFunctionInfo(const SnapObject* sobj1, const SnapObject* sobj2, TTDCompareMap& compareMap);
485+
#endif
486+
460487
//////////////////
461488

462489
////

lib/Runtime/Debug/TTSupport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ namespace TTD
250250
SnapPromiseResolveOrRejectFunctionObject,
251251
SnapPromiseReactionTaskFunctionObject,
252252
SnapPromiseAllResolveElementFunctionObject,
253+
SnapPromiseAllSettledResolveOrRejectElementFunctionObject,
253254
SnapGeneratorFunction,
254255
SnapGeneratorVirtualScriptFunction,
255256
SnapAsyncFunction,

0 commit comments

Comments
 (0)