[builtins] Implement %TypedArray%.prototype.forEach in the CSA
Bug: Change-Id: I472cc64bfbbef5ce6643b506b1fcb56c1cee5f24 Reviewed-on: https://chromium-review.googlesource.com/509715 Reviewed-by: Daniel Clifford <danno@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#45463}
This commit is contained in:
parent
dfc4d3f3a4
commit
0819f4c289
@ -2783,6 +2783,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
Builtins::kTypedArrayPrototypeEvery, 1, false);
|
||||
SimpleInstallFunction(prototype, "fill",
|
||||
Builtins::kTypedArrayPrototypeFill, 1, false);
|
||||
SimpleInstallFunction(prototype, "forEach",
|
||||
Builtins::kTypedArrayPrototypeForEach, 1, false);
|
||||
SimpleInstallFunction(prototype, "includes",
|
||||
Builtins::kTypedArrayPrototypeIncludes, 1, false);
|
||||
SimpleInstallFunction(prototype, "indexOf",
|
||||
|
@ -1225,6 +1225,26 @@ TF_BUILTIN(ArrayForEach, ArrayBuiltinCodeStubAssembler) {
|
||||
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) {
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
Node* receiver = Parameter(Descriptor::kReceiver);
|
||||
|
@ -948,6 +948,9 @@ namespace internal {
|
||||
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
|
||||
/* ES6 %TypedArray%.prototype.map */ \
|
||||
TFJ(TypedArrayPrototypeMap, SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
|
||||
/* ES6 %TypedArray%.prototype.forEach */ \
|
||||
TFJ(TypedArrayPrototypeForEach, \
|
||||
SharedFunctionInfo::kDontAdaptArgumentsSentinel) \
|
||||
\
|
||||
/* Wasm */ \
|
||||
ASM(WasmCompileLazy) \
|
||||
|
@ -366,36 +366,6 @@ function TypedArrayGetToStringTag() {
|
||||
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
|
||||
// preserving the semantics, since the calls to the receiver function can add
|
||||
// or delete elements from the array.
|
||||
@ -567,7 +537,6 @@ utils.InstallFunctions(GlobalTypedArray.prototype, DONT_ENUM, [
|
||||
"find", TypedArrayFind,
|
||||
"findIndex", TypedArrayFindIndex,
|
||||
"join", TypedArrayJoin,
|
||||
"forEach", TypedArrayForEach,
|
||||
"sort", TypedArraySort,
|
||||
"toLocaleString", TypedArrayToLocaleString
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user