Commit 014eb820 authored by Alexander Timokhin's avatar Alexander Timokhin Committed by Commit Bot

Reland "Don't use |v8_initializers| code in |v8_base|"

This is a reland of 2e36e9ea

Was reverted because of v8_presubmit.py issue in
https://chromium-review.googlesource.com/c/v8/v8/+/1374292

Original change's description:
> Don't use |v8_initializers| code in |v8_base|
>
> Removing |CodeStubAssembler| from |v8_base| source list (see
> https://chromium-review.googlesource.com/c/v8/v8/+/1346329) leads to
> linkage problems with some build configurations because it was explicitly
> and implicitly included in |v8_base| code.
>
> This CL decouple this code and fixes problems.
>
> Bug: v8:7777
> Change-Id: I58de5c62914bc77645ed6cc9114409890bc13189
> Reviewed-on: https://chromium-review.googlesource.com/c/1372067
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
> Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> Commit-Queue: Jakob Gruber <jgruber@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#58200}

Bug: v8:7777
Change-Id: Iaa00e73c7dbd8c413fbf15a17709aa12eda9a706
Reviewed-on: https://chromium-review.googlesource.com/c/1375654Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58209}
parent c4fdb272
...@@ -1707,6 +1707,7 @@ v8_source_set("v8_base") { ...@@ -1707,6 +1707,7 @@ v8_source_set("v8_base") {
"src/builtins/builtins-number.cc", "src/builtins/builtins-number.cc",
"src/builtins/builtins-object.cc", "src/builtins/builtins-object.cc",
"src/builtins/builtins-promise.cc", "src/builtins/builtins-promise.cc",
"src/builtins/builtins-promise.h",
"src/builtins/builtins-reflect.cc", "src/builtins/builtins-reflect.cc",
"src/builtins/builtins-regexp.cc", "src/builtins/builtins-regexp.cc",
"src/builtins/builtins-sharedarraybuffer.cc", "src/builtins/builtins-sharedarraybuffer.cc",
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "src/builtins/builtins-utils-inl.h" #include "src/builtins/builtins-utils-inl.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/conversions.h" #include "src/conversions.h"
#include "src/counters.h" #include "src/counters.h"
#include "src/date.h" #include "src/date.h"
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "src/builtins/builtins-utils-inl.h" #include "src/builtins/builtins-utils-inl.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/counters.h" #include "src/counters.h"
#include "src/keys.h" #include "src/keys.h"
#include "src/lookup.h" #include "src/lookup.h"
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/builtins/builtins-constructor-gen.h" #include "src/builtins/builtins-constructor-gen.h"
#include "src/builtins/builtins-iterator-gen.h" #include "src/builtins/builtins-iterator-gen.h"
#include "src/builtins/builtins-promise.h"
#include "src/builtins/builtins-utils-gen.h" #include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/code-factory.h" #include "src/code-factory.h"
...@@ -210,14 +211,17 @@ Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementContext( ...@@ -210,14 +211,17 @@ Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementContext(
TNode<JSArray> values_array = AllocateJSArray( TNode<JSArray> values_array = AllocateJSArray(
PACKED_ELEMENTS, array_map, IntPtrConstant(0), SmiConstant(0)); PACKED_ELEMENTS, array_map, IntPtrConstant(0), SmiConstant(0));
Node* const context = Node* const context = CreatePromiseContext(
CreatePromiseContext(native_context, kPromiseAllResolveElementLength); native_context, PromiseBuiltins::kPromiseAllResolveElementLength);
StoreContextElementNoWriteBarrier( StoreContextElementNoWriteBarrier(
context, kPromiseAllResolveElementRemainingSlot, SmiConstant(1)); context, PromiseBuiltins::kPromiseAllResolveElementRemainingSlot,
SmiConstant(1));
StoreContextElementNoWriteBarrier( StoreContextElementNoWriteBarrier(
context, kPromiseAllResolveElementCapabilitySlot, promise_capability); context, PromiseBuiltins::kPromiseAllResolveElementCapabilitySlot,
promise_capability);
StoreContextElementNoWriteBarrier( StoreContextElementNoWriteBarrier(
context, kPromiseAllResolveElementValuesArraySlot, values_array); context, PromiseBuiltins::kPromiseAllResolveElementValuesArraySlot,
values_array);
return context; return context;
} }
...@@ -245,20 +249,22 @@ Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementFunction( ...@@ -245,20 +249,22 @@ Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementFunction(
Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext( Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext(
Node* promise, Node* debug_event, Node* native_context) { Node* promise, Node* debug_event, Node* native_context) {
Node* const context = Node* const context = CreatePromiseContext(
CreatePromiseContext(native_context, kPromiseContextLength); native_context, PromiseBuiltins::kPromiseContextLength);
StoreContextElementNoWriteBarrier(context, kPromiseSlot, promise); StoreContextElementNoWriteBarrier(context, PromiseBuiltins::kPromiseSlot,
StoreContextElementNoWriteBarrier(context, kAlreadyResolvedSlot, promise);
FalseConstant()); StoreContextElementNoWriteBarrier(
StoreContextElementNoWriteBarrier(context, kDebugEventSlot, debug_event); context, PromiseBuiltins::kAlreadyResolvedSlot, FalseConstant());
StoreContextElementNoWriteBarrier(context, PromiseBuiltins::kDebugEventSlot,
debug_event);
return context; return context;
} }
Node* PromiseBuiltinsAssembler::CreatePromiseGetCapabilitiesExecutorContext( Node* PromiseBuiltinsAssembler::CreatePromiseGetCapabilitiesExecutorContext(
Node* promise_capability, Node* native_context) { Node* promise_capability, Node* native_context) {
int kContextLength = kCapabilitiesContextLength; int kContextLength = PromiseBuiltins::kCapabilitiesContextLength;
Node* context = CreatePromiseContext(native_context, kContextLength); Node* context = CreatePromiseContext(native_context, kContextLength);
StoreContextElementNoWriteBarrier(context, kCapabilitySlot, StoreContextElementNoWriteBarrier(context, PromiseBuiltins::kCapabilitySlot,
promise_capability); promise_capability);
return context; return context;
} }
...@@ -756,22 +762,24 @@ TF_BUILTIN(PromiseCapabilityDefaultReject, PromiseBuiltinsAssembler) { ...@@ -756,22 +762,24 @@ TF_BUILTIN(PromiseCapabilityDefaultReject, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
// 2. Let promise be F.[[Promise]]. // 2. Let promise be F.[[Promise]].
Node* const promise = LoadContextElement(context, kPromiseSlot); Node* const promise =
LoadContextElement(context, PromiseBuiltins::kPromiseSlot);
// 3. Let alreadyResolved be F.[[AlreadyResolved]]. // 3. Let alreadyResolved be F.[[AlreadyResolved]].
Label if_already_resolved(this, Label::kDeferred); Label if_already_resolved(this, Label::kDeferred);
Node* const already_resolved = Node* const already_resolved =
LoadContextElement(context, kAlreadyResolvedSlot); LoadContextElement(context, PromiseBuiltins::kAlreadyResolvedSlot);
// 4. If alreadyResolved.[[Value]] is true, return undefined. // 4. If alreadyResolved.[[Value]] is true, return undefined.
GotoIf(IsTrue(already_resolved), &if_already_resolved); GotoIf(IsTrue(already_resolved), &if_already_resolved);
// 5. Set alreadyResolved.[[Value]] to true. // 5. Set alreadyResolved.[[Value]] to true.
StoreContextElementNoWriteBarrier(context, kAlreadyResolvedSlot, StoreContextElementNoWriteBarrier(
TrueConstant()); context, PromiseBuiltins::kAlreadyResolvedSlot, TrueConstant());
// 6. Return RejectPromise(promise, reason). // 6. Return RejectPromise(promise, reason).
Node* const debug_event = LoadContextElement(context, kDebugEventSlot); Node* const debug_event =
LoadContextElement(context, PromiseBuiltins::kDebugEventSlot);
Return(CallBuiltin(Builtins::kRejectPromise, context, promise, reason, Return(CallBuiltin(Builtins::kRejectPromise, context, promise, reason,
debug_event)); debug_event));
...@@ -788,19 +796,20 @@ TF_BUILTIN(PromiseCapabilityDefaultResolve, PromiseBuiltinsAssembler) { ...@@ -788,19 +796,20 @@ TF_BUILTIN(PromiseCapabilityDefaultResolve, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
// 2. Let promise be F.[[Promise]]. // 2. Let promise be F.[[Promise]].
Node* const promise = LoadContextElement(context, kPromiseSlot); Node* const promise =
LoadContextElement(context, PromiseBuiltins::kPromiseSlot);
// 3. Let alreadyResolved be F.[[AlreadyResolved]]. // 3. Let alreadyResolved be F.[[AlreadyResolved]].
Label if_already_resolved(this, Label::kDeferred); Label if_already_resolved(this, Label::kDeferred);
Node* const already_resolved = Node* const already_resolved =
LoadContextElement(context, kAlreadyResolvedSlot); LoadContextElement(context, PromiseBuiltins::kAlreadyResolvedSlot);
// 4. If alreadyResolved.[[Value]] is true, return undefined. // 4. If alreadyResolved.[[Value]] is true, return undefined.
GotoIf(IsTrue(already_resolved), &if_already_resolved); GotoIf(IsTrue(already_resolved), &if_already_resolved);
// 5. Set alreadyResolved.[[Value]] to true. // 5. Set alreadyResolved.[[Value]] to true.
StoreContextElementNoWriteBarrier(context, kAlreadyResolvedSlot, StoreContextElementNoWriteBarrier(
TrueConstant()); context, PromiseBuiltins::kAlreadyResolvedSlot, TrueConstant());
// The rest of the logic (and the catch prediction) is // The rest of the logic (and the catch prediction) is
// encapsulated in the dedicated ResolvePromise builtin. // encapsulated in the dedicated ResolvePromise builtin.
...@@ -1402,7 +1411,8 @@ TF_BUILTIN(PromiseGetCapabilitiesExecutor, PromiseBuiltinsAssembler) { ...@@ -1402,7 +1411,8 @@ TF_BUILTIN(PromiseGetCapabilitiesExecutor, PromiseBuiltinsAssembler) {
Node* const reject = Parameter(Descriptor::kReject); Node* const reject = Parameter(Descriptor::kReject);
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
Node* const capability = LoadContextElement(context, kCapabilitySlot); Node* const capability =
LoadContextElement(context, PromiseBuiltins::kCapabilitySlot);
Label if_alreadyinvoked(this, Label::kDeferred); Label if_alreadyinvoked(this, Label::kDeferred);
GotoIfNot(IsUndefined( GotoIfNot(IsUndefined(
...@@ -1470,12 +1480,12 @@ TF_BUILTIN(PromiseReject, PromiseBuiltinsAssembler) { ...@@ -1470,12 +1480,12 @@ TF_BUILTIN(PromiseReject, PromiseBuiltinsAssembler) {
std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions( std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions(
Node* on_finally, Node* constructor, Node* native_context) { Node* on_finally, Node* constructor, Node* native_context) {
Node* const promise_context = Node* const promise_context = CreatePromiseContext(
CreatePromiseContext(native_context, kPromiseFinallyContextLength); native_context, PromiseBuiltins::kPromiseFinallyContextLength);
StoreContextElementNoWriteBarrier(promise_context, kOnFinallySlot, StoreContextElementNoWriteBarrier(
on_finally); promise_context, PromiseBuiltins::kOnFinallySlot, on_finally);
StoreContextElementNoWriteBarrier(promise_context, kConstructorSlot, StoreContextElementNoWriteBarrier(
constructor); promise_context, PromiseBuiltins::kConstructorSlot, constructor);
Node* const map = LoadContextElement( Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const then_finally_info = LoadContextElement( Node* const then_finally_info = LoadContextElement(
...@@ -1492,15 +1502,16 @@ std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions( ...@@ -1492,15 +1502,16 @@ std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions(
TF_BUILTIN(PromiseValueThunkFinally, PromiseBuiltinsAssembler) { TF_BUILTIN(PromiseValueThunkFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
Node* const value = LoadContextElement(context, kValueSlot); Node* const value = LoadContextElement(context, PromiseBuiltins::kValueSlot);
Return(value); Return(value);
} }
Node* PromiseBuiltinsAssembler::CreateValueThunkFunction(Node* value, Node* PromiseBuiltinsAssembler::CreateValueThunkFunction(Node* value,
Node* native_context) { Node* native_context) {
Node* const value_thunk_context = CreatePromiseContext( Node* const value_thunk_context = CreatePromiseContext(
native_context, kPromiseValueThunkOrReasonContextLength); native_context, PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(value_thunk_context, kValueSlot, value); StoreContextElementNoWriteBarrier(value_thunk_context,
PromiseBuiltins::kValueSlot, value);
Node* const map = LoadContextElement( Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const value_thunk_info = LoadContextElement( Node* const value_thunk_info = LoadContextElement(
...@@ -1517,7 +1528,8 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) { ...@@ -1517,7 +1528,8 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
// 1. Let onFinally be F.[[OnFinally]]. // 1. Let onFinally be F.[[OnFinally]].
Node* const on_finally = LoadContextElement(context, kOnFinallySlot); Node* const on_finally =
LoadContextElement(context, PromiseBuiltins::kOnFinallySlot);
// 2. Assert: IsCallable(onFinally) is true. // 2. Assert: IsCallable(onFinally) is true.
CSA_ASSERT(this, IsCallable(on_finally)); CSA_ASSERT(this, IsCallable(on_finally));
...@@ -1528,7 +1540,8 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) { ...@@ -1528,7 +1540,8 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) {
context, on_finally, UndefinedConstant()); context, on_finally, UndefinedConstant());
// 4. Let C be F.[[Constructor]]. // 4. Let C be F.[[Constructor]].
Node* const constructor = LoadContextElement(context, kConstructorSlot); Node* const constructor =
LoadContextElement(context, PromiseBuiltins::kConstructorSlot);
// 5. Assert: IsConstructor(C) is true. // 5. Assert: IsConstructor(C) is true.
CSA_ASSERT(this, IsConstructor(constructor)); CSA_ASSERT(this, IsConstructor(constructor));
...@@ -1548,7 +1561,7 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) { ...@@ -1548,7 +1561,7 @@ TF_BUILTIN(PromiseThenFinally, PromiseBuiltinsAssembler) {
TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) { TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
Node* const reason = LoadContextElement(context, kValueSlot); Node* const reason = LoadContextElement(context, PromiseBuiltins::kValueSlot);
CallRuntime(Runtime::kThrow, context, reason); CallRuntime(Runtime::kThrow, context, reason);
Unreachable(); Unreachable();
} }
...@@ -1556,8 +1569,9 @@ TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) { ...@@ -1556,8 +1569,9 @@ TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) {
Node* PromiseBuiltinsAssembler::CreateThrowerFunction(Node* reason, Node* PromiseBuiltinsAssembler::CreateThrowerFunction(Node* reason,
Node* native_context) { Node* native_context) {
Node* const thrower_context = CreatePromiseContext( Node* const thrower_context = CreatePromiseContext(
native_context, kPromiseValueThunkOrReasonContextLength); native_context, PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(thrower_context, kValueSlot, reason); StoreContextElementNoWriteBarrier(thrower_context,
PromiseBuiltins::kValueSlot, reason);
Node* const map = LoadContextElement( Node* const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const thrower_info = LoadContextElement( Node* const thrower_info = LoadContextElement(
...@@ -1574,7 +1588,8 @@ TF_BUILTIN(PromiseCatchFinally, PromiseBuiltinsAssembler) { ...@@ -1574,7 +1588,8 @@ TF_BUILTIN(PromiseCatchFinally, PromiseBuiltinsAssembler) {
Node* const context = Parameter(Descriptor::kContext); Node* const context = Parameter(Descriptor::kContext);
// 1. Let onFinally be F.[[OnFinally]]. // 1. Let onFinally be F.[[OnFinally]].
Node* const on_finally = LoadContextElement(context, kOnFinallySlot); Node* const on_finally =
LoadContextElement(context, PromiseBuiltins::kOnFinallySlot);
// 2. Assert: IsCallable(onFinally) is true. // 2. Assert: IsCallable(onFinally) is true.
CSA_ASSERT(this, IsCallable(on_finally)); CSA_ASSERT(this, IsCallable(on_finally));
...@@ -1585,7 +1600,8 @@ TF_BUILTIN(PromiseCatchFinally, PromiseBuiltinsAssembler) { ...@@ -1585,7 +1600,8 @@ TF_BUILTIN(PromiseCatchFinally, PromiseBuiltinsAssembler) {
context, on_finally, UndefinedConstant()); context, on_finally, UndefinedConstant());
// 4. Let C be F.[[Constructor]]. // 4. Let C be F.[[Constructor]].
Node* const constructor = LoadContextElement(context, kConstructorSlot); Node* const constructor =
LoadContextElement(context, PromiseBuiltins::kConstructorSlot);
// 5. Assert: IsConstructor(C) is true. // 5. Assert: IsConstructor(C) is true.
CSA_ASSERT(this, IsConstructor(constructor)); CSA_ASSERT(this, IsConstructor(constructor));
...@@ -1914,9 +1930,11 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll( ...@@ -1914,9 +1930,11 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll(
// Set remainingElementsCount.[[Value]] to // Set remainingElementsCount.[[Value]] to
// remainingElementsCount.[[Value]] + 1. // remainingElementsCount.[[Value]] + 1.
TNode<Smi> const remaining_elements_count = CAST(LoadContextElement( TNode<Smi> const remaining_elements_count = CAST(LoadContextElement(
resolve_element_context, kPromiseAllResolveElementRemainingSlot)); resolve_element_context,
PromiseBuiltins::kPromiseAllResolveElementRemainingSlot));
StoreContextElementNoWriteBarrier( StoreContextElementNoWriteBarrier(
resolve_element_context, kPromiseAllResolveElementRemainingSlot, resolve_element_context,
PromiseBuiltins::kPromiseAllResolveElementRemainingSlot,
SmiAdd(remaining_elements_count, SmiConstant(1))); SmiAdd(remaining_elements_count, SmiConstant(1)));
// Let resolveElement be CreateBuiltinFunction(steps, // Let resolveElement be CreateBuiltinFunction(steps,
...@@ -2033,11 +2051,13 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll( ...@@ -2033,11 +2051,13 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll(
// Set remainingElementsCount.[[Value]] to // Set remainingElementsCount.[[Value]] to
// remainingElementsCount.[[Value]] - 1. // remainingElementsCount.[[Value]] - 1.
TNode<Smi> remaining_elements_count = CAST(LoadContextElement( TNode<Smi> remaining_elements_count = CAST(LoadContextElement(
resolve_element_context, kPromiseAllResolveElementRemainingSlot)); resolve_element_context,
PromiseBuiltins::kPromiseAllResolveElementRemainingSlot));
remaining_elements_count = SmiSub(remaining_elements_count, SmiConstant(1)); remaining_elements_count = SmiSub(remaining_elements_count, SmiConstant(1));
StoreContextElementNoWriteBarrier(resolve_element_context, StoreContextElementNoWriteBarrier(
kPromiseAllResolveElementRemainingSlot, resolve_element_context,
remaining_elements_count); PromiseBuiltins::kPromiseAllResolveElementRemainingSlot,
remaining_elements_count);
GotoIf(SmiEqual(remaining_elements_count, SmiConstant(0)), GotoIf(SmiEqual(remaining_elements_count, SmiConstant(0)),
&resolve_promise); &resolve_promise);
...@@ -2046,7 +2066,8 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll( ...@@ -2046,7 +2066,8 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll(
// fancy Thenable that calls the resolve callback immediately, so we need // fancy Thenable that calls the resolve callback immediately, so we need
// to handle that correctly here. // to handle that correctly here.
Node* const values_array = LoadContextElement( Node* const values_array = LoadContextElement(
resolve_element_context, kPromiseAllResolveElementValuesArraySlot); resolve_element_context,
PromiseBuiltins::kPromiseAllResolveElementValuesArraySlot);
Node* const old_elements = LoadElements(values_array); Node* const old_elements = LoadElements(values_array);
TNode<Smi> const old_capacity = LoadFixedArrayBaseLength(old_elements); TNode<Smi> const old_capacity = LoadFixedArrayBaseLength(old_elements);
TNode<Smi> const new_capacity = var_index.value(); TNode<Smi> const new_capacity = var_index.value();
...@@ -2069,7 +2090,8 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll( ...@@ -2069,7 +2090,8 @@ Node* PromiseBuiltinsAssembler::PerformPromiseAll(
Node* const resolve = Node* const resolve =
LoadObjectField(capability, PromiseCapability::kResolveOffset); LoadObjectField(capability, PromiseCapability::kResolveOffset);
Node* const values_array = LoadContextElement( Node* const values_array = LoadContextElement(
resolve_element_context, kPromiseAllResolveElementValuesArraySlot); resolve_element_context,
PromiseBuiltins::kPromiseAllResolveElementValuesArraySlot);
Node* const resolve_call = CallJS( Node* const resolve_call = CallJS(
CodeFactory::Call(isolate(), ConvertReceiverMode::kNullOrUndefined), CodeFactory::Call(isolate(), ConvertReceiverMode::kNullOrUndefined),
native_context, resolve, UndefinedConstant(), values_array); native_context, resolve, UndefinedConstant(), values_array);
...@@ -2152,9 +2174,10 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) { ...@@ -2152,9 +2174,10 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) {
// first time, in which case we make it point to the native context here // first time, in which case we make it point to the native context here
// to mark this resolve element closure as done. // to mark this resolve element closure as done.
GotoIf(IsNativeContext(context), &already_called); GotoIf(IsNativeContext(context), &already_called);
CSA_ASSERT(this, CSA_ASSERT(
SmiEqual(LoadObjectField<Smi>(context, Context::kLengthOffset), this,
SmiConstant(kPromiseAllResolveElementLength))); SmiEqual(LoadObjectField<Smi>(context, Context::kLengthOffset),
SmiConstant(PromiseBuiltins::kPromiseAllResolveElementLength)));
TNode<Context> native_context = LoadNativeContext(context); TNode<Context> native_context = LoadNativeContext(context);
StoreObjectField(function, JSFunction::kContextOffset, native_context); StoreObjectField(function, JSFunction::kContextOffset, native_context);
...@@ -2167,8 +2190,8 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) { ...@@ -2167,8 +2190,8 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) {
TNode<IntPtrT> index = IntPtrSub(identity_hash, IntPtrConstant(1)); TNode<IntPtrT> index = IntPtrSub(identity_hash, IntPtrConstant(1));
// Check if we need to grow the [[ValuesArray]] to store {value} at {index}. // Check if we need to grow the [[ValuesArray]] to store {value} at {index}.
TNode<JSArray> values_array = CAST( TNode<JSArray> values_array = CAST(LoadContextElement(
LoadContextElement(context, kPromiseAllResolveElementValuesArraySlot)); context, PromiseBuiltins::kPromiseAllResolveElementValuesArraySlot));
TNode<FixedArray> elements = CAST(LoadElements(values_array)); TNode<FixedArray> elements = CAST(LoadElements(values_array));
TNode<IntPtrT> values_length = TNode<IntPtrT> values_length =
LoadAndUntagObjectField(values_array, JSArray::kLengthOffset); LoadAndUntagObjectField(values_array, JSArray::kLengthOffset);
...@@ -2227,17 +2250,18 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) { ...@@ -2227,17 +2250,18 @@ TF_BUILTIN(PromiseAllResolveElementClosure, PromiseBuiltinsAssembler) {
} }
BIND(&done); BIND(&done);
TNode<Smi> remaining_elements_count = TNode<Smi> remaining_elements_count = CAST(LoadContextElement(
CAST(LoadContextElement(context, kPromiseAllResolveElementRemainingSlot)); context, PromiseBuiltins::kPromiseAllResolveElementRemainingSlot));
remaining_elements_count = SmiSub(remaining_elements_count, SmiConstant(1)); remaining_elements_count = SmiSub(remaining_elements_count, SmiConstant(1));
StoreContextElement(context, kPromiseAllResolveElementRemainingSlot, StoreContextElement(context,
PromiseBuiltins::kPromiseAllResolveElementRemainingSlot,
remaining_elements_count); remaining_elements_count);
GotoIf(SmiEqual(remaining_elements_count, SmiConstant(0)), &resolve_promise); GotoIf(SmiEqual(remaining_elements_count, SmiConstant(0)), &resolve_promise);
Return(UndefinedConstant()); Return(UndefinedConstant());
BIND(&resolve_promise); BIND(&resolve_promise);
TNode<PromiseCapability> capability = CAST( TNode<PromiseCapability> capability = CAST(LoadContextElement(
LoadContextElement(context, kPromiseAllResolveElementCapabilitySlot)); context, PromiseBuiltins::kPromiseAllResolveElementCapabilitySlot));
TNode<Object> resolve = TNode<Object> resolve =
LoadObjectField(capability, PromiseCapability::kResolveOffset); LoadObjectField(capability, PromiseCapability::kResolveOffset);
CallJS(CodeFactory::Call(isolate(), ConvertReceiverMode::kNullOrUndefined), CallJS(CodeFactory::Call(isolate(), ConvertReceiverMode::kNullOrUndefined),
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define V8_BUILTINS_BUILTINS_PROMISE_GEN_H_ #define V8_BUILTINS_BUILTINS_PROMISE_GEN_H_
#include "src/code-stub-assembler.h" #include "src/code-stub-assembler.h"
#include "src/contexts.h"
#include "src/objects/promise.h" #include "src/objects/promise.h"
#include "torque-generated/builtins-base-from-dsl-gen.h" #include "torque-generated/builtins-base-from-dsl-gen.h"
#include "torque-generated/builtins-iterator-from-dsl-gen.h" #include "torque-generated/builtins-iterator-from-dsl-gen.h"
...@@ -18,59 +17,6 @@ typedef compiler::CodeAssemblerState CodeAssemblerState; ...@@ -18,59 +17,6 @@ typedef compiler::CodeAssemblerState CodeAssemblerState;
class PromiseBuiltinsAssembler : public CodeStubAssembler { class PromiseBuiltinsAssembler : public CodeStubAssembler {
public: public:
enum PromiseResolvingFunctionContextSlot {
// The promise which resolve/reject callbacks fulfill.
kPromiseSlot = Context::MIN_CONTEXT_SLOTS,
// Whether the callback was already invoked.
kAlreadyResolvedSlot,
// Whether to trigger a debug event or not. Used in catch
// prediction.
kDebugEventSlot,
kPromiseContextLength,
};
// TODO(bmeurer): Move this to a proper context map in contexts.h?
// Similar to the AwaitContext that we introduced for await closures.
enum PromiseAllResolveElementContextSlots {
// Remaining elements count
kPromiseAllResolveElementRemainingSlot = Context::MIN_CONTEXT_SLOTS,
// Promise capability from Promise.all
kPromiseAllResolveElementCapabilitySlot,
// Values array from Promise.all
kPromiseAllResolveElementValuesArraySlot,
kPromiseAllResolveElementLength
};
enum FunctionContextSlot {
kCapabilitySlot = Context::MIN_CONTEXT_SLOTS,
kCapabilitiesContextLength,
};
// This is used by the Promise.prototype.finally builtin to store
// onFinally callback and the 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,
kConstructorSlot,
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) explicit PromiseBuiltinsAssembler(compiler::CodeAssemblerState* state)
: CodeStubAssembler(state) {} : CodeStubAssembler(state) {}
// These allocate and initialize a promise with pending state and // These allocate and initialize a promise with pending state and
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/builtins/builtins-promise.h"
#include "src/builtins/builtins-utils-inl.h" #include "src/builtins/builtins-utils-inl.h"
#include "src/builtins/builtins.h" #include "src/builtins/builtins.h"
#include "src/counters.h" #include "src/counters.h"
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_BUILTINS_BUILTINS_PROMISE_H_
#define V8_BUILTINS_BUILTINS_PROMISE_H_
#include "src/contexts.h"
namespace v8 {
namespace internal {
class PromiseBuiltins {
public:
enum PromiseResolvingFunctionContextSlot {
// The promise which resolve/reject callbacks fulfill.
kPromiseSlot = Context::MIN_CONTEXT_SLOTS,
// Whether the callback was already invoked.
kAlreadyResolvedSlot,
// Whether to trigger a debug event or not. Used in catch
// prediction.
kDebugEventSlot,
kPromiseContextLength,
};
// TODO(bmeurer): Move this to a proper context map in contexts.h?
// Similar to the AwaitContext that we introduced for await closures.
enum PromiseAllResolveElementContextSlots {
// Remaining elements count
kPromiseAllResolveElementRemainingSlot = Context::MIN_CONTEXT_SLOTS,
// Promise capability from Promise.all
kPromiseAllResolveElementCapabilitySlot,
// Values array from Promise.all
kPromiseAllResolveElementValuesArraySlot,
kPromiseAllResolveElementLength
};
enum FunctionContextSlot {
kCapabilitySlot = Context::MIN_CONTEXT_SLOTS,
kCapabilitiesContextLength,
};
// This is used by the Promise.prototype.finally builtin to store
// onFinally callback and the 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,
kConstructorSlot,
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,
};
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseBuiltins);
};
} // namespace internal
} // namespace v8
#endif // V8_BUILTINS_BUILTINS_PROMISE_H_
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "src/compiler/js-call-reducer.h" #include "src/compiler/js-call-reducer.h"
#include "src/api-inl.h" #include "src/api-inl.h"
#include "src/builtins/builtins-promise-gen.h" #include "src/builtins/builtins-promise.h"
#include "src/builtins/builtins-utils.h" #include "src/builtins/builtins-utils.h"
#include "src/code-factory.h" #include "src/code-factory.h"
#include "src/compiler/access-builder.h" #include "src/compiler/access-builder.h"
...@@ -5602,21 +5602,20 @@ Reduction JSCallReducer::ReducePromiseConstructor(Node* node) { ...@@ -5602,21 +5602,20 @@ Reduction JSCallReducer::ReducePromiseConstructor(Node* node) {
Node* promise_context = effect = graph()->NewNode( Node* promise_context = effect = graph()->NewNode(
javascript()->CreateFunctionContext( javascript()->CreateFunctionContext(
handle(native_context().object()->scope_info(), isolate()), handle(native_context().object()->scope_info(), isolate()),
PromiseBuiltinsAssembler::kPromiseContextLength - PromiseBuiltins::kPromiseContextLength - Context::MIN_CONTEXT_SLOTS,
Context::MIN_CONTEXT_SLOTS,
FUNCTION_SCOPE), FUNCTION_SCOPE),
context, effect, control); context, effect, control);
effect =
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForContextSlot(
PromiseBuiltinsAssembler::kPromiseSlot)),
promise_context, promise, effect, control);
effect = graph()->NewNode( effect = graph()->NewNode(
simplified()->StoreField(AccessBuilder::ForContextSlot( simplified()->StoreField(
PromiseBuiltinsAssembler::kAlreadyResolvedSlot)), AccessBuilder::ForContextSlot(PromiseBuiltins::kPromiseSlot)),
promise_context, promise, effect, control);
effect = graph()->NewNode(
simplified()->StoreField(
AccessBuilder::ForContextSlot(PromiseBuiltins::kAlreadyResolvedSlot)),
promise_context, jsgraph()->FalseConstant(), effect, control); promise_context, jsgraph()->FalseConstant(), effect, control);
effect = graph()->NewNode( effect = graph()->NewNode(
simplified()->StoreField(AccessBuilder::ForContextSlot( simplified()->StoreField(
PromiseBuiltinsAssembler::kDebugEventSlot)), AccessBuilder::ForContextSlot(PromiseBuiltins::kDebugEventSlot)),
promise_context, jsgraph()->TrueConstant(), effect, control); promise_context, jsgraph()->TrueConstant(), effect, control);
// Allocate the closure for the resolve case. // Allocate the closure for the resolve case.
...@@ -5922,18 +5921,18 @@ Reduction JSCallReducer::ReducePromisePrototypeFinally(Node* node) { ...@@ -5922,18 +5921,18 @@ Reduction JSCallReducer::ReducePromisePrototypeFinally(Node* node) {
context = etrue = graph()->NewNode( context = etrue = graph()->NewNode(
javascript()->CreateFunctionContext( javascript()->CreateFunctionContext(
handle(native_context().object()->scope_info(), isolate()), handle(native_context().object()->scope_info(), isolate()),
PromiseBuiltinsAssembler::kPromiseFinallyContextLength - PromiseBuiltins::kPromiseFinallyContextLength -
Context::MIN_CONTEXT_SLOTS, Context::MIN_CONTEXT_SLOTS,
FUNCTION_SCOPE), FUNCTION_SCOPE),
context, etrue, if_true); context, etrue, if_true);
etrue = etrue = graph()->NewNode(
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForContextSlot( simplified()->StoreField(
PromiseBuiltinsAssembler::kOnFinallySlot)), AccessBuilder::ForContextSlot(PromiseBuiltins::kOnFinallySlot)),
context, on_finally, etrue, if_true); context, on_finally, etrue, if_true);
etrue = etrue = graph()->NewNode(
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForContextSlot( simplified()->StoreField(
PromiseBuiltinsAssembler::kConstructorSlot)), AccessBuilder::ForContextSlot(PromiseBuiltins::kConstructorSlot)),
context, constructor, etrue, if_true); context, constructor, etrue, if_true);
// Allocate the closure for the reject case. // Allocate the closure for the reject case.
SharedFunctionInfoRef catch_finally = SharedFunctionInfoRef catch_finally =
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "src/base/sys-info.h" #include "src/base/sys-info.h"
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
#include "src/bootstrapper.h" #include "src/bootstrapper.h"
#include "src/builtins/builtins-promise-gen.h" #include "src/builtins/builtins-promise.h"
#include "src/builtins/constants-table-builder.h" #include "src/builtins/constants-table-builder.h"
#include "src/cancelable-task.h" #include "src/cancelable-task.h"
#include "src/compilation-cache.h" #include "src/compilation-cache.h"
...@@ -763,7 +763,7 @@ void CaptureAsyncStackTrace(Isolate* isolate, Handle<JSPromise> promise, ...@@ -763,7 +763,7 @@ void CaptureAsyncStackTrace(Isolate* isolate, Handle<JSPromise> promise,
// find the promise capability that's being resolved when all // find the promise capability that's being resolved when all
// the concurrent promises resolve. // the concurrent promises resolve.
int const index = int const index =
PromiseBuiltinsAssembler::kPromiseAllResolveElementCapabilitySlot; PromiseBuiltins::kPromiseAllResolveElementCapabilitySlot;
Handle<PromiseCapability> capability( Handle<PromiseCapability> capability(
PromiseCapability::cast(context->get(index)), isolate); PromiseCapability::cast(context->get(index)), isolate);
if (!capability->promise()->IsJSPromise()) return; if (!capability->promise()->IsJSPromise()) return;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/api-inl.h" #include "src/api-inl.h"
#include "src/base/utils/random-number-generator.h" #include "src/base/utils/random-number-generator.h"
#include "src/builtins/builtins-promise-gen.h" #include "src/builtins/builtins-promise-gen.h"
#include "src/builtins/builtins-promise.h"
#include "src/builtins/builtins-string-gen.h" #include "src/builtins/builtins-string-gen.h"
#include "src/char-predicates.h" #include "src/char-predicates.h"
#include "src/code-factory.h" #include "src/code-factory.h"
...@@ -2358,9 +2359,9 @@ TEST(CreatePromiseResolvingFunctionsContext) { ...@@ -2358,9 +2359,9 @@ TEST(CreatePromiseResolvingFunctionsContext) {
CHECK_EQ(isolate->native_context()->scope_info(), context_js->scope_info()); CHECK_EQ(isolate->native_context()->scope_info(), context_js->scope_info());
CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context_js->extension()); CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context_js->extension());
CHECK_EQ(*isolate->native_context(), context_js->native_context()); CHECK_EQ(*isolate->native_context(), context_js->native_context());
CHECK(context_js->get(PromiseBuiltinsAssembler::kPromiseSlot)->IsJSPromise()); CHECK(context_js->get(PromiseBuiltins::kPromiseSlot)->IsJSPromise());
CHECK_EQ(ReadOnlyRoots(isolate).false_value(), CHECK_EQ(ReadOnlyRoots(isolate).false_value(),
context_js->get(PromiseBuiltinsAssembler::kDebugEventSlot)); context_js->get(PromiseBuiltins::kDebugEventSlot));
} }
TEST(CreatePromiseResolvingFunctions) { TEST(CreatePromiseResolvingFunctions) {
...@@ -2518,13 +2519,12 @@ TEST(CreatePromiseGetCapabilitiesExecutorContext) { ...@@ -2518,13 +2519,12 @@ TEST(CreatePromiseGetCapabilitiesExecutorContext) {
ft.Call(isolate->factory()->undefined_value()).ToHandleChecked(); ft.Call(isolate->factory()->undefined_value()).ToHandleChecked();
CHECK(result_obj->IsContext()); CHECK(result_obj->IsContext());
Handle<Context> context_js = Handle<Context>::cast(result_obj); Handle<Context> context_js = Handle<Context>::cast(result_obj);
CHECK_EQ(PromiseBuiltinsAssembler::kCapabilitiesContextLength, CHECK_EQ(PromiseBuiltins::kCapabilitiesContextLength, context_js->length());
context_js->length());
CHECK_EQ(isolate->native_context()->scope_info(), context_js->scope_info()); CHECK_EQ(isolate->native_context()->scope_info(), context_js->scope_info());
CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context_js->extension()); CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context_js->extension());
CHECK_EQ(*isolate->native_context(), context_js->native_context()); CHECK_EQ(*isolate->native_context(), context_js->native_context());
CHECK(context_js->get(PromiseBuiltinsAssembler::kCapabilitySlot) CHECK(
->IsPromiseCapability()); context_js->get(PromiseBuiltins::kCapabilitySlot)->IsPromiseCapability());
} }
TEST(NewPromiseCapability) { TEST(NewPromiseCapability) {
...@@ -2571,10 +2571,8 @@ TEST(NewPromiseCapability) { ...@@ -2571,10 +2571,8 @@ TEST(NewPromiseCapability) {
CHECK_EQ(isolate->native_context()->scope_info(), context->scope_info()); CHECK_EQ(isolate->native_context()->scope_info(), context->scope_info());
CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context->extension()); CHECK_EQ(ReadOnlyRoots(isolate).the_hole_value(), context->extension());
CHECK_EQ(*isolate->native_context(), context->native_context()); CHECK_EQ(*isolate->native_context(), context->native_context());
CHECK_EQ(PromiseBuiltinsAssembler::kPromiseContextLength, CHECK_EQ(PromiseBuiltins::kPromiseContextLength, context->length());
context->length()); CHECK_EQ(context->get(PromiseBuiltins::kPromiseSlot), result->promise());
CHECK_EQ(context->get(PromiseBuiltinsAssembler::kPromiseSlot),
result->promise());
} }
} }
......
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