OLD | NEW |
---|---|
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...) Loading... | |
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); |
Igor Sheludko
2016/12/13 23:42:34
Please make it IntPtrConstant...
gsathya
2016/12/19 20:12:43
Done.
| |
57 NOT_TENURED); | 58 const ElementsKind kind = FAST_ELEMENTS; |
59 const WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER; | |
60 Node* const arr = a.AllocateFixedArray(kind, kSize); | |
Igor Sheludko
2016/12/13 23:42:34
and pass here INTPTR_PARAMETERS.
1) INTPTR paramet
gsathya
2016/12/19 20:12:43
Done.
| |
61 a.StoreFixedArrayElement(arr, 0, resolve, barrier_mode); | |
62 a.StoreFixedArrayElement(arr, 1, reject, barrier_mode); | |
63 | |
64 Node* const array_map = a.LoadJSArrayElementsMap(kind, native_context); | |
65 Node* const length = a.SmiTag(kSize); | |
66 Node* const result = a.AllocateUninitializedJSArrayWithoutElements( | |
67 kind, array_map, length, nullptr); | |
68 | |
69 a.StoreObjectField(result, JSObject::kElementsOffset, arr); | |
70 a.Return(result); | |
58 } | 71 } |
59 | 72 |
60 void Builtins::Generate_PromiseConstructor( | 73 void Builtins::Generate_PromiseConstructor( |
61 compiler::CodeAssemblerState* state) { | 74 compiler::CodeAssemblerState* state) { |
62 CodeStubAssembler a(state); | 75 CodeStubAssembler a(state); |
63 typedef CodeStubAssembler::Variable Variable; | 76 typedef CodeStubAssembler::Variable Variable; |
64 typedef CodeStubAssembler::Label Label; | 77 typedef CodeStubAssembler::Label Label; |
65 typedef compiler::Node Node; | 78 typedef compiler::Node Node; |
66 | 79 |
67 Node* const executor = a.Parameter(1); | 80 Node* const executor = a.Parameter(1); |
(...skipping 52 matching lines...) Loading... | |
120 a.Bind(&debug_push); | 133 a.Bind(&debug_push); |
121 { | 134 { |
122 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); | 135 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); |
123 a.Goto(&run_executor); | 136 a.Goto(&run_executor); |
124 } | 137 } |
125 | 138 |
126 a.Bind(&run_executor); | 139 a.Bind(&run_executor); |
127 { | 140 { |
128 Label out(&a), if_rejectpromise(&a), debug_pop(&a, Label::kDeferred); | 141 Label out(&a), if_rejectpromise(&a), debug_pop(&a, Label::kDeferred); |
129 | 142 |
130 // TODO(gsathya): Move this to TF. | 143 Node* resolve = nullptr; |
131 Node* const resolving_functions = a.CallRuntime( | 144 Node* reject = nullptr; |
132 Runtime::kCreateResolvingFunctions, context, var_result.value()); | 145 |
133 Node* const resolve = | 146 std::tie(resolve, reject) = a.CreatePromiseResolvingFunctions( |
134 a.LoadFixedArrayElement(resolving_functions, a.IntPtrConstant(0)); | 147 var_result.value(), a.TrueConstant(), native_context); |
135 Node* const reject = | 148 |
136 a.LoadFixedArrayElement(resolving_functions, a.IntPtrConstant(1)); | |
137 Callable call_callable = CodeFactory::Call(isolate); | 149 Callable call_callable = CodeFactory::Call(isolate); |
138 | 150 |
139 Node* const maybe_exception = | 151 Node* const maybe_exception = |
140 a.CallJS(call_callable, context, executor, a.UndefinedConstant(), | 152 a.CallJS(call_callable, context, executor, a.UndefinedConstant(), |
141 resolve, reject); | 153 resolve, reject); |
142 | 154 |
143 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); | 155 a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); |
144 a.Branch(is_debug_active, &debug_pop, &out); | 156 a.Branch(is_debug_active, &debug_pop, &out); |
145 | 157 |
146 a.Bind(&if_rejectpromise); | 158 a.Bind(&if_rejectpromise); |
(...skipping 715 matching lines...) Loading... | |
862 | 874 |
863 Label out(&a); | 875 Label out(&a); |
864 InternalResolvePromise(&a, context, promise, result, &out); | 876 InternalResolvePromise(&a, context, promise, result, &out); |
865 | 877 |
866 a.Bind(&out); | 878 a.Bind(&out); |
867 a.Return(a.UndefinedConstant()); | 879 a.Return(a.UndefinedConstant()); |
868 } | 880 } |
869 | 881 |
870 } // namespace internal | 882 } // namespace internal |
871 } // namespace v8 | 883 } // namespace v8 |
OLD | NEW |