Chromium Code Reviews

Side by Side Diff: src/builtins/builtins-promise.cc

Issue 2567033003: [promises] Port CreateResolvingFunctions to TF (Closed)
Patch Set: add tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stub-assembler.h" 8 #include "src/code-stub-assembler.h"
9 #include "src/promise-utils.h" 9 #include "src/promise-utils.h"
10 10
(...skipping 20 matching lines...)
31 Handle<Object> argv[] = {promise, value, debug_event}; 31 Handle<Object> argv[] = {promise, value, debug_event};
32 RETURN_FAILURE_ON_EXCEPTION( 32 RETURN_FAILURE_ON_EXCEPTION(
33 isolate, Execution::Call(isolate, isolate->promise_internal_reject(), 33 isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
34 isolate->factory()->undefined_value(), 34 isolate->factory()->undefined_value(),
35 arraysize(argv), argv)); 35 arraysize(argv), argv));
36 return isolate->heap()->undefined_value(); 36 return isolate->heap()->undefined_value();
37 } 37 }
38 38
39 // ES#sec-createresolvingfunctions 39 // ES#sec-createresolvingfunctions
40 // CreateResolvingFunctions ( promise ) 40 // CreateResolvingFunctions ( promise )
41 BUILTIN(CreateResolvingFunctions) { 41 void Builtins::Generate_CreateResolvingFunctions(
42 HandleScope scope(isolate); 42 compiler::CodeAssemblerState* state) {
43 DCHECK_EQ(3, args.length()); 43 CodeStubAssembler a(state);
44 typedef compiler::Node Node;
44 45
45 Handle<JSObject> promise = args.at<JSObject>(1); 46 Node* const promise = a.Parameter(1);
46 Handle<Object> debug_event = args.at<Object>(2); 47 Node* const debug_event = a.Parameter(2);
47 Handle<JSFunction> resolve, reject; 48 Node* const context = a.Parameter(5);
49 Node* const native_context = a.LoadNativeContext(context);
48 50
49 PromiseUtils::CreateResolvingFunctions(isolate, promise, debug_event, 51 Node* resolve = nullptr;
50 &resolve, &reject); 52 Node* reject = nullptr;
51 53
52 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); 54 std::tie(resolve, reject) =
53 result->set(0, *resolve); 55 a.CreatePromiseResolvingFunctions(promise, debug_event, native_context);
54 result->set(1, *reject);
55 56
56 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, 57 Node* const kSize = a.Int32Constant(2);
57 NOT_TENURED); 58 Node* const arr = a.AllocateFixedArray(FAST_ELEMENTS, kSize);
59 a.StoreFixedArrayElement(arr, 0, resolve);
jgruber 2016/12/13 10:44:04 We can skip write barriers when arr is guaranteed
gsathya 2016/12/13 13:01:46 Done.
60 a.StoreFixedArrayElement(arr, 1, reject);
61
62 const ElementsKind kind = FAST_ELEMENTS;
jgruber 2016/12/13 10:44:04 If you pull this up you could use it in AllocateFi
gsathya 2016/12/13 13:01:46 Done.
63 Node* const array_map = a.LoadJSArrayElementsMap(kind, native_context);
64 Node* const length = a.SmiTag(kSize);
65 Node* const result = a.AllocateUninitializedJSArrayWithoutElements(
66 kind, array_map, length, nullptr);
67
68 a.StoreObjectField(result, JSObject::kElementsOffset, arr);
69 a.Return(result);
58 } 70 }
59 71
60 void Builtins::Generate_PromiseConstructor( 72 void Builtins::Generate_PromiseConstructor(
61 compiler::CodeAssemblerState* state) { 73 compiler::CodeAssemblerState* state) {
62 CodeStubAssembler a(state); 74 CodeStubAssembler a(state);
63 typedef CodeStubAssembler::Variable Variable; 75 typedef CodeStubAssembler::Variable Variable;
64 typedef CodeStubAssembler::Label Label; 76 typedef CodeStubAssembler::Label Label;
65 typedef compiler::Node Node; 77 typedef compiler::Node Node;
66 78
67 Node* const executor = a.Parameter(1); 79 Node* const executor = a.Parameter(1);
(...skipping 52 matching lines...)
120 a.Bind(&debug_push); 132 a.Bind(&debug_push);
121 { 133 {
122 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); 134 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value());
123 a.Goto(&run_executor); 135 a.Goto(&run_executor);
124 } 136 }
125 137
126 a.Bind(&run_executor); 138 a.Bind(&run_executor);
127 { 139 {
128 Label out(&a), if_rejectpromise(&a), debug_pop(&a, Label::kDeferred); 140 Label out(&a), if_rejectpromise(&a), debug_pop(&a, Label::kDeferred);
129 141
130 // TODO(gsathya): Move this to TF. 142 Node* resolve = nullptr;
131 Node* const resolving_functions = a.CallRuntime( 143 Node* reject = nullptr;
132 Runtime::kCreateResolvingFunctions, context, var_result.value()); 144
133 Node* const resolve = 145 std::tie(resolve, reject) = a.CreatePromiseResolvingFunctions(
134 a.LoadFixedArrayElement(resolving_functions, a.IntPtrConstant(0)); 146 var_result.value(), a.BooleanConstant(true), native_context);
jgruber 2016/12/13 10:44:04 a.TrueConstant()
gsathya 2016/12/13 13:01:46 Done.
135 Node* const reject = 147
136 a.LoadFixedArrayElement(resolving_functions, a.IntPtrConstant(1));
137 Callable call_callable = CodeFactory::Call(isolate); 148 Callable call_callable = CodeFactory::Call(isolate);
138 149
139 Node* const maybe_exception = 150 Node* const maybe_exception =
140 a.CallJS(call_callable, context, executor, a.UndefinedConstant(), 151 a.CallJS(call_callable, context, executor, a.UndefinedConstant(),
141 resolve, reject); 152 resolve, reject);
142 153
143 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); 154 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
144 a.Branch(is_debug_active, &debug_pop, &out); 155 a.Branch(is_debug_active, &debug_pop, &out);
145 156
146 a.Bind(&if_rejectpromise); 157 a.Bind(&if_rejectpromise);
(...skipping 715 matching lines...)
862 873
863 Label out(&a); 874 Label out(&a);
864 InternalResolvePromise(&a, context, promise, result, &out); 875 InternalResolvePromise(&a, context, promise, result, &out);
865 876
866 a.Bind(&out); 877 a.Bind(&out);
867 a.Return(a.UndefinedConstant()); 878 a.Return(a.UndefinedConstant());
868 } 879 }
869 880
870 } // namespace internal 881 } // namespace internal
871 } // namespace v8 882 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-stub-assembler.h » ('j') | src/code-stub-assembler.h » ('J')

Powered by Google App Engine