Chromium Code Reviews| Index: src/builtins/builtins-promise.cc |
| diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc |
| index aa38002218e744fd87a221fe753230a78487f337..e84e50c9771fe3978587737e6a2d3a1a6b257dba 100644 |
| --- a/src/builtins/builtins-promise.cc |
| +++ b/src/builtins/builtins-promise.cc |
| @@ -57,6 +57,23 @@ BUILTIN(CreateResolvingFunctions) { |
| NOT_TENURED); |
| } |
| +namespace { |
| + |
| +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
|
| + typedef compiler::Node Node; |
| + |
| + Node* const native_context = a->LoadNativeContext(context); |
| + Node* const promise_fun = |
| + a->LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
| + Node* const initial_map = |
| + a->LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
| + Node* const instance = a->AllocateJSObjectFromMap(initial_map); |
| + |
| + return instance; |
| +} |
| + |
| +} // namespace |
| + |
| void PromiseInit(CodeStubAssembler* a, compiler::Node* promise, |
| compiler::Node* status, compiler::Node* result) { |
| CSA_ASSERT(a, a->TaggedIsSmi(status)); |
| @@ -104,10 +121,7 @@ void Builtins::Generate_PromiseConstructor( |
| a.Bind(&if_targetisnotmodified); |
| { |
| - Node* const initial_map = a.LoadObjectField( |
| - promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
| - |
| - Node* const instance = a.AllocateJSObjectFromMap(initial_map); |
| + Node* const instance = CreatePromise(&a, context); |
| var_result.Bind(instance); |
| a.Goto(&init); |
| } |
| @@ -196,13 +210,7 @@ void Builtins::Generate_PromiseInternalConstructor( |
| CodeStubAssembler a(state); |
| Node* const context = a.Parameter(3); |
| - Node* const native_context = a.LoadNativeContext(context); |
| - Node* const promise_fun = |
| - a.LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
| - Node* const initial_map = |
| - a.LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
| - Node* const instance = a.AllocateJSObjectFromMap(initial_map); |
| - |
| + Node* const instance = CreatePromise(&a, context); |
| PromiseInit(&a, instance, a.SmiConstant(kPromisePending), |
| a.UndefinedConstant()); |
| a.Return(instance); |
| @@ -216,14 +224,8 @@ void Builtins::Generate_PromiseCreateAndSet( |
| Node* const status = a.Parameter(1); |
| Node* const result = a.Parameter(2); |
| Node* const context = a.Parameter(5); |
| - Node* const native_context = a.LoadNativeContext(context); |
| - |
| - Node* const promise_fun = |
| - a.LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
| - Node* const initial_map = |
| - a.LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
| - Node* const instance = a.AllocateJSObjectFromMap(initial_map); |
| + Node* const instance = CreatePromise(&a, context); |
| PromiseInit(&a, instance, status, result); |
| a.Return(instance); |
| } |