Commit 01735ae2 authored by Maya Lekova's avatar Maya Lekova Committed by Commit Bot

[cleanup] TNodify AsyncBuiltinsAssembler

Bug: v8:9396
Change-Id: Icfaa04f02f1d3114cd42ad42e97572ac3cf8f985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1801841Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63784}
parent 1dd791fc
...@@ -263,7 +263,7 @@ void AsyncFunctionBuiltinsAssembler::AsyncFunctionAwait( ...@@ -263,7 +263,7 @@ void AsyncFunctionBuiltinsAssembler::AsyncFunctionAwait(
TNode<Object> value = CAST(Parameter(Descriptor::kValue)); TNode<Object> value = CAST(Parameter(Descriptor::kValue));
TNode<Context> context = CAST(Parameter(Descriptor::kContext)); TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> outer_promise = LoadObjectField( TNode<JSPromise> outer_promise = LoadObjectField<JSPromise>(
async_function_object, JSAsyncFunctionObject::kPromiseOffset); async_function_object, JSAsyncFunctionObject::kPromiseOffset);
Label after_debug_hook(this), call_debug_hook(this, Label::kDeferred); Label after_debug_hook(this), call_debug_hook(this, Label::kDeferred);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "src/builtins/builtins-utils-gen.h" #include "src/builtins/builtins-utils-gen.h"
#include "src/heap/factory-inl.h" #include "src/heap/factory-inl.h"
#include "src/objects/js-generator.h"
#include "src/objects/js-promise.h" #include "src/objects/js-promise.h"
#include "src/objects/shared-function-info.h" #include "src/objects/shared-function-info.h"
...@@ -23,11 +24,12 @@ class ValueUnwrapContext { ...@@ -23,11 +24,12 @@ class ValueUnwrapContext {
} // namespace } // namespace
Node* AsyncBuiltinsAssembler::AwaitOld(Node* context, Node* generator, TNode<Object> AsyncBuiltinsAssembler::AwaitOld(
Node* value, Node* outer_promise, TNode<Context> context, TNode<JSGeneratorObject> generator,
Node* on_resolve_context_index, TNode<Object> value, TNode<JSPromise> outer_promise,
Node* on_reject_context_index, TNode<IntPtrT> on_resolve_context_index,
Node* is_predicted_as_caught) { TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> is_predicted_as_caught) {
TNode<NativeContext> const native_context = LoadNativeContext(context); TNode<NativeContext> const native_context = LoadNativeContext(context);
static const int kWrappedPromiseOffset = static const int kWrappedPromiseOffset =
...@@ -114,13 +116,13 @@ Node* AsyncBuiltinsAssembler::AwaitOld(Node* context, Node* generator, ...@@ -114,13 +116,13 @@ Node* AsyncBuiltinsAssembler::AwaitOld(Node* context, Node* generator,
on_resolve, on_reject, var_throwaway.value()); on_resolve, on_reject, var_throwaway.value());
} }
Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator, TNode<Object> AsyncBuiltinsAssembler::AwaitOptimized(
Node* promise, Node* outer_promise, TNode<Context> context, TNode<JSGeneratorObject> generator,
Node* on_resolve_context_index, TNode<JSPromise> promise, TNode<JSPromise> outer_promise,
Node* on_reject_context_index, TNode<IntPtrT> on_resolve_context_index,
Node* is_predicted_as_caught) { TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> is_predicted_as_caught) {
TNode<NativeContext> const native_context = LoadNativeContext(context); TNode<NativeContext> const native_context = LoadNativeContext(context);
CSA_ASSERT(this, IsJSPromise(promise));
static const int kResolveClosureOffset = static const int kResolveClosureOffset =
FixedArray::SizeFor(Context::MIN_CONTEXT_SLOTS); FixedArray::SizeFor(Context::MIN_CONTEXT_SLOTS);
...@@ -130,8 +132,8 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator, ...@@ -130,8 +132,8 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator,
kRejectClosureOffset + JSFunction::kSizeWithoutPrototype; kRejectClosureOffset + JSFunction::kSizeWithoutPrototype;
// 2. Let promise be ? PromiseResolve(« promise »). // 2. Let promise be ? PromiseResolve(« promise »).
// Node* const promise = // We skip this step, because promise is already guaranteed to be a
// CallBuiltin(Builtins::kPromiseResolve, context, promise_fun, value); // JSPRomise at this point.
TNode<HeapObject> base = AllocateInNewSpace(kTotalSize); TNode<HeapObject> base = AllocateInNewSpace(kTotalSize);
TNode<Context> closure_context = UncheckedCast<Context>(base); TNode<Context> closure_context = UncheckedCast<Context>(base);
...@@ -182,12 +184,13 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator, ...@@ -182,12 +184,13 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator,
on_resolve, on_reject, var_throwaway.value()); on_resolve, on_reject, var_throwaway.value());
} }
Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value, TNode<Object> AsyncBuiltinsAssembler::Await(
Node* outer_promise, TNode<Context> context, TNode<JSGeneratorObject> generator,
Node* on_resolve_context_index, TNode<Object> value, TNode<JSPromise> outer_promise,
Node* on_reject_context_index, TNode<IntPtrT> on_resolve_context_index,
Node* is_predicted_as_caught) { TNode<IntPtrT> on_reject_context_index,
VARIABLE(result, MachineRepresentation::kTagged); TNode<Oddball> is_predicted_as_caught) {
TVARIABLE(Object, result);
Label if_old(this), if_new(this), done(this), Label if_old(this), if_new(this), done(this),
if_slow_constructor(this, Label::kDeferred); if_slow_constructor(this, Label::kDeferred);
...@@ -197,7 +200,8 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value, ...@@ -197,7 +200,8 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value,
// to allocate the wrapper promise and can just use the `AwaitOptimized` // to allocate the wrapper promise and can just use the `AwaitOptimized`
// logic. // logic.
GotoIf(TaggedIsSmi(value), &if_old); GotoIf(TaggedIsSmi(value), &if_old);
TNode<Map> const value_map = LoadMap(value); TNode<HeapObject> value_object = CAST(value);
TNode<Map> const value_map = LoadMap(value_object);
GotoIfNot(IsJSPromiseMap(value_map), &if_old); GotoIfNot(IsJSPromiseMap(value_map), &if_old);
// We can skip the "constructor" lookup on {value} if it's [[Prototype]] // We can skip the "constructor" lookup on {value} if it's [[Prototype]]
// is the (initial) Promise.prototype and the @@species protector is // is the (initial) Promise.prototype and the @@species protector is
...@@ -223,25 +227,24 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value, ...@@ -223,25 +227,24 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value,
} }
BIND(&if_old); BIND(&if_old);
result.Bind(AwaitOld(context, generator, value, outer_promise, result = AwaitOld(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index, on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught)); is_predicted_as_caught);
Goto(&done); Goto(&done);
BIND(&if_new); BIND(&if_new);
result.Bind(AwaitOptimized(context, generator, value, outer_promise, result = AwaitOptimized(context, generator, CAST(value), outer_promise,
on_resolve_context_index, on_reject_context_index, on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught)); is_predicted_as_caught);
Goto(&done); Goto(&done);
BIND(&done); BIND(&done);
return result.value(); return result.value();
} }
void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context, void AsyncBuiltinsAssembler::InitializeNativeClosure(
Node* native_context, TNode<Context> context, TNode<NativeContext> native_context,
Node* function, TNode<HeapObject> function, TNode<IntPtrT> context_index) {
Node* context_index) {
TNode<Map> function_map = CAST(LoadContextElement( TNode<Map> function_map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX)); native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
// Ensure that we don't have to initialize prototype_or_initial_map field of // Ensure that we don't have to initialize prototype_or_initial_map field of
...@@ -276,33 +279,32 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context, ...@@ -276,33 +279,32 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context,
StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset, code); StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset, code);
} }
Node* AsyncBuiltinsAssembler::CreateUnwrapClosure(Node* native_context, TNode<JSFunction> AsyncBuiltinsAssembler::CreateUnwrapClosure(
Node* done) { TNode<NativeContext> native_context, TNode<HeapObject> done) {
TNode<Object> const map = LoadContextElement( TNode<Object> const map = LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
TNode<SharedFunctionInfo> const on_fulfilled_shared = CAST(LoadContextElement( TNode<SharedFunctionInfo> const on_fulfilled_shared = CAST(LoadContextElement(
native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN)); native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN));
Node* const closure_context = TNode<Context> const closure_context =
AllocateAsyncIteratorValueUnwrapContext(native_context, done); AllocateAsyncIteratorValueUnwrapContext(native_context, done);
return AllocateFunctionWithMapAndContext(map, on_fulfilled_shared, return SloppyTNode<JSFunction>(AllocateFunctionWithMapAndContext(
closure_context); map, on_fulfilled_shared, closure_context));
} }
Node* AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext( TNode<Context> AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext(
Node* native_context, Node* done) { TNode<NativeContext> native_context, TNode<HeapObject> done) {
CSA_ASSERT(this, IsNativeContext(native_context));
CSA_ASSERT(this, IsBoolean(done)); CSA_ASSERT(this, IsBoolean(done));
Node* const context = TNode<Context> context = SloppyTNode<Context>(
CreatePromiseContext(native_context, ValueUnwrapContext::kLength); CreatePromiseContext(native_context, ValueUnwrapContext::kLength));
StoreContextElementNoWriteBarrier(context, ValueUnwrapContext::kDoneSlot, StoreContextElementNoWriteBarrier(context, ValueUnwrapContext::kDoneSlot,
done); done);
return context; return context;
} }
TF_BUILTIN(AsyncIteratorValueUnwrap, AsyncBuiltinsAssembler) { TF_BUILTIN(AsyncIteratorValueUnwrap, AsyncBuiltinsAssembler) {
Node* const value = Parameter(Descriptor::kValue); TNode<Object> value = CAST(Parameter(Descriptor::kValue));
Node* const context = Parameter(Descriptor::kContext); TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> const done = TNode<Object> const done =
LoadContextElement(context, ValueUnwrapContext::kDoneSlot); LoadContextElement(context, ValueUnwrapContext::kDoneSlot);
......
...@@ -21,20 +21,27 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler { ...@@ -21,20 +21,27 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler {
// point to a SharedFunctioninfo instance used to create the closure. The // point to a SharedFunctioninfo instance used to create the closure. The
// value following the reject index should be a similar value for the resolve // value following the reject index should be a similar value for the resolve
// closure. Returns the Promise-wrapped `value`. // closure. Returns the Promise-wrapped `value`.
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, TNode<Object> Await(TNode<Context> context,
Node* on_resolve_context_index, Node* on_reject_context_index, TNode<JSGeneratorObject> generator, TNode<Object> value,
Node* is_predicted_as_caught); TNode<JSPromise> outer_promise,
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, TNode<IntPtrT> on_resolve_context_index,
int on_resolve_context_index, int on_reject_context_index, TNode<IntPtrT> on_reject_context_index,
Node* is_predicted_as_caught) { TNode<Oddball> is_predicted_as_caught);
TNode<Object> Await(TNode<Context> context,
TNode<JSGeneratorObject> generator, TNode<Object> value,
TNode<JSPromise> outer_promise,
int on_resolve_context_index, int on_reject_context_index,
TNode<Oddball> is_predicted_as_caught) {
return Await(context, generator, value, outer_promise, return Await(context, generator, value, outer_promise,
IntPtrConstant(on_resolve_context_index), IntPtrConstant(on_resolve_context_index),
IntPtrConstant(on_reject_context_index), IntPtrConstant(on_reject_context_index),
is_predicted_as_caught); is_predicted_as_caught);
} }
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise, TNode<Object> Await(TNode<Context> context,
int on_resolve_context_index, int on_reject_context_index, TNode<JSGeneratorObject> generator, TNode<Object> value,
bool is_predicted_as_caught) { TNode<JSPromise> outer_promise,
int on_resolve_context_index, int on_reject_context_index,
bool is_predicted_as_caught) {
return Await(context, generator, value, outer_promise, return Await(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index, on_resolve_context_index, on_reject_context_index,
BooleanConstant(is_predicted_as_caught)); BooleanConstant(is_predicted_as_caught));
...@@ -42,21 +49,30 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler { ...@@ -42,21 +49,30 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler {
// Return a new built-in function object as defined in // Return a new built-in function object as defined in
// Async Iterator Value Unwrap Functions // Async Iterator Value Unwrap Functions
Node* CreateUnwrapClosure(Node* const native_context, Node* const done); TNode<JSFunction> CreateUnwrapClosure(TNode<NativeContext> native_context,
TNode<HeapObject> done);
private: private:
void InitializeNativeClosure(Node* context, Node* native_context, void InitializeNativeClosure(TNode<Context> context,
Node* function, Node* context_index); TNode<NativeContext> native_context,
Node* AllocateAsyncIteratorValueUnwrapContext(Node* native_context, TNode<HeapObject> function,
Node* done); TNode<IntPtrT> context_index);
TNode<Context> AllocateAsyncIteratorValueUnwrapContext(
TNode<NativeContext> native_context, TNode<HeapObject> done);
Node* AwaitOld(Node* context, Node* generator, Node* value, TNode<Object> AwaitOld(TNode<Context> context,
Node* outer_promise, Node* on_resolve_context_index, TNode<JSGeneratorObject> generator,
Node* on_reject_context_index, Node* is_predicted_as_caught); TNode<Object> value, TNode<JSPromise> outer_promise,
Node* AwaitOptimized(Node* context, Node* generator, Node* value, TNode<IntPtrT> on_resolve_context_index,
Node* outer_promise, Node* on_resolve_context_index, TNode<IntPtrT> on_reject_context_index,
Node* on_reject_context_index, TNode<Oddball> is_predicted_as_caught);
Node* is_predicted_as_caught); TNode<Object> AwaitOptimized(TNode<Context> context,
TNode<JSGeneratorObject> generator,
TNode<JSPromise> promise,
TNode<JSPromise> outer_promise,
TNode<IntPtrT> on_resolve_context_index,
TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> is_predicted_as_caught);
}; };
} // namespace internal } // namespace internal
......
...@@ -567,13 +567,15 @@ TF_BUILTIN(AsyncGeneratorReject, AsyncGeneratorBuiltinsAssembler) { ...@@ -567,13 +567,15 @@ TF_BUILTIN(AsyncGeneratorReject, AsyncGeneratorBuiltinsAssembler) {
} }
TF_BUILTIN(AsyncGeneratorYield, AsyncGeneratorBuiltinsAssembler) { TF_BUILTIN(AsyncGeneratorYield, AsyncGeneratorBuiltinsAssembler) {
Node* const generator = Parameter(Descriptor::kGenerator); const TNode<JSGeneratorObject> generator =
Node* const value = Parameter(Descriptor::kValue); CAST(Parameter(Descriptor::kGenerator));
Node* const is_caught = Parameter(Descriptor::kIsCaught); const TNode<Object> value = CAST(Parameter(Descriptor::kValue));
Node* const context = Parameter(Descriptor::kContext); const TNode<Oddball> is_caught = CAST(Parameter(Descriptor::kIsCaught));
const TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* const request = LoadFirstAsyncGeneratorRequestFromQueue(generator); Node* const request = LoadFirstAsyncGeneratorRequestFromQueue(generator);
Node* const outer_promise = LoadPromiseFromAsyncGeneratorRequest(request); const TNode<JSPromise> outer_promise =
CAST(LoadPromiseFromAsyncGeneratorRequest(request));
const int on_resolve = Context::ASYNC_GENERATOR_YIELD_RESOLVE_SHARED_FUN; const int on_resolve = Context::ASYNC_GENERATOR_YIELD_RESOLVE_SHARED_FUN;
const int on_reject = Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN; const int on_reject = Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN;
...@@ -617,33 +619,35 @@ TF_BUILTIN(AsyncGeneratorReturn, AsyncGeneratorBuiltinsAssembler) { ...@@ -617,33 +619,35 @@ TF_BUILTIN(AsyncGeneratorReturn, AsyncGeneratorBuiltinsAssembler) {
// (per proposal-async-iteration/#sec-asyncgeneratorresumenext step 10.b.i) // (per proposal-async-iteration/#sec-asyncgeneratorresumenext step 10.b.i)
// //
// In all cases, the final step is to jump back to AsyncGeneratorResumeNext. // In all cases, the final step is to jump back to AsyncGeneratorResumeNext.
Node* const generator = Parameter(Descriptor::kGenerator); const TNode<JSGeneratorObject> generator =
Node* const value = Parameter(Descriptor::kValue); CAST(Parameter(Descriptor::kGenerator));
Node* const is_caught = Parameter(Descriptor::kIsCaught); const TNode<Object> value = CAST(Parameter(Descriptor::kValue));
const TNode<Oddball> is_caught = CAST(Parameter(Descriptor::kIsCaught));
Node* const req = LoadFirstAsyncGeneratorRequestFromQueue(generator); Node* const req = LoadFirstAsyncGeneratorRequestFromQueue(generator);
CSA_ASSERT(this, IsNotUndefined(req)); CSA_ASSERT(this, IsNotUndefined(req));
Label perform_await(this); Label perform_await(this);
VARIABLE(var_on_resolve, MachineType::PointerRepresentation(), TVARIABLE(IntPtrT, var_on_resolve,
IntPtrConstant( IntPtrConstant(
Context::ASYNC_GENERATOR_RETURN_CLOSED_RESOLVE_SHARED_FUN)); Context::ASYNC_GENERATOR_RETURN_CLOSED_RESOLVE_SHARED_FUN));
VARIABLE( TVARIABLE(
var_on_reject, MachineType::PointerRepresentation(), IntPtrT, var_on_reject,
IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_CLOSED_REJECT_SHARED_FUN)); IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_CLOSED_REJECT_SHARED_FUN));
Node* const state = LoadGeneratorState(generator); Node* const state = LoadGeneratorState(generator);
GotoIf(IsGeneratorStateClosed(state), &perform_await); GotoIf(IsGeneratorStateClosed(state), &perform_await);
var_on_resolve.Bind( var_on_resolve =
IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_RESOLVE_SHARED_FUN)); IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_RESOLVE_SHARED_FUN);
var_on_reject.Bind( var_on_reject =
IntPtrConstant(Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN)); IntPtrConstant(Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN);
Goto(&perform_await); Goto(&perform_await);
BIND(&perform_await); BIND(&perform_await);
SetGeneratorAwaiting(generator); SetGeneratorAwaiting(generator);
Node* const context = Parameter(Descriptor::kContext); TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* const outer_promise = LoadPromiseFromAsyncGeneratorRequest(req); const TNode<JSPromise> outer_promise =
CAST(LoadPromiseFromAsyncGeneratorRequest(req));
Await(context, generator, value, outer_promise, var_on_resolve.value(), Await(context, generator, value, outer_promise, var_on_resolve.value(),
var_on_reject.value(), is_caught); var_on_reject.value(), is_caught);
......
...@@ -145,7 +145,7 @@ void AsyncFromSyncBuiltinsAssembler::Generate_AsyncFromSyncIteratorMethod( ...@@ -145,7 +145,7 @@ void AsyncFromSyncBuiltinsAssembler::Generate_AsyncFromSyncIteratorMethod(
// Let onFulfilled be a new built-in function object as defined in // Let onFulfilled be a new built-in function object as defined in
// Async Iterator Value Unwrap Functions. // Async Iterator Value Unwrap Functions.
// Set onFulfilled.[[Done]] to throwDone. // Set onFulfilled.[[Done]] to throwDone.
Node* const on_fulfilled = CreateUnwrapClosure(native_context, done); Node* const on_fulfilled = CreateUnwrapClosure(native_context, CAST(done));
// Perform ! PerformPromiseThen(valueWrapper, // Perform ! PerformPromiseThen(valueWrapper,
// onFulfilled, undefined, promiseCapability). // onFulfilled, undefined, promiseCapability).
......
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