Commit cd8100b6 authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[CSA][cleanup] TNodify builtins promise gen (pt. 2)

The promise file is too big so I am splitting it in several CLs.

TNodified:
 * AllocatePromiseReaction
 * AllocatePromiseReactionJobTask
 * AllocatePromiseResolveThenableJobTask
 * CreatePromiseResolvingFunctions
 * CreatePromiseResolvingFunctionsContext
 * CreatePromiseContext

This CL introduces some CASTs that will be deleted once the file is
TNodified in full.

Bug: v8:6949
Change-Id: Ia3006faa5e9fd0e6fa3c58511772857910326532
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1809360
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63882}
parent e8d74ad0
......@@ -93,8 +93,7 @@ TNode<Object> AsyncBuiltinsAssembler::AwaitOld(
InitializeNativeClosure(closure_context, native_context, on_reject,
on_reject_context_index);
VARIABLE(var_throwaway, MachineRepresentation::kTaggedPointer,
UndefinedConstant());
TVARIABLE(HeapObject, var_throwaway, UndefinedConstant());
// Deal with PromiseHooks and debug support in the runtime. This
// also allocates the throwaway promise, which is only needed in
......@@ -103,9 +102,9 @@ TNode<Object> AsyncBuiltinsAssembler::AwaitOld(
Branch(IsPromiseHookEnabledOrDebugIsActiveOrHasAsyncEventDelegate(),
&if_debugging, &do_resolve_promise);
BIND(&if_debugging);
var_throwaway.Bind(CallRuntime(Runtime::kAwaitPromisesInitOld, context, value,
wrapped_value, outer_promise, on_reject,
is_predicted_as_caught));
var_throwaway = CAST(CallRuntime(Runtime::kAwaitPromisesInitOld, context,
value, wrapped_value, outer_promise,
on_reject, is_predicted_as_caught));
Goto(&do_resolve_promise);
BIND(&do_resolve_promise);
......@@ -164,8 +163,7 @@ TNode<Object> AsyncBuiltinsAssembler::AwaitOptimized(
InitializeNativeClosure(closure_context, native_context, on_reject,
on_reject_context_index);
VARIABLE(var_throwaway, MachineRepresentation::kTaggedPointer,
UndefinedConstant());
TVARIABLE(HeapObject, var_throwaway, UndefinedConstant());
// Deal with PromiseHooks and debug support in the runtime. This
// also allocates the throwaway promise, which is only needed in
......@@ -174,9 +172,9 @@ TNode<Object> AsyncBuiltinsAssembler::AwaitOptimized(
Branch(IsPromiseHookEnabledOrDebugIsActiveOrHasAsyncEventDelegate(),
&if_debugging, &do_perform_promise_then);
BIND(&if_debugging);
var_throwaway.Bind(CallRuntime(Runtime::kAwaitPromisesInit, context, promise,
promise, outer_promise, on_reject,
is_predicted_as_caught));
var_throwaway =
CAST(CallRuntime(Runtime::kAwaitPromisesInit, context, promise, promise,
outer_promise, on_reject, is_predicted_as_caught));
Goto(&do_perform_promise_then);
BIND(&do_perform_promise_then);
......@@ -281,22 +279,22 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(
TNode<JSFunction> AsyncBuiltinsAssembler::CreateUnwrapClosure(
TNode<NativeContext> native_context, TNode<HeapObject> done) {
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<SharedFunctionInfo> const on_fulfilled_shared = CAST(LoadContextElement(
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> on_fulfilled_shared = CAST(LoadContextElement(
native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN));
TNode<Context> const closure_context =
const TNode<Context> closure_context =
AllocateAsyncIteratorValueUnwrapContext(native_context, done);
return SloppyTNode<JSFunction>(AllocateFunctionWithMapAndContext(
map, on_fulfilled_shared, closure_context));
return AllocateFunctionWithMapAndContext(map, on_fulfilled_shared,
closure_context);
}
TNode<Context> AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext(
TNode<NativeContext> native_context, TNode<HeapObject> done) {
CSA_ASSERT(this, IsBoolean(done));
TNode<Context> context = SloppyTNode<Context>(
CreatePromiseContext(native_context, ValueUnwrapContext::kLength));
TNode<Context> context =
CreatePromiseContext(native_context, ValueUnwrapContext::kLength);
StoreContextElementNoWriteBarrier(context, ValueUnwrapContext::kDoneSlot,
done);
return context;
......
......@@ -98,22 +98,23 @@ TNode<JSPromise> PromiseBuiltinsAssembler::AllocateAndSetJSPromise(
return instance;
}
std::pair<Node*, Node*>
std::pair<TNode<JSFunction>, TNode<JSFunction>>
PromiseBuiltinsAssembler::CreatePromiseResolvingFunctions(
Node* promise, Node* debug_event, Node* native_context) {
Node* const promise_context = CreatePromiseResolvingFunctionsContext(
TNode<JSPromise> promise, TNode<Object> debug_event,
TNode<NativeContext> native_context) {
const TNode<Context> promise_context = CreatePromiseResolvingFunctionsContext(
promise, debug_event, native_context);
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const resolve_info = LoadContextElement(
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> resolve_info = CAST(LoadContextElement(
native_context,
Context::PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX);
Node* const resolve =
Context::PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX));
const TNode<JSFunction> resolve =
AllocateFunctionWithMapAndContext(map, resolve_info, promise_context);
TNode<Object> const reject_info = LoadContextElement(
const TNode<SharedFunctionInfo> reject_info = CAST(LoadContextElement(
native_context,
Context::PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX);
Node* const reject =
Context::PROMISE_CAPABILITY_DEFAULT_REJECT_SHARED_FUN_INDEX));
const TNode<JSFunction> reject =
AllocateFunctionWithMapAndContext(map, reject_info, promise_context);
return std::make_pair(resolve, reject);
}
......@@ -197,7 +198,7 @@ TF_BUILTIN(NewPromiseCapability, PromiseBuiltinsAssembler) {
BIND(&if_fast_promise_capability);
{
Node* promise =
TNode<JSPromise> promise =
AllocateAndInitJSPromise(native_context, UndefinedConstant());
Node* resolve = nullptr;
......@@ -227,14 +228,15 @@ TF_BUILTIN(NewPromiseCapability, PromiseBuiltinsAssembler) {
StoreObjectFieldRoot(capability, PromiseCapability::kRejectOffset,
RootIndex::kUndefinedValue);
Node* executor_context =
CreatePromiseGetCapabilitiesExecutorContext(capability, native_context);
TNode<Object> executor_info = LoadContextElement(
native_context, Context::PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN);
TNode<Object> function_map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<JSFunction> executor = CAST(AllocateFunctionWithMapAndContext(
function_map, executor_info, executor_context));
TNode<Context> executor_context =
CAST(CreatePromiseGetCapabilitiesExecutorContext(capability,
native_context));
TNode<SharedFunctionInfo> executor_info = CAST(LoadContextElement(
native_context, Context::PROMISE_GET_CAPABILITIES_EXECUTOR_SHARED_FUN));
TNode<Map> function_map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
TNode<JSFunction> executor = AllocateFunctionWithMapAndContext(
function_map, executor_info, executor_context);
TNode<JSReceiver> promise =
Construct(native_context, CAST(constructor), executor);
......@@ -259,14 +261,14 @@ TF_BUILTIN(NewPromiseCapability, PromiseBuiltinsAssembler) {
ThrowTypeError(context, MessageTemplate::kPromiseNonCallable);
}
Node* PromiseBuiltinsAssembler::CreatePromiseContext(Node* native_context,
int slots) {
TNode<Context> PromiseBuiltinsAssembler::CreatePromiseContext(
TNode<NativeContext> native_context, int slots) {
DCHECK_GE(slots, Context::MIN_CONTEXT_SLOTS);
TNode<HeapObject> const context =
AllocateInNewSpace(FixedArray::SizeFor(slots));
InitializeFunctionContext(native_context, context, slots);
return context;
return CAST(context);
}
Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementContext(
......@@ -280,7 +282,7 @@ Node* PromiseBuiltinsAssembler::CreatePromiseAllResolveElementContext(
PACKED_ELEMENTS, array_map, IntPtrConstant(0), SmiConstant(0));
Node* const context = CreatePromiseContext(
native_context, PromiseBuiltins::kPromiseAllResolveElementLength);
CAST(native_context), PromiseBuiltins::kPromiseAllResolveElementLength);
StoreContextElementNoWriteBarrier(
context, PromiseBuiltins::kPromiseAllResolveElementRemainingSlot,
SmiConstant(1));
......@@ -302,12 +304,12 @@ PromiseBuiltinsAssembler::CreatePromiseAllResolveElementFunction(
index, SmiConstant(PropertyArray::HashField::kMax)));
CSA_ASSERT(this, IsNativeContext(native_context));
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const resolve_info =
LoadContextElement(native_context, slot_index);
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> resolve_info =
CAST(LoadContextElement(native_context, slot_index));
TNode<JSFunction> resolve =
Cast(AllocateFunctionWithMapAndContext(map, resolve_info, context));
AllocateFunctionWithMapAndContext(map, resolve_info, CAST(context));
STATIC_ASSERT(PropertyArray::kNoHashSentinel == 0);
StoreObjectFieldNoWriteBarrier(resolve, JSFunction::kPropertiesOrHashOffset,
......@@ -316,9 +318,10 @@ PromiseBuiltinsAssembler::CreatePromiseAllResolveElementFunction(
return resolve;
}
Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext(
Node* promise, Node* debug_event, Node* native_context) {
Node* const context = CreatePromiseContext(
TNode<Context> PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext(
TNode<JSPromise> promise, TNode<Object> debug_event,
TNode<NativeContext> native_context) {
const TNode<Context> context = CreatePromiseContext(
native_context, PromiseBuiltins::kPromiseContextLength);
StoreContextElementNoWriteBarrier(context, PromiseBuiltins::kPromiseSlot,
promise);
......@@ -332,7 +335,7 @@ Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext(
Node* PromiseBuiltinsAssembler::CreatePromiseGetCapabilitiesExecutorContext(
Node* promise_capability, Node* native_context) {
int kContextLength = PromiseBuiltins::kCapabilitiesContextLength;
Node* context = CreatePromiseContext(native_context, kContextLength);
Node* context = CreatePromiseContext(CAST(native_context), kContextLength);
StoreContextElementNoWriteBarrier(context, PromiseBuiltins::kCapabilitySlot,
promise_capability);
return context;
......@@ -410,9 +413,9 @@ void PromiseBuiltinsAssembler::PerformPromiseThen(
// PromiseReaction holding both the onFulfilled and onRejected callbacks.
// Once the {promise} is resolved we decide on the concrete handler to
// push onto the microtask queue.
TNode<Object> const promise_reactions =
const TNode<Object> promise_reactions =
LoadObjectField(promise, JSPromise::kReactionsOrResultOffset);
Node* const reaction =
const TNode<PromiseReaction> reaction =
AllocatePromiseReaction(promise_reactions, result_promise_or_capability,
on_fulfilled, on_rejected);
StoreObjectField(promise, JSPromise::kReactionsOrResultOffset, reaction);
......@@ -421,10 +424,9 @@ void PromiseBuiltinsAssembler::PerformPromiseThen(
BIND(&if_notpending);
{
VARIABLE(var_map, MachineRepresentation::kTagged);
VARIABLE(var_handler, MachineRepresentation::kTagged);
VARIABLE(var_handler_context, MachineRepresentation::kTagged,
UndefinedConstant());
TVARIABLE(Map, var_map);
TVARIABLE(HeapObject, var_handler);
TVARIABLE(Object, var_handler_context, UndefinedConstant());
Label if_fulfilled(this), if_rejected(this, Label::kDeferred),
enqueue(this);
Branch(IsPromiseStatus(status, v8::Promise::kFulfilled), &if_fulfilled,
......@@ -432,15 +434,15 @@ void PromiseBuiltinsAssembler::PerformPromiseThen(
BIND(&if_fulfilled);
{
var_map.Bind(PromiseFulfillReactionJobTaskMapConstant());
var_handler.Bind(on_fulfilled);
var_map = PromiseFulfillReactionJobTaskMapConstant();
var_handler = on_fulfilled;
Label use_fallback(this, Label::kDeferred), done(this);
ExtractHandlerContext(on_fulfilled, &var_handler_context);
Branch(IsUndefined(var_handler_context.value()), &use_fallback, &done);
BIND(&use_fallback);
var_handler_context.Bind(context);
var_handler_context = context;
ExtractHandlerContext(on_rejected, &var_handler_context);
Goto(&done);
......@@ -451,15 +453,15 @@ void PromiseBuiltinsAssembler::PerformPromiseThen(
BIND(&if_rejected);
{
CSA_ASSERT(this, IsPromiseStatus(status, v8::Promise::kRejected));
var_map.Bind(PromiseRejectReactionJobTaskMapConstant());
var_handler.Bind(on_rejected);
var_map = PromiseRejectReactionJobTaskMapConstant();
var_handler = on_rejected;
Label use_fallback(this, Label::kDeferred), done(this);
ExtractHandlerContext(on_rejected, &var_handler_context);
Branch(IsUndefined(var_handler_context.value()), &use_fallback, &done);
BIND(&use_fallback);
var_handler_context.Bind(context);
var_handler_context = context;
ExtractHandlerContext(on_fulfilled, &var_handler_context);
Goto(&done);
BIND(&done);
......@@ -474,7 +476,7 @@ void PromiseBuiltinsAssembler::PerformPromiseThen(
TNode<Object> argument =
LoadObjectField(promise, JSPromise::kReactionsOrResultOffset);
Node* microtask = AllocatePromiseReactionJobTask(
var_map.value(), var_handler_context.value(), argument,
var_map.value(), CAST(var_handler_context.value()), argument,
var_handler.value(), result_promise_or_capability);
CallBuiltin(Builtins::kEnqueueMicrotask, var_handler_context.value(),
microtask);
......@@ -505,9 +507,9 @@ TF_BUILTIN(PerformPromiseThen, PromiseBuiltinsAssembler) {
Return(result_promise);
}
Node* PromiseBuiltinsAssembler::AllocatePromiseReaction(
Node* next, Node* promise_or_capability, Node* fulfill_handler,
Node* reject_handler) {
TNode<PromiseReaction> PromiseBuiltinsAssembler::AllocatePromiseReaction(
TNode<Object> next, TNode<HeapObject> promise_or_capability,
TNode<HeapObject> fulfill_handler, TNode<HeapObject> reject_handler) {
TNode<HeapObject> const reaction = Allocate(PromiseReaction::kSize);
StoreMapNoWriteBarrier(reaction, RootIndex::kPromiseReactionMap);
StoreObjectFieldNoWriteBarrier(reaction, PromiseReaction::kNextOffset, next);
......@@ -518,12 +520,13 @@ Node* PromiseBuiltinsAssembler::AllocatePromiseReaction(
reaction, PromiseReaction::kFulfillHandlerOffset, fulfill_handler);
StoreObjectFieldNoWriteBarrier(
reaction, PromiseReaction::kRejectHandlerOffset, reject_handler);
return reaction;
return CAST(reaction);
}
Node* PromiseBuiltinsAssembler::AllocatePromiseReactionJobTask(
Node* map, Node* context, Node* argument, Node* handler,
Node* promise_or_capability) {
TNode<PromiseReactionJobTask>
PromiseBuiltinsAssembler::AllocatePromiseReactionJobTask(
TNode<Map> map, TNode<Context> context, TNode<Object> argument,
TNode<HeapObject> handler, TNode<HeapObject> promise_or_capability) {
TNode<HeapObject> const microtask =
Allocate(PromiseReactionJobTask::kSizeOfAllPromiseReactionJobTasks);
StoreMapNoWriteBarrier(microtask, map);
......@@ -536,12 +539,14 @@ Node* PromiseBuiltinsAssembler::AllocatePromiseReactionJobTask(
StoreObjectFieldNoWriteBarrier(
microtask, PromiseReactionJobTask::kPromiseOrCapabilityOffset,
promise_or_capability);
return microtask;
return CAST(microtask);
}
Node* PromiseBuiltinsAssembler::AllocatePromiseResolveThenableJobTask(
Node* promise_to_resolve, Node* then, Node* thenable, Node* context) {
TNode<HeapObject> const microtask =
TNode<PromiseResolveThenableJobTask>
PromiseBuiltinsAssembler::AllocatePromiseResolveThenableJobTask(
TNode<JSPromise> promise_to_resolve, TNode<JSReceiver> then,
TNode<JSReceiver> thenable, TNode<Context> context) {
const TNode<HeapObject> microtask =
Allocate(PromiseResolveThenableJobTask::kSize);
StoreMapNoWriteBarrier(microtask,
RootIndex::kPromiseResolveThenableJobTaskMap);
......@@ -554,7 +559,7 @@ Node* PromiseBuiltinsAssembler::AllocatePromiseResolveThenableJobTask(
microtask, PromiseResolveThenableJobTask::kThenOffset, then);
StoreObjectFieldNoWriteBarrier(
microtask, PromiseResolveThenableJobTask::kThenableOffset, thenable);
return microtask;
return CAST(microtask);
}
// ES #sec-triggerpromisereactions
......@@ -1036,7 +1041,7 @@ TF_BUILTIN(PromiseConstructor, PromiseBuiltinsAssembler) {
Node *resolve, *reject;
std::tie(resolve, reject) = CreatePromiseResolvingFunctions(
var_result.value(), TrueConstant(), native_context);
CAST(var_result.value()), TrueConstant(), native_context);
Node* const maybe_exception = CallJS(
CodeFactory::Call(isolate, ConvertReceiverMode::kNullOrUndefined),
......@@ -1624,20 +1629,20 @@ TF_BUILTIN(PromiseReject, PromiseBuiltinsAssembler) {
std::pair<Node*, Node*> PromiseBuiltinsAssembler::CreatePromiseFinallyFunctions(
Node* on_finally, Node* constructor, Node* native_context) {
Node* const promise_context = CreatePromiseContext(
native_context, PromiseBuiltins::kPromiseFinallyContextLength);
const TNode<Context> promise_context = CreatePromiseContext(
CAST(native_context), PromiseBuiltins::kPromiseFinallyContextLength);
StoreContextElementNoWriteBarrier(
promise_context, PromiseBuiltins::kOnFinallySlot, on_finally);
StoreContextElementNoWriteBarrier(
promise_context, PromiseBuiltins::kConstructorSlot, constructor);
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const then_finally_info = LoadContextElement(
native_context, Context::PROMISE_THEN_FINALLY_SHARED_FUN);
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> then_finally_info = CAST(LoadContextElement(
native_context, Context::PROMISE_THEN_FINALLY_SHARED_FUN));
Node* const then_finally = AllocateFunctionWithMapAndContext(
map, then_finally_info, promise_context);
TNode<Object> const catch_finally_info = LoadContextElement(
native_context, Context::PROMISE_CATCH_FINALLY_SHARED_FUN);
const TNode<SharedFunctionInfo> catch_finally_info = CAST(LoadContextElement(
native_context, Context::PROMISE_CATCH_FINALLY_SHARED_FUN));
Node* const catch_finally = AllocateFunctionWithMapAndContext(
map, catch_finally_info, promise_context);
return std::make_pair(then_finally, catch_finally);
......@@ -1653,14 +1658,15 @@ TF_BUILTIN(PromiseValueThunkFinally, PromiseBuiltinsAssembler) {
Node* PromiseBuiltinsAssembler::CreateValueThunkFunction(Node* value,
Node* native_context) {
Node* const value_thunk_context = CreatePromiseContext(
native_context, PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
const TNode<Context> value_thunk_context = CreatePromiseContext(
CAST(native_context),
PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(value_thunk_context,
PromiseBuiltins::kValueSlot, value);
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const value_thunk_info = LoadContextElement(
native_context, Context::PROMISE_VALUE_THUNK_FINALLY_SHARED_FUN);
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> value_thunk_info = CAST(LoadContextElement(
native_context, Context::PROMISE_VALUE_THUNK_FINALLY_SHARED_FUN));
Node* const value_thunk = AllocateFunctionWithMapAndContext(
map, value_thunk_info, value_thunk_context);
return value_thunk;
......@@ -1714,14 +1720,15 @@ TF_BUILTIN(PromiseThrowerFinally, PromiseBuiltinsAssembler) {
Node* PromiseBuiltinsAssembler::CreateThrowerFunction(Node* reason,
Node* native_context) {
Node* const thrower_context = CreatePromiseContext(
native_context, PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
const TNode<Context> thrower_context = CreatePromiseContext(
CAST(native_context),
PromiseBuiltins::kPromiseValueThunkOrReasonContextLength);
StoreContextElementNoWriteBarrier(thrower_context,
PromiseBuiltins::kValueSlot, reason);
TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const thrower_info = LoadContextElement(
native_context, Context::PROMISE_THROWER_FINALLY_SHARED_FUN);
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> thrower_info = CAST(LoadContextElement(
native_context, Context::PROMISE_THROWER_FINALLY_SHARED_FUN));
Node* const thrower =
AllocateFunctionWithMapAndContext(map, thrower_info, thrower_context);
return thrower;
......@@ -1922,7 +1929,7 @@ TF_BUILTIN(ResolvePromise, PromiseBuiltinsAssembler) {
Label do_enqueue(this), if_fulfill(this), if_reject(this, Label::kDeferred),
if_runtime(this, Label::kDeferred);
TVARIABLE(Object, var_reason);
TVARIABLE(Object, var_then);
TVARIABLE(JSReceiver, var_then);
// If promise hook is enabled or the debugger is active, let
// the runtime handle this operation, which greatly reduces
......@@ -1958,7 +1965,8 @@ TF_BUILTIN(ResolvePromise, PromiseBuiltinsAssembler) {
BIND(&if_fast);
{
// The {resolution} is a native Promise in this case.
var_then = LoadContextElement(native_context, Context::PROMISE_THEN_INDEX);
var_then =
CAST(LoadContextElement(native_context, Context::PROMISE_THEN_INDEX));
Goto(&do_enqueue);
}
......@@ -1990,7 +1998,7 @@ TF_BUILTIN(ResolvePromise, PromiseBuiltinsAssembler) {
GotoIf(TaggedIsSmi(then), &if_fulfill);
TNode<Map> const then_map = LoadMap(CAST(then));
GotoIfNot(IsCallableMap(then_map), &if_fulfill);
var_then = then;
var_then = CAST(then);
Goto(&do_enqueue);
}
......@@ -1998,8 +2006,9 @@ TF_BUILTIN(ResolvePromise, PromiseBuiltinsAssembler) {
{
// 12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob,
// «promise, resolution, thenAction»).
Node* const task = AllocatePromiseResolveThenableJobTask(
promise, var_then.value(), resolution, native_context);
const TNode<PromiseResolveThenableJobTask> task =
AllocatePromiseResolveThenableJobTask(promise, var_then.value(),
CAST(resolution), native_context);
TailCallBuiltin(Builtins::kEnqueueMicrotask, native_context, task);
}
......
......@@ -34,19 +34,22 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
v8::Promise::PromiseState status,
TNode<Object> result);
Node* AllocatePromiseReaction(Node* next, Node* promise_or_capability,
Node* fulfill_handler, Node* reject_handler);
TNode<PromiseReaction> AllocatePromiseReaction(
TNode<Object> next, TNode<HeapObject> promise_or_capability,
TNode<HeapObject> fulfill_handler, TNode<HeapObject> reject_handler);
Node* AllocatePromiseReactionJobTask(Node* map, Node* context, Node* argument,
Node* handler,
Node* promise_or_capability);
Node* AllocatePromiseResolveThenableJobTask(Node* promise_to_resolve,
Node* then, Node* thenable,
Node* context);
TNode<PromiseReactionJobTask> AllocatePromiseReactionJobTask(
TNode<Map> map, TNode<Context> context, TNode<Object> argument,
TNode<HeapObject> handler, TNode<HeapObject> promise_or_capability);
std::pair<Node*, Node*> CreatePromiseResolvingFunctions(Node* promise,
Node* debug_event,
Node* native_context);
TNode<PromiseResolveThenableJobTask> AllocatePromiseResolveThenableJobTask(
TNode<JSPromise> promise_to_resolve, TNode<JSReceiver> then,
TNode<JSReceiver> thenable, TNode<Context> context);
std::pair<TNode<JSFunction>, TNode<JSFunction>>
CreatePromiseResolvingFunctions(TNode<JSPromise> promise,
TNode<Object> debug_event,
TNode<NativeContext> native_context);
Node* PromiseHasHandler(Node* promise);
......@@ -64,8 +67,9 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
Node* native_context,
int slot_index);
Node* CreatePromiseResolvingFunctionsContext(Node* promise, Node* debug_event,
Node* native_context);
TNode<Context> CreatePromiseResolvingFunctionsContext(
TNode<JSPromise> promise, TNode<Object> debug_event,
TNode<NativeContext> native_context);
Node* CreatePromiseGetCapabilitiesExecutorContext(Node* promise_capability,
Node* native_context);
......@@ -81,7 +85,8 @@ class V8_EXPORT_PRIVATE PromiseBuiltinsAssembler : public CodeStubAssembler {
TNode<HeapObject> on_rejected,
TNode<HeapObject> result_promise_or_capability);
Node* CreatePromiseContext(Node* native_context, int slots);
TNode<Context> CreatePromiseContext(TNode<NativeContext> native_context,
int slots);
Node* TriggerPromiseReactions(Node* context, Node* promise, Node* result,
PromiseReaction::Type type);
......
......@@ -129,15 +129,15 @@ TNode<JSFunction> ProxiesCodeStubAssembler::AllocateProxyRevokeFunction(
TNode<Context> context, TNode<JSProxy> proxy) {
TNode<NativeContext> const native_context = LoadNativeContext(context);
Node* const proxy_context =
CreateProxyRevokeFunctionContext(proxy, native_context);
TNode<Object> const revoke_map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<Object> const revoke_info =
LoadContextElement(native_context, Context::PROXY_REVOKE_SHARED_FUN);
return CAST(AllocateFunctionWithMapAndContext(revoke_map, revoke_info,
proxy_context));
const TNode<Context> proxy_context =
CAST(CreateProxyRevokeFunctionContext(proxy, native_context));
const TNode<Map> revoke_map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
const TNode<SharedFunctionInfo> revoke_info = CAST(
LoadContextElement(native_context, Context::PROXY_REVOKE_SHARED_FUN));
return AllocateFunctionWithMapAndContext(revoke_map, revoke_info,
proxy_context);
}
TF_BUILTIN(CallProxy, ProxiesCodeStubAssembler) {
......
......@@ -13945,11 +13945,9 @@ TNode<Code> CodeStubAssembler::GetSharedFunctionInfoCode(
return sfi_code.value();
}
Node* CodeStubAssembler::AllocateFunctionWithMapAndContext(Node* map,
Node* shared_info,
Node* context) {
CSA_SLOW_ASSERT(this, IsMap(map));
TNode<JSFunction> CodeStubAssembler::AllocateFunctionWithMapAndContext(
TNode<Map> map, TNode<SharedFunctionInfo> shared_info,
TNode<Context> context) {
TNode<Code> const code = GetSharedFunctionInfoCode(shared_info);
// TODO(ishell): All the callers of this function pass map loaded from
......@@ -13970,7 +13968,7 @@ Node* CodeStubAssembler::AllocateFunctionWithMapAndContext(Node* map,
shared_info);
StoreObjectFieldNoWriteBarrier(fun, JSFunction::kContextOffset, context);
StoreObjectFieldNoWriteBarrier(fun, JSFunction::kCodeOffset, code);
return fun;
return CAST(fun);
}
void CodeStubAssembler::CheckPrototypeEnumCache(Node* receiver,
......
......@@ -3566,8 +3566,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
SloppyTNode<SharedFunctionInfo> shared_info,
Label* if_compile_lazy = nullptr);
Node* AllocateFunctionWithMapAndContext(Node* map, Node* shared_info,
Node* context);
TNode<JSFunction> AllocateFunctionWithMapAndContext(
TNode<Map> map, TNode<SharedFunctionInfo> shared_info,
TNode<Context> context);
// Promise helpers
Node* IsPromiseHookEnabled();
......
......@@ -2419,7 +2419,7 @@ TEST(CreatePromiseResolvingFunctionsContext) {
Node* const context = m.Parameter(kNumParams + 2);
TNode<NativeContext> const native_context = m.LoadNativeContext(context);
Node* const promise =
const TNode<JSPromise> promise =
m.AllocateAndInitJSPromise(m.CAST(context), m.UndefinedConstant());
Node* const promise_context = m.CreatePromiseResolvingFunctionsContext(
promise, m.BooleanConstant(false), native_context);
......@@ -2447,7 +2447,7 @@ TEST(CreatePromiseResolvingFunctions) {
Node* const context = m.Parameter(kNumParams + 2);
TNode<NativeContext> const native_context = m.LoadNativeContext(context);
Node* const promise =
const TNode<JSPromise> promise =
m.AllocateAndInitJSPromise(m.CAST(context), m.UndefinedConstant());
Node *resolve, *reject;
std::tie(resolve, reject) = m.CreatePromiseResolvingFunctions(
......@@ -2537,7 +2537,7 @@ TEST(AllocateFunctionWithMapAndContext) {
Node* const context = m.Parameter(kNumParams + 2);
TNode<NativeContext> const native_context = m.LoadNativeContext(context);
Node* const promise =
const TNode<JSPromise> promise =
m.AllocateAndInitJSPromise(m.CAST(context), m.UndefinedConstant());
Node* promise_context = m.CreatePromiseResolvingFunctionsContext(
promise, m.BooleanConstant(false), native_context);
......@@ -2546,8 +2546,8 @@ TEST(AllocateFunctionWithMapAndContext) {
Context::PROMISE_CAPABILITY_DEFAULT_RESOLVE_SHARED_FUN_INDEX);
TNode<Object> const map = m.LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
Node* const resolve =
m.AllocateFunctionWithMapAndContext(map, resolve_info, promise_context);
Node* const resolve = m.AllocateFunctionWithMapAndContext(
m.CAST(map), m.CAST(resolve_info), m.CAST(promise_context));
m.Return(resolve);
FunctionTester ft(asm_tester.GenerateCode(), kNumParams);
......
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