Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Unified Diff: src/builtins/builtins-array-gen.cc

Issue 2765293002: [Builtins] Provide a code-stub impl. of Array.prototype.map (Closed)
Patch Set: Comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-array-gen.cc
diff --git a/src/builtins/builtins-array-gen.cc b/src/builtins/builtins-array-gen.cc
index 41a75c49b0b660e7be0aa1be8ef9ba9cfc7d0c85..4764d2341bb1808b556f362ba50d4c4977365f9d 100644
--- a/src/builtins/builtins-array-gen.cc
+++ b/src/builtins/builtins-array-gen.cc
@@ -129,24 +129,42 @@ class ArrayBuiltinCodeStubAssembler : public CodeStubAssembler {
}
Node* FilterProcessor(Node* k_value, Node* k) {
- Node* callback_result = CallJS(CodeFactory::Call(isolate()), context(),
- callbackfn(), this_arg(), k_value, k, o());
+ // ii. Let selected be ToBoolean(? Call(callbackfn, T, kValue, k, O)).
+ Node* selected = CallJS(CodeFactory::Call(isolate()), context(),
+ callbackfn(), this_arg(), k_value, k, o());
Label true_continue(this, &to_), false_continue(this);
- BranchIfToBooleanIsTrue(callback_result, &true_continue, &false_continue);
+ BranchIfToBooleanIsTrue(selected, &true_continue, &false_continue);
Bind(&true_continue);
+ // iii. If selected is true, then...
+ {
+ // 1. Perform ? CreateDataPropertyOrThrow(A, ToString(to), kValue).
+ CallRuntime(Runtime::kCreateDataProperty, context(), a(), to_.value(),
+ k_value);
- // 1. let status be CreateDataPropertyOrThrow(A, ToString(to), kValue).
- // 2. ReturnIfAbrupt(status)
- Node* const p_to = ToString(context(), to_.value());
- CallRuntime(Runtime::kCreateDataProperty, context(), a(), p_to, k_value);
-
- // 3. Increase to by 1.
- to_.Bind(NumberInc(to_.value()));
- Goto(&false_continue);
+ // 2. Increase to by 1.
+ to_.Bind(NumberInc(to_.value()));
+ Goto(&false_continue);
+ }
Bind(&false_continue);
return a();
}
+ Node* MapResultGenerator() {
+ // 5. Let A be ? ArraySpeciesCreate(O, len).
+ return ArraySpeciesCreate(context(), o(), len_);
+ }
+
+ Node* MapProcessor(Node* k_value, Node* k) {
+ // i. Let kValue be ? Get(O, Pk). Performed by the caller of MapProcessor.
+ // ii. Let mappedValue be ? Call(callbackfn, T, kValue, k, O).
+ Node* mappedValue = CallJS(CodeFactory::Call(isolate()), context(),
+ callbackfn(), this_arg(), k_value, k, o());
+
+ // iii. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue).
+ CallRuntime(Runtime::kCreateDataProperty, context(), a(), k, mappedValue);
+ return a();
+ }
+
void NullPostLoopAction() {}
protected:
@@ -770,13 +788,50 @@ TF_BUILTIN(ArrayFilter, ArrayBuiltinCodeStubAssembler) {
new_target);
GenerateIteratingArrayBuiltinBody(
- "Array.prototype.reduce",
+ "Array.prototype.filter",
&ArrayBuiltinCodeStubAssembler::FilterResultGenerator,
&ArrayBuiltinCodeStubAssembler::FilterProcessor,
&ArrayBuiltinCodeStubAssembler::NullPostLoopAction,
CodeFactory::ArrayFilterLoopContinuation(isolate()));
}
+TF_BUILTIN(ArrayMapLoopContinuation, ArrayBuiltinCodeStubAssembler) {
+ Node* context = Parameter(Descriptor::kContext);
+ Node* receiver = Parameter(Descriptor::kReceiver);
+ Node* callbackfn = Parameter(Descriptor::kCallbackFn);
+ Node* this_arg = Parameter(Descriptor::kThisArg);
+ Node* array = Parameter(Descriptor::kArray);
+ Node* object = Parameter(Descriptor::kObject);
+ Node* initial_k = Parameter(Descriptor::kInitialK);
+ Node* len = Parameter(Descriptor::kLength);
+ Node* to = Parameter(Descriptor::kTo);
+
+ InitIteratingArrayBuiltinLoopContinuation(context, receiver, callbackfn,
+ this_arg, array, object, initial_k,
+ len, to);
+
+ GenerateIteratingArrayBuiltinLoopContinuation(
+ &ArrayBuiltinCodeStubAssembler::MapProcessor,
+ &ArrayBuiltinCodeStubAssembler::NullPostLoopAction);
+}
+
+TF_BUILTIN(ArrayMap, ArrayBuiltinCodeStubAssembler) {
+ Node* context = Parameter(Descriptor::kContext);
+ Node* receiver = Parameter(Descriptor::kReceiver);
+ Node* callbackfn = Parameter(Descriptor::kCallbackFn);
+ Node* this_arg = Parameter(Descriptor::kThisArg);
+ Node* new_target = Parameter(Descriptor::kNewTarget);
+
+ InitIteratingArrayBuiltinBody(context, receiver, callbackfn, this_arg,
+ new_target);
+
+ GenerateIteratingArrayBuiltinBody(
+ "Array.prototype.map", &ArrayBuiltinCodeStubAssembler::MapResultGenerator,
+ &ArrayBuiltinCodeStubAssembler::MapProcessor,
+ &ArrayBuiltinCodeStubAssembler::NullPostLoopAction,
+ CodeFactory::ArrayMapLoopContinuation(isolate()));
+}
+
TF_BUILTIN(ArrayIsArray, CodeStubAssembler) {
Node* object = Parameter(Descriptor::kArg);
Node* context = Parameter(Descriptor::kContext);
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698