Skip to content

Commit 833faff

Browse files
committed
[MERGE #5723 @yullin-ms] Implemented every, some, includes, and reduce for array.prototype as JsBuiltIn
Merge pull request #5723 from yullin-ms:arrayEverySomeIncludesReduce Implemented every, some, includes, and reduce for array.prototype as JsBuiltIn
2 parents 9a951e2 + 45c0553 commit 833faff

18 files changed

+7575
-5878
lines changed

lib/Parser/rterrors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ RT_ERROR_MSG(JSERR_ObjectIsNotInitialized, 5617, "%s: Object internal state is n
304304
RT_ERROR_MSG(JSERR_GeneratorAlreadyExecuting, 5618, "%s: Cannot execute generator function because it is currently executing", "", kjstTypeError, 0)
305305
RT_ERROR_MSG(JSERR_LengthIsTooBig, 5619, "Length property would exceed maximum value in output from '%s'", "", kjstTypeError, 0)
306306
RT_ERROR_MSG(JSERR_NonObjectFromIterable, 5620, "Iterable provided to %s must not return non-object or null value.", "", kjstTypeError, 0)
307-
// 5621-5626 Unused
307+
RT_ERROR_MSG(JSERR_EmptyArrayAndInitValueNotPresent, 5621, "%s: Array contains no elements and initialValue is not provided", "", kjstTypeError, 0)
308+
// 5622-5626 Unused
308309
RT_ERROR_MSG(JSERR_NeedConstructor, 5627, "'%s' is not a constructor", "Constructor expected", kjstTypeError, 0)
309310

310311
RT_ERROR_MSG(VBSERR_CantDisplayDate, 32812, "", "The specified date is not available in the current locale's calendar", kjstRangeError, 0)

lib/Runtime/Base/JnDirectFields.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,20 @@ ENTRY(Array_filter)
653653
ENTRY(Array_flat)
654654
ENTRY(Array_flatMap)
655655
ENTRY(Array_forEach)
656+
ENTRY(Array_some)
657+
ENTRY(Array_every)
658+
ENTRY(Array_includes)
659+
ENTRY(Array_reduce)
656660
ENTRY(Object_fromEntries)
657661
ENTRY(FunctionKind)
658662

659663
// EngineInterfaceObject built-ins
660664
ENTRY(builtInJavascriptArrayEntryFilter)
661665
ENTRY(builtInJavascriptArrayEntryForEach)
662666
ENTRY(builtInJavascriptArrayEntryIndexOf)
667+
ENTRY(builtInJavascriptArrayEntrySome)
668+
ENTRY(builtInJavascriptArrayEntryEvery)
669+
ENTRY(builtInJavascriptArrayEntryIncludes)
663670
ENTRY(EngineInterface)
664671
ENTRY(builtInCallInstanceFunction)
665672

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-
// {9FAAF688-ACBA-4092-BA5B-77D97D3CD53A}
7+
// {3149B52F-5789-47B2-83EC-04670A814491}
88
const GUID byteCodeCacheReleaseFileVersion =
9-
{ 0x9FAAF688, 0xACBA, 0x4092, { 0xBA, 0x5B, 0x77, 0xD9, 0x7D, 0x3C, 0xD5, 0x3A } };
9+
{ 0x3149B52F, 0x5789, 0x47B2, { 0x83, 0xEC, 0x04, 0x67, 0x0A, 0x81, 0x44, 0x91 } };

lib/Runtime/Library/EngineInterfaceObjectBuiltIns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ BuiltInRaiseException1(TypeError, NotAConstructor)
105105
BuiltInRaiseException1(TypeError, ObjectIsNonExtensible)
106106
BuiltInRaiseException1(TypeError, LengthIsTooBig)
107107
BuiltInRaiseException1(TypeError, NonObjectFromIterable)
108+
BuiltInRaiseException1(TypeError, EmptyArrayAndInitValueNotPresent)
108109
BuiltInRaiseException2(TypeError, NeedObjectOfType)
109110
BuiltInRaiseException1(RangeError, InvalidCurrencyCode)
110111
BuiltInRaiseException(TypeError, MissingCurrencyCode)

lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Lines changed: 785 additions & 785 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Lines changed: 788 additions & 788 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Lines changed: 793 additions & 793 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Lines changed: 772 additions & 772 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JavascriptArray.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9903,9 +9903,13 @@ using namespace Js;
99039903
JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext());
99049904

99059905
AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Array.prototype.reduce"));
9906-
9906+
9907+
#ifdef ENABLE_JS_BUILTINS
9908+
Assert(!scriptContext->IsJsBuiltInEnabled());
9909+
#endif
9910+
99079911
CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(Array_Prototype_reduce);
9908-
9912+
99099913
Assert(!(callInfo.Flags & CallFlags_New));
99109914

99119915
if (args.Info.Count == 0)
@@ -9964,7 +9968,14 @@ using namespace Js;
99649968
{
99659969
if (length == 0)
99669970
{
9967-
JavascriptError::ThrowTypeError(scriptContext, VBSERR_ActionNotSupported);
9971+
if (typedArrayBase)
9972+
{
9973+
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("TypedArray.prototype.reduce"));
9974+
}
9975+
else
9976+
{
9977+
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("Array.prototype.reduce"));
9978+
}
99689979
}
99699980

