Chromium Code Reviews| 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 namespace { | |
| 61 | |
| 62 compiler::Node* CreatePromise(CodeStubAssembler* a, compiler::Node* context) { | |
|
caitp
2016/12/12 23:41:58
There are _a lot_ of builtins that need to be able
| |
| 63 typedef compiler::Node Node; | |
| 64 | |
| 65 Node* const native_context = a->LoadNativeContext(context); | |
| 66 Node* const promise_fun = | |
| 67 a->LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | |
| 68 Node* const initial_map = | |
| 69 a->LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | |
| 70 Node* const instance = a->AllocateJSObjectFromMap(initial_map); | |
| 71 | |
| 72 return instance; | |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 | |
| 60 void PromiseInit(CodeStubAssembler* a, compiler::Node* promise, | 77 void PromiseInit(CodeStubAssembler* a, compiler::Node* promise, |
| 61 compiler::Node* status, compiler::Node* result) { | 78 compiler::Node* status, compiler::Node* result) { |
| 62 CSA_ASSERT(a, a->TaggedIsSmi(status)); | 79 CSA_ASSERT(a, a->TaggedIsSmi(status)); |
| 63 a->StoreObjectField(promise, JSPromise::kStatusOffset, status); | 80 a->StoreObjectField(promise, JSPromise::kStatusOffset, status); |
| 64 a->StoreObjectField(promise, JSPromise::kResultOffset, result); | 81 a->StoreObjectField(promise, JSPromise::kResultOffset, result); |
| 65 a->StoreObjectField(promise, JSPromise::kFlagsOffset, a->SmiConstant(0)); | 82 a->StoreObjectField(promise, JSPromise::kFlagsOffset, a->SmiConstant(0)); |
| 66 } | 83 } |
| 67 | 84 |
| 68 void Builtins::Generate_PromiseConstructor( | 85 void Builtins::Generate_PromiseConstructor( |
| 69 compiler::CodeAssemblerState* state) { | 86 compiler::CodeAssemblerState* state) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 97 | 114 |
| 98 a.Branch(a.WordEqual(promise_fun, new_target), &if_targetisnotmodified, | 115 a.Branch(a.WordEqual(promise_fun, new_target), &if_targetisnotmodified, |
| 99 &if_targetismodified); | 116 &if_targetismodified); |
| 100 | 117 |
| 101 Variable var_result(&a, MachineRepresentation::kTagged), | 118 Variable var_result(&a, MachineRepresentation::kTagged), |
| 102 var_reject_call(&a, MachineRepresentation::kTagged), | 119 var_reject_call(&a, MachineRepresentation::kTagged), |
| 103 var_reason(&a, MachineRepresentation::kTagged); | 120 var_reason(&a, MachineRepresentation::kTagged); |
| 104 | 121 |
| 105 a.Bind(&if_targetisnotmodified); | 122 a.Bind(&if_targetisnotmodified); |
| 106 { | 123 { |
| 107 Node* const initial_map = a.LoadObjectField( | 124 Node* const instance = CreatePromise(&a, context); |
| 108 promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | |
| 109 | |
| 110 Node* const instance = a.AllocateJSObjectFromMap(initial_map); | |
| 111 var_result.Bind(instance); | 125 var_result.Bind(instance); |
| 112 a.Goto(&init); | 126 a.Goto(&init); |
| 113 } | 127 } |
| 114 | 128 |
| 115 a.Bind(&if_targetismodified); | 129 a.Bind(&if_targetismodified); |
| 116 { | 130 { |
| 117 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); | 131 Callable fast_new_object_stub = CodeFactory::FastNewObject(isolate); |
| 118 Node* const instance = | 132 Node* const instance = |
| 119 a.CallStub(fast_new_object_stub, context, promise_fun, new_target); | 133 a.CallStub(fast_new_object_stub, context, promise_fun, new_target); |
| 120 | 134 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 a.Return(a.UndefinedConstant()); // Never reached. | 203 a.Return(a.UndefinedConstant()); // Never reached. |
| 190 } | 204 } |
| 191 } | 205 } |
| 192 | 206 |
| 193 void Builtins::Generate_PromiseInternalConstructor( | 207 void Builtins::Generate_PromiseInternalConstructor( |
| 194 compiler::CodeAssemblerState* state) { | 208 compiler::CodeAssemblerState* state) { |
| 195 typedef compiler::Node Node; | 209 typedef compiler::Node Node; |
| 196 CodeStubAssembler a(state); | 210 CodeStubAssembler a(state); |
| 197 | 211 |
| 198 Node* const context = a.Parameter(3); | 212 Node* const context = a.Parameter(3); |
| 199 Node* const native_context = a.LoadNativeContext(context); | 213 Node* const instance = CreatePromise(&a, context); |
| 200 Node* const promise_fun = | |
| 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), | 214 PromiseInit(&a, instance, a.SmiConstant(kPromisePending), |
| 207 a.UndefinedConstant()); | 215 a.UndefinedConstant()); |
| 208 a.Return(instance); | 216 a.Return(instance); |
| 209 } | 217 } |
| 210 | 218 |
| 211 void Builtins::Generate_PromiseCreateAndSet( | 219 void Builtins::Generate_PromiseCreateAndSet( |
| 212 compiler::CodeAssemblerState* state) { | 220 compiler::CodeAssemblerState* state) { |
| 213 typedef compiler::Node Node; | 221 typedef compiler::Node Node; |
| 214 CodeStubAssembler a(state); | 222 CodeStubAssembler a(state); |
| 215 | 223 |
| 216 Node* const status = a.Parameter(1); | 224 Node* const status = a.Parameter(1); |
| 217 Node* const result = a.Parameter(2); | 225 Node* const result = a.Parameter(2); |
| 218 Node* const context = a.Parameter(5); | 226 Node* const context = a.Parameter(5); |
| 219 Node* const native_context = a.LoadNativeContext(context); | |
| 220 | 227 |
| 221 Node* const promise_fun = | 228 Node* const instance = CreatePromise(&a, context); |
| 222 a.LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | |
| 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); | 229 PromiseInit(&a, instance, status, result); |
| 228 a.Return(instance); | 230 a.Return(instance); |
| 229 } | 231 } |
| 230 | 232 |
| 231 namespace { | 233 namespace { |
| 232 | 234 |
| 233 compiler::Node* ThrowIfNotJSReceiver(CodeStubAssembler* a, Isolate* isolate, | 235 compiler::Node* ThrowIfNotJSReceiver(CodeStubAssembler* a, Isolate* isolate, |
| 234 compiler::Node* context, | 236 compiler::Node* context, |
| 235 compiler::Node* value, | 237 compiler::Node* value, |
| 236 MessageTemplate::Template msg_template) { | 238 MessageTemplate::Template msg_template) { |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 887 | 889 |
| 888 Label out(&a); | 890 Label out(&a); |
| 889 InternalResolvePromise(&a, context, promise, result, &out); | 891 InternalResolvePromise(&a, context, promise, result, &out); |
| 890 | 892 |
| 891 a.Bind(&out); | 893 a.Bind(&out); |
| 892 a.Return(a.UndefinedConstant()); | 894 a.Return(a.UndefinedConstant()); |
| 893 } | 895 } |
| 894 | 896 |
| 895 } // namespace internal | 897 } // namespace internal |
| 896 } // namespace v8 | 898 } // namespace v8 |
| OLD | NEW |