Commit d3229dee authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[esnext] Clean up Promise.prototype.finally implementation

Split the PromiseFinallyContextSlot enum into two separate enums
because the spec requires additional slot to store the Promise
constructor in the Promise.prototype.finally builtin. This will be
added in a follow on patch.

Inline the various context creation functions into their callsites since
they're only a single line and have only one callsite.

Bug: v8:5967
Change-Id: I2834c9c3d4940b8fbbdb7c162f42323d0fe0939f
Reviewed-on: https://chromium-review.googlesource.com/624543
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47525}
parent 35e4bcb6
......@@ -1552,18 +1552,12 @@ TF_BUILTIN(InternalPromiseReject, PromiseBuiltinsAssembler) {
Return(UndefinedConstant());
}
Node* PromiseBuiltinsAssembler::CreatePromiseFinallyContext(
Node* on_finally, Node* native_context) {
Node* const context =
CreatePromiseContext(native_context, kOnFinallyContextLength);
StoreContextElementNoWriteBarrier(context, kOnFinallySlot, on_finally);
return context;
}
std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions(
Node* on_finally, Node* native_context) {
Node* const promise_context =
CreatePromiseFinallyContext(on_finally, native_context);
CreatePromiseContext(native_context, kPromiseFinallyContextLength);
StoreContextElementNoWriteBarrier(promise_context, kOnFinallySlot,
on_finally);
Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const then_finally_info = LoadContextElement(
......@@ -1580,22 +1574,15 @@ std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions(
TF_BUILTIN(PromiseValueThunkFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext);
Node* const value = LoadContextElement(context, kOnFinallySlot);
Node* const value = LoadContextElement(context, kValueSlot);
Return(value);
}
Node* PromiseBuiltinsAssembler::CreateValueThunkFunctionContext(
Node* value, Node* native_context) {
Node* const context =
CreatePromiseContext(native_context, kOnFinallyContextLength);
StoreContextElementNoWriteBarrier(context, kOnFinallySlot, value);
return context;
}
Node* PromiseBuiltinsAssembler::CreateValueThunkFunction(Node* value,
Node* native_context) {
Node* const value_thunk_context =
CreateValueThunkFunctionContext(value, native_context);
Node* const value_thunk_context = CreatePromiseContext(
native_context, kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(value_thunk_context, kValueSlot, value);
Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const value_thunk_info = LoadContextElement(
......@@ -1640,23 +1627,16 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) {
TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext);
Node* const reason = LoadContextElement(context, kOnFinallySlot);
Node* const reason = LoadContextElement(context, kValueSlot);
CallRuntime(Runtime::kThrow, context, reason);
Unreachable();
}
Node* PromiseBuiltinsAssembler::CreateThrowerFunctionContext(
Node* reason, Node* native_context) {
Node* const context =
CreatePromiseContext(native_context, kOnFinallyContextLength);
StoreContextElementNoWriteBarrier(context, kOnFinallySlot, reason);
return context;
}
Node* PromiseBuiltinsAssembler::CreateThrowerFunction(Node* reason,
Node* native_context) {
Node* const thrower_context =
CreateThrowerFunctionContext(reason, native_context);
Node* const thrower_context = CreatePromiseContext(
native_context, kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(thrower_context, kValueSlot, reason);
Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const thrower_info = LoadContextElement(
......
......@@ -55,16 +55,23 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler {
kCapabilitiesContextLength,
};
// This is used by the PromiseThenFinally and PromiseCatchFinally
// builtins to store the onFinally in the onFinallySlot.
//
// This is also used by the PromiseValueThunkFinally to store the
// value in the onFinallySlot and PromiseThrowerFinally to store the
// reason in the onFinallySlot.
// This is used by the Promise.prototype.finally builtin to store
// onFinally callback and the Promise constructor.
// TODO(gsathya): Add extra slot for Promise constructor.
// TODO(gsathya): For native promises we can create a variant of
// this without extra space for the constructor to save memory.
enum PromiseFinallyContextSlot {
kOnFinallySlot = Context::MIN_CONTEXT_SLOTS,
kOnFinallyContextLength,
kPromiseFinallyContextLength,
};
// This is used by the ThenFinally and CatchFinally builtins to
// store the value to return or reason to throw.
enum PromiseValueThunkOrReasonContextSlot {
kValueSlot = Context::MIN_CONTEXT_SLOTS,
kPromiseValueThunkOrReasonContextLength,
};
explicit PromiseBuiltinsAssembler(compiler::CodeAssemblerState* state)
......@@ -149,12 +156,8 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler {
Node* debug_event);
std::pair<Node*, Node*> CreatePromiseFinallyFunctions(Node* on_finally,
Node* native_context);
Node* CreatePromiseFinallyContext(Node* on_finally, Node* native_context);
Node* CreateValueThunkFunction(Node* value, Node* native_context);
Node* CreateValueThunkFunctionContext(Node* value, Node* native_context);
Node* CreateThrowerFunctionContext(Node* reason, Node* native_context);
Node* CreateThrowerFunction(Node* reason, Node* native_context);
Node* PerformPromiseAll(Node* context, Node* constructor, Node* capability,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment