Skip to content

Commit

Permalink
[MERGE chakra-core#5723 @yullin-ms] Implemented every, some, includes…
Browse files Browse the repository at this point in the history
…, and reduce for array.prototype as JsBuiltIn

Merge pull request chakra-core#5723 from yullin-ms:arrayEverySomeIncludesReduce

Implemented every, some, includes, and reduce for array.prototype as JsBuiltIn
  • Loading branch information
yullin-ms committed Oct 4, 2018
2 parents 9a951e2 + 45c0553 commit 833faff
Show file tree
Hide file tree
Showing 18 changed files with 7,575 additions and 5,878 deletions.
3 changes: 2 additions & 1 deletion lib/Parser/rterrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ RT_ERROR_MSG(JSERR_ObjectIsNotInitialized, 5617, "%s: Object internal state is n
RT_ERROR_MSG(JSERR_GeneratorAlreadyExecuting, 5618, "%s: Cannot execute generator function because it is currently executing", "", kjstTypeError, 0)
RT_ERROR_MSG(JSERR_LengthIsTooBig, 5619, "Length property would exceed maximum value in output from '%s'", "", kjstTypeError, 0)
RT_ERROR_MSG(JSERR_NonObjectFromIterable, 5620, "Iterable provided to %s must not return non-object or null value.", "", kjstTypeError, 0)
// 5621-5626 Unused
RT_ERROR_MSG(JSERR_EmptyArrayAndInitValueNotPresent, 5621, "%s: Array contains no elements and initialValue is not provided", "", kjstTypeError, 0)
// 5622-5626 Unused
RT_ERROR_MSG(JSERR_NeedConstructor, 5627, "'%s' is not a constructor", "Constructor expected", kjstTypeError, 0)

RT_ERROR_MSG(VBSERR_CantDisplayDate, 32812, "", "The specified date is not available in the current locale's calendar", kjstRangeError, 0)
Expand Down
7 changes: 7 additions & 0 deletions lib/Runtime/Base/JnDirectFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,13 +653,20 @@ ENTRY(Array_filter)
ENTRY(Array_flat)
ENTRY(Array_flatMap)
ENTRY(Array_forEach)
ENTRY(Array_some)
ENTRY(Array_every)
ENTRY(Array_includes)
ENTRY(Array_reduce)
ENTRY(Object_fromEntries)
ENTRY(FunctionKind)

// EngineInterfaceObject built-ins
ENTRY(builtInJavascriptArrayEntryFilter)
ENTRY(builtInJavascriptArrayEntryForEach)
ENTRY(builtInJavascriptArrayEntryIndexOf)
ENTRY(builtInJavascriptArrayEntrySome)
ENTRY(builtInJavascriptArrayEntryEvery)
ENTRY(builtInJavascriptArrayEntryIncludes)
ENTRY(EngineInterface)
ENTRY(builtInCallInstanceFunction)

Expand Down
4 changes: 2 additions & 2 deletions lib/Runtime/ByteCode/ByteCodeCacheReleaseFileVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
//-------------------------------------------------------------------------------------------------------
// NOTE: If there is a merge conflict the correct fix is to make a new GUID.

// {9FAAF688-ACBA-4092-BA5B-77D97D3CD53A}
// {3149B52F-5789-47B2-83EC-04670A814491}
const GUID byteCodeCacheReleaseFileVersion =
{ 0x9FAAF688, 0xACBA, 0x4092, { 0xBA, 0x5B, 0x77, 0xD9, 0x7D, 0x3C, 0xD5, 0x3A } };
{ 0x3149B52F, 0x5789, 0x47B2, { 0x83, 0xEC, 0x04, 0x67, 0x0A, 0x81, 0x44, 0x91 } };
1 change: 1 addition & 0 deletions lib/Runtime/Library/EngineInterfaceObjectBuiltIns.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ BuiltInRaiseException1(TypeError, NotAConstructor)
BuiltInRaiseException1(TypeError, ObjectIsNonExtensible)
BuiltInRaiseException1(TypeError, LengthIsTooBig)
BuiltInRaiseException1(TypeError, NonObjectFromIterable)
BuiltInRaiseException1(TypeError, EmptyArrayAndInitValueNotPresent)
BuiltInRaiseException2(TypeError, NeedObjectOfType)
BuiltInRaiseException1(RangeError, InvalidCurrencyCode)
BuiltInRaiseException(TypeError, MissingCurrencyCode)
Expand Down
1,570 changes: 785 additions & 785 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Large diffs are not rendered by default.

1,576 changes: 788 additions & 788 deletions lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Large diffs are not rendered by default.

1,586 changes: 793 additions & 793 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Large diffs are not rendered by default.

1,544 changes: 772 additions & 772 deletions lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions lib/Runtime/Library/JavascriptArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9903,9 +9903,13 @@ using namespace Js;
JS_REENTRANCY_LOCK(jsReentLock, scriptContext->GetThreadContext());

AUTO_TAG_NATIVE_LIBRARY_ENTRY(function, callInfo, _u("Array.prototype.reduce"));


#ifdef ENABLE_JS_BUILTINS
Assert(!scriptContext->IsJsBuiltInEnabled());
#endif

CHAKRATEL_LANGSTATS_INC_BUILTINCOUNT(Array_Prototype_reduce);

Assert(!(callInfo.Flags & CallFlags_New));

if (args.Info.Count == 0)
Expand Down Expand Up @@ -9964,7 +9968,14 @@ using namespace Js;
{
if (length == 0)
{
JavascriptError::ThrowTypeError(scriptContext, VBSERR_ActionNotSupported);
if (typedArrayBase)
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("TypedArray.prototype.reduce"));
}
else
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("Array.prototype.reduce"));
}
}

bool bPresent = false;
Expand Down Expand Up @@ -9999,7 +10010,14 @@ using namespace Js;

if (bPresent == false)
{
JavascriptError::ThrowTypeError(scriptContext, VBSERR_ActionNotSupported);
if (typedArrayBase)
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("TypedArray.prototype.reduce"));
}
else
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_EmptyArrayAndInitValueNotPresent, _u("Array.prototype.reduce"));
}
}
}

Expand Down
10 changes: 4 additions & 6 deletions lib/Runtime/Library/JavascriptLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,15 +1798,12 @@ namespace Js
if (!scriptContext->IsJsBuiltInEnabled())
{
builtinFuncs[BuiltinFunction::JavascriptArray_IndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::indexOf, &JavascriptArray::EntryInfo::IndexOf, 1);
builtinFuncs[BuiltinFunction::JavascriptArray_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);
}

/* No inlining Array_Every */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::every, &JavascriptArray::EntryInfo::Every, 1);

builtinFuncs[BuiltinFunction::JavascriptArray_LastIndexOf] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::lastIndexOf, &JavascriptArray::EntryInfo::LastIndexOf, 1);
/* No inlining Array_Map */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::map, &JavascriptArray::EntryInfo::Map, 1);
/* No inlining Array_Reduce */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduce, &JavascriptArray::EntryInfo::Reduce, 1);
/* No inlining Array_ReduceRight */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::reduceRight, &JavascriptArray::EntryInfo::ReduceRight, 1);
/* No inlining Array_Some */ library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::some, &JavascriptArray::EntryInfo::Some, 1);

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

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

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

builtinFuncs[BuiltinFunction::JavascriptArray_Includes] = library->AddFunctionToLibraryObject(arrayPrototype, PropertyIds::includes, &JavascriptArray::EntryInfo::Includes, 1);

DebugOnly(CheckRegisteredBuiltIns(builtinFuncs, scriptContext));

arrayPrototype->SetHasNoEnumerableProperties(true);
Expand Down
Loading

0 comments on commit 833faff

Please sign in to comment.