99709981
bool bPresent = false;
@@ -9999,7 +10010,14 @@ using namespace Js;
999910010

1000010011
if (bPresent == false)
1000110012
{
10002-
JavascriptError::ThrowTypeError(scriptContext, VBSERR_ActionNotSupported);
10013+
if (typedArrayBase)
10014+
{
10015+
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("TypedArray.prototype.reduce"));
10016+
}
10017+
else
10018+
{
10019+
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("Array.prototype.reduce"));
10020+
}
1000310021
}
1000410022
}
1000510023

lib/Runtime/Library/JavascriptLibrary.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,15 +1798,12 @@ namespace Js
17981798
if (!scriptContext->IsJsBuiltInEnabled())
17991799
{
18001800
builtinFuncs[BuiltinFunction::JavascriptArray_IndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::indexOf, &JavascriptArray::EntryInfo::IndexOf, 1);
1801+
builtinFuncs[BuiltinFunction::JavascriptArray_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);
18011802
}
18021803

1803-
/* No inlining Array_Every */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::every, &JavascriptArray::EntryInfo::Every, 1);
1804-
18051804
builtinFuncs[BuiltinFunction::JavascriptArray_LastIndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::lastIndexOf, &JavascriptArray::EntryInfo::LastIndexOf, 1);
18061805
/* No inlining Array_Map */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::map, &JavascriptArray::EntryInfo::Map, 1);
1807-
/* No inlining Array_Reduce */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduce, &JavascriptArray::EntryInfo::Reduce, 1);
18081806
/* No inlining Array_ReduceRight */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduceRight, &JavascriptArray::EntryInfo::ReduceRight, 1);
1809-
/* No inlining Array_Some */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::some, &JavascriptArray::EntryInfo::Some, 1);
18101807

18111808
if (scriptContext->GetConfig()->IsES6StringExtensionsEnabled()) // This is not a typo, Array.prototype.find and .findIndex are part of the ES6 Improved String APIs feature
18121809
{
@@ -1834,6 +1831,9 @@ namespace Js
18341831

18351832
/* No inlining Array_Filter */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::filter, &JavascriptArray::EntryInfo::Filter, 1);
18361833
/* No inlining Array_ForEach */ library->AddMember(arrayPrototype, PropertyIds::forEach, library->EnsureArrayPrototypeForEachFunction());
1834+
/* No inlining Array_Some */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::some, &JavascriptArray::EntryInfo::Some, 1);
1835+
/* No inlining Array_Reduce */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduce, &JavascriptArray::EntryInfo::Reduce, 1);
1836+
/* No inlining Array_Every */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::every, &JavascriptArray::EntryInfo::Every, 1);
18371837
}
18381838

18391839
if (scriptContext->GetConfig()->IsES6UnscopablesEnabled())
@@ -1854,8 +1854,6 @@ namespace Js
18541854
/* No inlining Array_Fill */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::fill, &JavascriptArray::EntryInfo::Fill, 1);
18551855
/* No inlining Array_CopyWithin */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::copyWithin, &JavascriptArray::EntryInfo::CopyWithin, 2);
18561856

1857-
builtinFuncs[BuiltinFunction::JavascriptArray_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);
1858-
18591857
DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));
18601858

18611859
arrayPrototype->SetHasNoEnumerableProperties(true);

0 commit comments

Comments
 (0)