[cleanup] TNodify AsyncBuiltinsAssembler

Bug: v8:9396
Change-Id: Icfaa04f02f1d3114cd42ad42e97572ac3cf8f985
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1801841
Reviewed-by: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63784}
This commit is contained in:
Maya Lekova 2019-09-16 10:01:56 +02:00 committed by Commit Bot
parent 1dd791fca2
commit 01735ae28a
5 changed files with 106 additions and 84 deletions

View File

@ -263,7 +263,7 @@ void AsyncFunctionBuiltinsAssembler::AsyncFunctionAwait(
TNode<Object> value = CAST(Parameter(Descriptor::kValue));
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> outer_promise = LoadObjectField(
TNode<JSPromise> outer_promise = LoadObjectField<JSPromise>(
async_function_object, JSAsyncFunctionObject::kPromiseOffset);
Label after_debug_hook(this), call_debug_hook(this, Label::kDeferred);

View File

@ -6,6 +6,7 @@
#include "src/builtins/builtins-utils-gen.h"
#include "src/heap/factory-inl.h"
#include "src/objects/js-generator.h"
#include "src/objects/js-promise.h"
#include "src/objects/shared-function-info.h"
@ -23,11 +24,12 @@ class ValueUnwrapContext {
} // namespace
Node* AsyncBuiltinsAssembler::AwaitOld(Node* context, Node* generator,
Node* value, Node* outer_promise,
Node* on_resolve_context_index,
Node* on_reject_context_index,
Node* is_predicted_as_caught) {
TNode<Object> AsyncBuiltinsAssembler::AwaitOld(
TNode<Context> context, TNode<JSGeneratorObject> generator,
TNode<Object> value, TNode<JSPromise> outer_promise,
TNode<IntPtrT> on_resolve_context_index,
TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> is_predicted_as_caught) {
TNode<NativeContext> const native_context = LoadNativeContext(context);
static const int kWrappedPromiseOffset =
@ -114,13 +116,13 @@ Node* AsyncBuiltinsAssembler::AwaitOld(Node* context, Node* generator,
on_resolve, on_reject, var_throwaway.value());
}
Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator,
Node* promise, Node* outer_promise,
Node* on_resolve_context_index,
Node* on_reject_context_index,
Node* is_predicted_as_caught) {
TNode<Object> AsyncBuiltinsAssembler::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) {
TNode<NativeContext> const native_context = LoadNativeContext(context);
CSA_ASSERT(this, IsJSPromise(promise));
static const int kResolveClosureOffset =
FixedArray::SizeFor(Context::MIN_CONTEXT_SLOTS);
@ -130,8 +132,8 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator,
kRejectClosureOffset + JSFunction::kSizeWithoutPrototype;
// 2. Let promise be ? PromiseResolve(« promise »).
// Node* const promise =
// CallBuiltin(Builtins::kPromiseResolve, context, promise_fun, value);
// We skip this step, because promise is already guaranteed to be a
// JSPRomise at this point.
TNode<HeapObject> base = AllocateInNewSpace(kTotalSize);
TNode<Context> closure_context = UncheckedCast<Context>(base);
@ -182,12 +184,13 @@ Node* AsyncBuiltinsAssembler::AwaitOptimized(Node* context, Node* generator,
on_resolve, on_reject, var_throwaway.value());
}
Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value,
Node* outer_promise,
Node* on_resolve_context_index,
Node* on_reject_context_index,
Node* is_predicted_as_caught) {
VARIABLE(result, MachineRepresentation::kTagged);
TNode<Object> AsyncBuiltinsAssembler::Await(
TNode<Context> context, TNode<JSGeneratorObject> generator,
TNode<Object> value, TNode<JSPromise> outer_promise,
TNode<IntPtrT> on_resolve_context_index,
TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> is_predicted_as_caught) {
TVARIABLE(Object, result);
Label if_old(this), if_new(this), done(this),
if_slow_constructor(this, Label::kDeferred);
@ -197,7 +200,8 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value,
// to allocate the wrapper promise and can just use the `AwaitOptimized`
// logic.
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);
// We can skip the "constructor" lookup on {value} if it's [[Prototype]]
// is the (initial) Promise.prototype and the @@species protector is
@ -223,25 +227,24 @@ Node* AsyncBuiltinsAssembler::Await(Node* context, Node* generator, Node* value,
}
BIND(&if_old);
result.Bind(AwaitOld(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught));
result = AwaitOld(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught);
Goto(&done);
BIND(&if_new);
result.Bind(AwaitOptimized(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught));
result = AwaitOptimized(context, generator, CAST(value), outer_promise,
on_resolve_context_index, on_reject_context_index,
is_predicted_as_caught);
Goto(&done);
BIND(&done);
return result.value();
}
void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context,
Node* native_context,
Node* function,
Node* context_index) {
void AsyncBuiltinsAssembler::InitializeNativeClosure(
TNode<Context> context, TNode<NativeContext> native_context,
TNode<HeapObject> function, TNode<IntPtrT> context_index) {
TNode<Map> function_map = CAST(LoadContextElement(
native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX));
// Ensure that we don't have to initialize prototype_or_initial_map field of
@ -276,33 +279,32 @@ void AsyncBuiltinsAssembler::InitializeNativeClosure(Node* context,
StoreObjectFieldNoWriteBarrier(function, JSFunction::kCodeOffset, code);
}
Node* AsyncBuiltinsAssembler::CreateUnwrapClosure(Node* native_context,
Node* done) {
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(
native_context, Context::ASYNC_ITERATOR_VALUE_UNWRAP_SHARED_FUN));
Node* const closure_context =
TNode<Context> const closure_context =
AllocateAsyncIteratorValueUnwrapContext(native_context, done);
return AllocateFunctionWithMapAndContext(map, on_fulfilled_shared,
closure_context);
return SloppyTNode<JSFunction>(AllocateFunctionWithMapAndContext(
map, on_fulfilled_shared, closure_context));
}
Node* AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext(
Node* native_context, Node* done) {
CSA_ASSERT(this, IsNativeContext(native_context));
TNode<Context> AsyncBuiltinsAssembler::AllocateAsyncIteratorValueUnwrapContext(
TNode<NativeContext> native_context, TNode<HeapObject> done) {
CSA_ASSERT(this, IsBoolean(done));
Node* const context =
CreatePromiseContext(native_context, ValueUnwrapContext::kLength);
TNode<Context> context = SloppyTNode<Context>(
CreatePromiseContext(native_context, ValueUnwrapContext::kLength));
StoreContextElementNoWriteBarrier(context, ValueUnwrapContext::kDoneSlot,
done);
return context;
}
TF_BUILTIN(AsyncIteratorValueUnwrap, AsyncBuiltinsAssembler) {
Node* const value = Parameter(Descriptor::kValue);
Node* const context = Parameter(Descriptor::kContext);
TNode<Object> value = CAST(Parameter(Descriptor::kValue));
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> const done =
LoadContextElement(context, ValueUnwrapContext::kDoneSlot);

View File

@ -21,20 +21,27 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler {
// point to a SharedFunctioninfo instance used to create the closure. The
// value following the reject index should be a similar value for the resolve
// closure. Returns the Promise-wrapped `value`.
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
Node* on_resolve_context_index, Node* on_reject_context_index,
Node* is_predicted_as_caught);
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
int on_resolve_context_index, int on_reject_context_index,
Node* is_predicted_as_caught) {
TNode<Object> Await(TNode<Context> context,
TNode<JSGeneratorObject> generator, TNode<Object> value,
TNode<JSPromise> outer_promise,
TNode<IntPtrT> on_resolve_context_index,
TNode<IntPtrT> on_reject_context_index,
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,
IntPtrConstant(on_resolve_context_index),
IntPtrConstant(on_reject_context_index),
is_predicted_as_caught);
}
Node* Await(Node* context, Node* generator, Node* value, Node* outer_promise,
int on_resolve_context_index, int on_reject_context_index,
bool 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,
bool is_predicted_as_caught) {
return Await(context, generator, value, outer_promise,
on_resolve_context_index, on_reject_context_index,
BooleanConstant(is_predicted_as_caught));
@ -42,21 +49,30 @@ class AsyncBuiltinsAssembler : public PromiseBuiltinsAssembler {
// Return a new built-in function object as defined in
// 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:
void InitializeNativeClosure(Node* context, Node* native_context,
Node* function, Node* context_index);
Node* AllocateAsyncIteratorValueUnwrapContext(Node* native_context,
Node* done);
void InitializeNativeClosure(TNode<Context> context,
TNode<NativeContext> native_context,
TNode<HeapObject> function,
TNode<IntPtrT> context_index);
TNode<Context> AllocateAsyncIteratorValueUnwrapContext(
TNode<NativeContext> native_context, TNode<HeapObject> done);
Node* AwaitOld(Node* context, Node* generator, Node* value,
Node* outer_promise, Node* on_resolve_context_index,
Node* on_reject_context_index, Node* is_predicted_as_caught);
Node* AwaitOptimized(Node* context, Node* generator, Node* value,
Node* outer_promise, Node* on_resolve_context_index,
Node* on_reject_context_index,
Node* is_predicted_as_caught);
TNode<Object> AwaitOld(TNode<Context> context,
TNode<JSGeneratorObject> generator,
TNode<Object> value, TNode<JSPromise> outer_promise,
TNode<IntPtrT> on_resolve_context_index,
TNode<IntPtrT> on_reject_context_index,
TNode<Oddball> 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

View File

@ -567,13 +567,15 @@ TF_BUILTIN(AsyncGeneratorReject, AsyncGeneratorBuiltinsAssembler) {
}
TF_BUILTIN(AsyncGeneratorYield, AsyncGeneratorBuiltinsAssembler) {
Node* const generator = Parameter(Descriptor::kGenerator);
Node* const value = Parameter(Descriptor::kValue);
Node* const is_caught = Parameter(Descriptor::kIsCaught);
Node* const context = Parameter(Descriptor::kContext);
const TNode<JSGeneratorObject> generator =
CAST(Parameter(Descriptor::kGenerator));
const TNode<Object> value = CAST(Parameter(Descriptor::kValue));
const TNode<Oddball> is_caught = CAST(Parameter(Descriptor::kIsCaught));
const TNode<Context> context = CAST(Parameter(Descriptor::kContext));
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_reject = Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN;
@ -617,33 +619,35 @@ TF_BUILTIN(AsyncGeneratorReturn, AsyncGeneratorBuiltinsAssembler) {
// (per proposal-async-iteration/#sec-asyncgeneratorresumenext step 10.b.i)
//
// In all cases, the final step is to jump back to AsyncGeneratorResumeNext.
Node* const generator = Parameter(Descriptor::kGenerator);
Node* const value = Parameter(Descriptor::kValue);
Node* const is_caught = Parameter(Descriptor::kIsCaught);
const TNode<JSGeneratorObject> generator =
CAST(Parameter(Descriptor::kGenerator));
const TNode<Object> value = CAST(Parameter(Descriptor::kValue));
const TNode<Oddball> is_caught = CAST(Parameter(Descriptor::kIsCaught));
Node* const req = LoadFirstAsyncGeneratorRequestFromQueue(generator);
CSA_ASSERT(this, IsNotUndefined(req));
Label perform_await(this);
VARIABLE(var_on_resolve, MachineType::PointerRepresentation(),
IntPtrConstant(
Context::ASYNC_GENERATOR_RETURN_CLOSED_RESOLVE_SHARED_FUN));
VARIABLE(
var_on_reject, MachineType::PointerRepresentation(),
TVARIABLE(IntPtrT, var_on_resolve,
IntPtrConstant(
Context::ASYNC_GENERATOR_RETURN_CLOSED_RESOLVE_SHARED_FUN));
TVARIABLE(
IntPtrT, var_on_reject,
IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_CLOSED_REJECT_SHARED_FUN));
Node* const state = LoadGeneratorState(generator);
GotoIf(IsGeneratorStateClosed(state), &perform_await);
var_on_resolve.Bind(
IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_RESOLVE_SHARED_FUN));
var_on_reject.Bind(
IntPtrConstant(Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN));
var_on_resolve =
IntPtrConstant(Context::ASYNC_GENERATOR_RETURN_RESOLVE_SHARED_FUN);
var_on_reject =
IntPtrConstant(Context::ASYNC_GENERATOR_AWAIT_REJECT_SHARED_FUN);
Goto(&perform_await);
BIND(&perform_await);
SetGeneratorAwaiting(generator);
Node* const context = Parameter(Descriptor::kContext);
Node* const outer_promise = LoadPromiseFromAsyncGeneratorRequest(req);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
const TNode<JSPromise> outer_promise =
CAST(LoadPromiseFromAsyncGeneratorRequest(req));
Await(context, generator, value, outer_promise, var_on_resolve.value(),
var_on_reject.value(), is_caught);

View File

@ -145,7 +145,7 @@ void AsyncFromSyncBuiltinsAssembler::Generate_AsyncFromSyncIteratorMethod(
// Let onFulfilled be a new built-in function object as defined in
// Async Iterator Value Unwrap Functions.
// 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,
// onFulfilled, undefined, promiseCapability).