Commit 0819f4c2 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[builtins] Implement %TypedArray%.prototype.forEach in the CSA

Bug: 
Change-Id: I472cc64bfbbef5ce6643b506b1fcb56c1cee5f24
Reviewed-on: https://chromium-review.googlesource.com/509715Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45463}
parent dfc4d3f3
...@@ -2783,6 +2783,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object, ...@@ -2783,6 +2783,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kTypedArrayPrototypeEvery, 1, false); Builtins::kTypedArrayPrototypeEvery, 1, false);
SimpleInstallFunction(prototype, "fill", SimpleInstallFunction(prototype, "fill",
Builtins::kTypedArrayPrototypeFill, 1, false); Builtins::kTypedArrayPrototypeFill, 1, false);
SimpleInstallFunction(prototype, "forEach",
Builtins::kTypedArrayPrototypeForEach, 1, false);
SimpleInstallFunction(prototype, "includes", SimpleInstallFunction(prototype, "includes",
Builtins::kTypedArrayPrototypeIncludes, 1, false); Builtins::kTypedArrayPrototypeIncludes, 1, false);
SimpleInstallFunction(prototype, "indexOf", SimpleInstallFunction(prototype, "indexOf",
......
...@@ -1225,6 +1225,26 @@ TF_BUILTIN(ArrayForEach, ArrayBuiltinCodeStubAssembler) { ...@@ -1225,6 +1225,26 @@ TF_BUILTIN(ArrayForEach, ArrayBuiltinCodeStubAssembler) {
Builtins::kArrayForEachLoopContinuation)); Builtins::kArrayForEachLoopContinuation));
} }
TF_BUILTIN(TypedArrayPrototypeForEach, ArrayBuiltinCodeStubAssembler) {
Node* argc =
ChangeInt32ToIntPtr(Parameter(BuiltinDescriptor::kArgumentsCount));
CodeStubArguments args(this, argc);
Node* context = Parameter(BuiltinDescriptor::kContext);
Node* new_target = Parameter(BuiltinDescriptor::kNewTarget);
Node* receiver = args.GetReceiver();
Node* callbackfn = args.GetOptionalArgumentValue(0, UndefinedConstant());
Node* this_arg = args.GetOptionalArgumentValue(1, UndefinedConstant());
InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg,
new_target, argc);
GenerateIteratingTypedArrayBuiltinBody(
"%TypedArray%.prototype.forEach",
&ArrayBuiltinCodeStubAssembler::ForEachResultGenerator,
&ArrayBuiltinCodeStubAssembler::ForEachProcessor,
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction);
}
TF_BUILTIN(ArraySomeLoopContinuation, ArrayBuiltinCodeStubAssembler) { TF_BUILTIN(ArraySomeLoopContinuation, ArrayBuiltinCodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext); Node* context = Parameter(Descriptor::kContext);
Node* receiver = Parameter(Descriptor::kReceiver); Node* receiver = Parameter(Descriptor::kReceiver);
......
...@@ -948,6 +948,9 @@ namespace internal { ...@@ -948,6 +948,9 @@ namespace internal {
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 %TypedArray%.prototype.map */ \ /* ES6 %TypedArray%.prototype.map */ \
TFJ(TypedArrayPrototypeMap, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \ TFJ(TypedArrayPrototypeMap, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
/* ES6 %TypedArray%.prototype.forEach */ \
TFJ(TypedArrayPrototypeForEach, \
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
\ \
/* Wasm */ \ /* Wasm */ \
ASM(WasmCompileLazy) \ ASM(WasmCompileLazy) \
......
...@@ -366,36 +366,6 @@ function TypedArrayGetToStringTag() { ...@@ -366,36 +366,6 @@ function TypedArrayGetToStringTag() {
return name; return name;
} }
function InnerTypedArrayForEach(f, receiver, array, length) {
if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
if (IS_UNDEFINED(receiver)) {
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
f(element, i, array);
}
}
} else {
for (var i = 0; i < length; i++) {
if (i in array) {
var element = array[i];
%_Call(f, receiver, element, i, array);
}
}
}
}
// ES6 draft 08-24-14, section 22.2.3.12
function TypedArrayForEach(f, receiver) {
ValidateTypedArray(this, "%TypedArray%.prototype.forEach");
var length = %_TypedArrayGetLength(this);
InnerTypedArrayForEach(f, receiver, this, length);
}
%FunctionSetLength(TypedArrayForEach, 1);
// The following functions cannot be made efficient on sparse arrays while // The following functions cannot be made efficient on sparse arrays while
// preserving the semantics, since the calls to the receiver function can add // preserving the semantics, since the calls to the receiver function can add
// or delete elements from the array. // or delete elements from the array.
...@@ -567,7 +537,6 @@ utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [ ...@@ -567,7 +537,6 @@ utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
"find", TypedArrayFind, "find", TypedArrayFind,
"findIndex", TypedArrayFindIndex, "findIndex", TypedArrayFindIndex,
"join", TypedArrayJoin, "join", TypedArrayJoin,
"forEach", TypedArrayForEach,
"sort", TypedArraySort, "sort", TypedArraySort,
"toLocaleString", TypedArrayToLocaleString "toLocaleString", TypedArrayToLocaleString
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment