| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 &resolve, &reject); | 50 &resolve, &reject); |
| 51 | 51 |
| 52 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); | 52 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); |
| 53 result->set(0, *resolve); | 53 result->set(0, *resolve); |
| 54 result->set(1, *reject); | 54 result->set(1, *reject); |
| 55 | 55 |
| 56 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, | 56 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, |
| 57 NOT_TENURED); | 57 NOT_TENURED); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void PromiseInit(CodeStubAssembler* a, compiler::Node* promise, | |
| 61 compiler::Node* status, compiler::Node* result) { | |
| 62 CSA_ASSERT(a, a->TaggedIsSmi(status)); | |
| 63 a->StoreObjectField(promise, JSPromise::kStatusOffset, status); | |
| 64 a->StoreObjectField(promise, JSPromise::kResultOffset, result); | |
| 65 a->StoreObjectField(promise, JSPromise::kFlagsOffset, a->SmiConstant(0)); | |
| 66 } | |
| 67 | |
| 68 void Builtins::Generate_PromiseConstructor( | 60 void Builtins::Generate_PromiseConstructor( |
| 69 compiler::CodeAssemblerState* state) { | 61 compiler::CodeAssemblerState* state) { |
| 70 CodeStubAssembler a(state); | 62 CodeStubAssembler a(state); |
| 71 typedef CodeStubAssembler::Variable Variable; | 63 typedef CodeStubAssembler::Variable Variable; |
| 72 typedef CodeStubAssembler::Label Label; | 64 typedef CodeStubAssembler::Label Label; |
| 73 typedef compiler::Node Node; | 65 typedef compiler::Node Node; |
| 74 | 66 |
| 75 Node* const executor = a.Parameter(1); | 67 Node* const executor = a.Parameter(1); |
| 76 Node* const new_target = a.Parameter(2); | 68 Node* const new_target = a.Parameter(2); |
| 77 Node* const context = a.Parameter(4); | 69 Node* const context = a.Parameter(4); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 97 | 89 |
| 98 a.Branch(a.WordEqual(promise_fun, new_target), &if_targetisnotmodified, | 90 a.Branch(a.WordEqual(promise_fun, new_target), &if_targetisnotmodified, |
| 99 &if_targetismodified); | 91 &if_targetismodified); |
| 100 | 92 |
| 101 Variable var_result(&a, MachineRepresentation::kTagged), | 93 Variable var_result(&a, MachineRepresentation::kTagged), |
| 102 var_reject_call(&a, MachineRepresentation::kTagged), | 94 var_reject_call(&a, MachineRepresentation::kTagged), |
| 103 var_reason(&a, MachineRepresentation::kTagged); | 95 var_reason(&a, MachineRepresentation::kTagged); |
| 104 | 96 |
| 105 a.Bind(&if_targetisnotmodified); | 97 a.Bind(&if_targetisnotmodified); |
| 106 { | 98 { |
| 107 Node* const initial_map = a.LoadObjectField( | 99 Node* const instance = a.AllocateJSPromise(context); |
| 108 promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | |
| 109 | |
| 110 Node* const instance = a.AllocateJSObjectFromMap(initial_map); | |
| 111 var_result.Bind(instance); | 100 var_result.Bind(instance); |
| 112 a.Goto(&init); | 101 a.Goto(&init); |
| 113 } | 102 } |
| 114 | 103 |
| 115 a.Bind(&if_targetismodified); | 104 a.Bind(&if_targetismodified); |
| 116 { | 105 { |
| 117 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); | 106 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); |
| 118 Node* const instance = | 107 Node* const instance = |
| 119 a.CallStub(fast_new_object_stub, context, promise_fun, new_target); | 108 a.CallStub(fast_new_object_stub, context, promise_fun, new_target); |
| 120 | 109 |
| 121 var_result.Bind(instance); | 110 var_result.Bind(instance); |
| 122 a.Goto(&init); | 111 a.Goto(&init); |
| 123 } | 112 } |
| 124 | 113 |
| 125 a.Bind(&init); | 114 a.Bind(&init); |
| 126 { | 115 { |
| 127 PromiseInit(&a, var_result.value(), a.SmiConstant(kPromisePending), | 116 a.PromiseInit(var_result.value()); |
| 128 a.UndefinedConstant()); | |
| 129 a.Branch(is_debug_active, &debug_push, &run_executor); | 117 a.Branch(is_debug_active, &debug_push, &run_executor); |
| 130 } | 118 } |
| 131 | 119 |
| 132 a.Bind(&debug_push); | 120 a.Bind(&debug_push); |
| 133 { | 121 { |
| 134 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); | 122 a.CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); |
| 135 a.Goto(&run_executor); | 123 a.Goto(&run_executor); |
| 136 } | 124 } |
| 137 | 125 |
| 138 a.Bind(&run_executor); | 126 a.Bind(&run_executor); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 a.Return(a.UndefinedConstant()); // Never reached. | 177 a.Return(a.UndefinedConstant()); // Never reached. |
| 190 } | 178 } |
| 191 } | 179 } |
| 192 | 180 |
| 193 void Builtins::Generate_PromiseInternalConstructor( | 181 void Builtins::Generate_PromiseInternalConstructor( |
| 194 compiler::CodeAssemblerState* state) { | 182 compiler::CodeAssemblerState* state) { |
| 195 typedef compiler::Node Node; | 183 typedef compiler::Node Node; |
| 196 CodeStubAssembler a(state); | 184 CodeStubAssembler a(state); |
| 197 | 185 |
| 198 Node* const context = a.Parameter(3); | 186 Node* const context = a.Parameter(3); |
| 199 Node* const native_context = a.LoadNativeContext(context); | 187 Node* const instance = a.AllocateJSPromise(context); |
| 200 Node* const promise_fun = | 188 a.PromiseInit(instance); |
| 201 a.LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | |
| 202 Node* const initial_map = | |
| 203 a.LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | |
| 204 Node* const instance = a.AllocateJSObjectFromMap(initial_map); | |
| 205 | |
| 206 PromiseInit(&a, instance, a.SmiConstant(kPromisePending), | |
| 207 a.UndefinedConstant()); | |
| 208 a.Return(instance); | 189 a.Return(instance); |
| 209 } | 190 } |
| 210 | 191 |
| 211 void Builtins::Generate_PromiseCreateAndSet( | 192 void Builtins::Generate_PromiseCreateAndSet( |
| 212 compiler::CodeAssemblerState* state) { | 193 compiler::CodeAssemblerState* state) { |
| 213 typedef compiler::Node Node; | 194 typedef compiler::Node Node; |
| 214 CodeStubAssembler a(state); | 195 CodeStubAssembler a(state); |
| 215 | 196 |
| 216 Node* const status = a.Parameter(1); | 197 Node* const status = a.Parameter(1); |
| 217 Node* const result = a.Parameter(2); | 198 Node* const result = a.Parameter(2); |
| 218 Node* const context = a.Parameter(5); | 199 Node* const context = a.Parameter(5); |
| 219 Node* const native_context = a.LoadNativeContext(context); | |
| 220 | 200 |
| 221 Node* const promise_fun = | 201 Node* const instance = a.AllocateJSPromise(context); |
| 222 a.LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | 202 a.PromiseSet(instance, status, result); |
| 223 Node* const initial_map = | |
| 224 a.LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | |
| 225 Node* const instance = a.AllocateJSObjectFromMap(initial_map); | |
| 226 | |
| 227 PromiseInit(&a, instance, status, result); | |
| 228 a.Return(instance); | 203 a.Return(instance); |
| 229 } | 204 } |
| 230 | 205 |
| 231 namespace { | 206 namespace { |
| 232 | 207 |
| 233 compiler::Node* ThrowIfNotJSReceiver(CodeStubAssembler* a, Isolate* isolate, | 208 compiler::Node* ThrowIfNotJSReceiver(CodeStubAssembler* a, Isolate* isolate, |
| 234 compiler::Node* context, | 209 compiler::Node* context, |
| 235 compiler::Node* value, | 210 compiler::Node* value, |
| 236 MessageTemplate::Template msg_template) { | 211 MessageTemplate::Template msg_template) { |
| 237 typedef compiler::Node Node; | 212 typedef compiler::Node Node; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 | 862 |
| 888 Label out(&a); | 863 Label out(&a); |
| 889 InternalResolvePromise(&a, context, promise, result, &out); | 864 InternalResolvePromise(&a, context, promise, result, &out); |
| 890 | 865 |
| 891 a.Bind(&out); | 866 a.Bind(&out); |
| 892 a.Return(a.UndefinedConstant()); | 867 a.Return(a.UndefinedConstant()); |
| 893 } | 868 } |
| 894 | 869 |
| 895 } // namespace internal | 870 } // namespace internal |
| 896 } // namespace v8 | 871 } // namespace v8 |
| OLD | NEW |