Chromium Code Reviews| Index: src/code-stub-assembler.cc |
| diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc |
| index e67f81f8e1ad28afb5ac25e2ac682167e964a484..4053c42b73f35e9e3ee68e2b51c35cea8c758825 100644 |
| --- a/src/code-stub-assembler.cc |
| +++ b/src/code-stub-assembler.cc |
| @@ -5,6 +5,7 @@ |
| #include "src/code-factory.h" |
| #include "src/frames-inl.h" |
| #include "src/frames.h" |
| +#include "src/promise-utils.h" |
| namespace v8 { |
| namespace internal { |
| @@ -8222,6 +8223,76 @@ Node* CodeStubAssembler::IsPromiseHookEnabled() { |
| return WordNotEqual(is_promisehook_enabled, Int32Constant(0)); |
| } |
| +Node* CodeStubAssembler::AllocateFunctionWithMapAndContext(Node* map, |
| + Node* shared_info, |
| + Node* context) { |
| + Node* const code = |
| + LoadObjectField(shared_info, SharedFunctionInfo::kCodeOffset); |
| + Node* const code_entry = |
| + IntPtrAdd(code, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag)); |
| + |
| + Node* const fun = Allocate(JSFunction::kSize); |
| + StoreMapNoWriteBarrier(fun, map); |
| + StoreObjectFieldRoot(fun, JSObject::kPropertiesOffset, |
| + Heap::kEmptyFixedArrayRootIndex); |
| + StoreObjectFieldRoot(fun, JSObject::kElementsOffset, |
| + Heap::kEmptyFixedArrayRootIndex); |
| + StoreObjectFieldRoot(fun, JSFunction::kLiteralsOffset, |
| + Heap::kEmptyLiteralsArrayRootIndex); |
| + StoreObjectFieldRoot(fun, JSFunction::kPrototypeOrInitialMapOffset, |
| + Heap::kTheHoleValueRootIndex); |
| + StoreObjectFieldNoWriteBarrier(fun, JSFunction::kSharedFunctionInfoOffset, |
| + shared_info); |
| + StoreObjectFieldNoWriteBarrier(fun, JSFunction::kContextOffset, context); |
| + StoreObjectFieldNoWriteBarrier(fun, JSFunction::kCodeEntryOffset, code_entry); |
| + StoreObjectFieldRoot(fun, JSFunction::kNextFunctionLinkOffset, |
| + Heap::kUndefinedValueRootIndex); |
| + |
| + return fun; |
| +} |
| + |
| +Node* CodeStubAssembler::CreatePromiseResolvingFunctionsContext( |
| + Node* promise, Node* debug_event, Node* native_context) { |
| + Node* const context = |
| + Allocate(FixedArray::SizeFor(PromiseUtils::kPromiseContextLength)); |
| + Node* const map = HeapConstant(isolate()->factory()->function_context_map()); |
| + StoreMapNoWriteBarrier(context, map); |
|
Igor Sheludko
2016/12/13 23:42:34
StoreMapNoWriteBarrier(context, Heap::kFunctionCon
gsathya
2016/12/19 20:12:43
Done.
|
| + StoreObjectFieldNoWriteBarrier( |
| + context, FixedArray::kLengthOffset, |
| + SmiConstant(PromiseUtils::kPromiseContextLength)); |
| + |
| + Node* const empty_fn = |
| + LoadContextElement(native_context, Context::CLOSURE_INDEX); |
| + StoreContextElement(context, Context::CLOSURE_INDEX, empty_fn); |
|
Igor Sheludko
2016/12/13 23:42:34
We can skip write barriers here and below since th
gsathya
2016/12/19 20:12:43
Done.
|
| + StoreContextElement(context, Context::PREVIOUS_INDEX, UndefinedConstant()); |
| + StoreContextElement(context, Context::EXTENSION_INDEX, TheHoleConstant()); |
| + StoreContextElement(context, Context::NATIVE_CONTEXT_INDEX, native_context); |
| + StoreContextElement(context, PromiseUtils::kAlreadyVisitedSlot, |
| + SmiConstant(0)); |
| + StoreContextElement(context, PromiseUtils::kPromiseSlot, promise); |
| + StoreContextElement(context, PromiseUtils::kDebugEventSlot, debug_event); |
| + return context; |
| +} |
| + |
| +std::pair<Node*, Node*> CodeStubAssembler::CreatePromiseResolvingFunctions( |
| + Node* promise, Node* debug_event, Node* native_context) { |
| + Node* const promise_context = CreatePromiseResolvingFunctionsContext( |
| + promise, debug_event, native_context); |
| + Node* const resolve_info = |
| + LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN); |
|
Igor Sheludko
2016/12/13 23:42:34
Please move the load before the call to respective
gsathya
2016/12/19 20:12:43
Done.
|
| + Node* const reject_info = |
| + LoadContextElement(native_context, Context::PROMISE_REJECT_SHARED_FUN); |
|
Igor Sheludko
2016/12/13 23:42:35
Same here.
gsathya
2016/12/19 20:12:43
Done.
|
| + |
| + Node* const map = LoadContextElement( |
| + native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); |
| + Node* const resolve = |
| + AllocateFunctionWithMapAndContext(map, resolve_info, promise_context); |
| + Node* const reject = |
| + AllocateFunctionWithMapAndContext(map, reject_info, promise_context); |
| + |
| + return std::make_pair(resolve, reject); |
| +} |
| + |
| Node* CodeStubAssembler::AllocateJSPromise(Node* context) { |
| Node* const native_context = LoadNativeContext(context); |
| Node* const promise_fun = |