Commit b4aadaec authored by gsathya's avatar gsathya Committed by Commit bot

[promisehook] Store promise in PromiseReactionJob

This will be used in PromiseHook.

BUG=v8:4643

Review-Url: https://codereview.chromium.org/2581503003
Cr-Commit-Position: refs/heads/master@{#41730}
parent 80b8a3c1
......@@ -1925,7 +1925,7 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
{ // Internal: PromiseHandle
Handle<JSFunction> function = SimpleCreateFunction(
isolate, factory->empty_string(), Builtins::kPromiseHandle, 3, true);
isolate, factory->empty_string(), Builtins::kPromiseHandle, 4, true);
InstallWithIntrinsicDefaultProto(isolate, function,
Context::PROMISE_HANDLE_INDEX);
// Set up catch prediction
......
......@@ -500,8 +500,8 @@ compiler::Node* InternalPerformPromiseThen(CodeStubAssembler* a,
&reject);
// TODO(gsathya): Move this to TF.
a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, result,
var_on_resolve.value(), deferred,
a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise,
result, var_on_resolve.value(), deferred,
a->SmiConstant(kPromiseFulfilled));
a->Goto(&out);
......@@ -517,8 +517,8 @@ compiler::Node* InternalPerformPromiseThen(CodeStubAssembler* a,
a->Bind(&enqueue);
{
a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, result,
var_on_reject.value(), deferred,
a->CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, promise,
result, var_on_reject.value(), deferred,
a->SmiConstant(kPromiseRejected));
a->Goto(&out);
......@@ -909,17 +909,17 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
Node* const value = a.Parameter(1);
Node* const handler = a.Parameter(2);
Node* const deferred = a.Parameter(3);
Node* const context = a.Parameter(6);
Node* const value = a.Parameter(2);
Node* const handler = a.Parameter(3);
Node* const deferred = a.Parameter(4);
Node* const context = a.Parameter(7);
Isolate* isolate = a.isolate();
// Get promise from deferred
// TODO(gsathya): Remove this lookup by getting rid of the deferred object.
Callable getproperty_callable = CodeFactory::GetProperty(isolate);
Node* const key = a.HeapConstant(isolate->factory()->promise_string());
Node* const promise =
Node* const deferred_promise =
a.CallStub(getproperty_callable, context, deferred, key);
Variable var_reason(&a, MachineRepresentation::kTagged);
......@@ -931,7 +931,7 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
a.Bind(&debug_push);
{
a.CallRuntime(Runtime::kDebugPushPromise, context, promise);
a.CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
a.Goto(&run_handler);
}
......@@ -953,7 +953,7 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler);
a.Bind(&if_internalhandler);
InternalResolvePromise(&a, context, promise, result, &debug_pop);
InternalResolvePromise(&a, context, deferred_promise, result, &debug_pop);
a.Bind(&if_customhandler);
{
......@@ -972,7 +972,7 @@ void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
a.CallStub(getproperty_callable, context, deferred, key);
Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
a.CallStub(promise_handle_reject, context, promise, on_reject,
a.CallStub(promise_handle_reject, context, deferred_promise, on_reject,
var_reason.value());
a.Goto(&debug_pop);
}
......
......@@ -576,7 +576,7 @@ namespace internal {
TFJ(PerformPromiseThen, 4) \
TFJ(ResolvePromise, 2) \
TFS(PromiseHandleReject, BUILTIN, kNoExtraICState, PromiseHandleReject) \
TFJ(PromiseHandle, 3) \
TFJ(PromiseHandle, 4) \
\
/* Proxy */ \
CPP(ProxyConstructor) \
......
......@@ -8273,12 +8273,12 @@ void CodeStubAssembler::PromiseSet(Node* promise, Node* status, Node* result) {
StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0));
}
Node* CodeStubAssembler::AllocatePromiseReactionJobInfo(Node* value,
Node* tasks,
Node* deferred,
Node* context) {
Node* CodeStubAssembler::AllocatePromiseReactionJobInfo(
Node* value, Node* promise, Node* tasks, Node* deferred, Node* context) {
Node* const result = Allocate(PromiseReactionJobInfo::kSize);
StoreMapNoWriteBarrier(result, Heap::kPromiseReactionJobInfoMapRootIndex);
StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kPromiseOffset,
promise);
StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kValueOffset,
value);
StoreObjectFieldNoWriteBarrier(result, PromiseReactionJobInfo::kTasksOffset,
......
......@@ -1096,8 +1096,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
// provides a helper for certain init patterns.
void PromiseSet(Node* promise, Node* status, Node* result);
Node* AllocatePromiseReactionJobInfo(Node* value, Node* tasks, Node* deferred,
Node* context);
Node* AllocatePromiseReactionJobInfo(Node* value, Node* promise, Node* tasks,
Node* deferred, Node* context);
protected:
void DescriptorLookupLinear(Node* unique_name, Node* descriptors, Node* nof,
......
......@@ -1011,11 +1011,12 @@ Handle<PromiseResolveThenableJobInfo> Factory::NewPromiseResolveThenableJobInfo(
}
Handle<PromiseReactionJobInfo> Factory::NewPromiseReactionJobInfo(
Handle<Object> value, Handle<Object> tasks, Handle<Object> deferred,
Handle<Object> debug_id, Handle<Object> debug_name,
Handle<JSPromise> promise, Handle<Object> value, Handle<Object> tasks,
Handle<Object> deferred, Handle<Object> debug_id, Handle<Object> debug_name,
Handle<Context> context) {
Handle<PromiseReactionJobInfo> result = Handle<PromiseReactionJobInfo>::cast(
NewStruct(PROMISE_REACTION_JOB_INFO_TYPE));
result->set_promise(*promise);
result->set_value(*value);
result->set_tasks(*tasks);
result->set_deferred(*deferred);
......
......@@ -71,9 +71,9 @@ class V8_EXPORT_PRIVATE Factory final {
// Create a new PromiseReactionJobInfo struct.
Handle<PromiseReactionJobInfo> NewPromiseReactionJobInfo(
Handle<Object> value, Handle<Object> tasks, Handle<Object> deferred,
Handle<Object> debug_id, Handle<Object> debug_name,
Handle<Context> context);
Handle<JSPromise> promise, Handle<Object> value, Handle<Object> tasks,
Handle<Object> deferred, Handle<Object> debug_id,
Handle<Object> debug_name, Handle<Context> context);
// Create a new PromiseResolveThenableJobInfo struct.
Handle<PromiseResolveThenableJobInfo> NewPromiseResolveThenableJobInfo(
......
......@@ -3227,6 +3227,7 @@ void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info,
MaybeHandle<Object>* maybe_exception) {
PromiseDebugEventScope helper(this, info->debug_id(), info->debug_name());
Handle<JSPromise> promise(info->promise(), this);
Handle<Object> value(info->value(), this);
Handle<Object> tasks(info->tasks(), this);
Handle<JSFunction> promise_handle_fn = promise_handle();
......@@ -3238,7 +3239,7 @@ void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info,
Handle<FixedArray> deferred_arr = Handle<FixedArray>::cast(deferred);
Handle<FixedArray> tasks_arr = Handle<FixedArray>::cast(tasks);
for (int i = 0; i < deferred_arr->length(); i++) {
Handle<Object> argv[] = {value, handle(tasks_arr->get(i), this),
Handle<Object> argv[] = {promise, value, handle(tasks_arr->get(i), this),
handle(deferred_arr->get(i), this)};
*result = Execution::TryCall(this, promise_handle_fn, undefined,
arraysize(argv), argv, maybe_exception);
......@@ -3248,7 +3249,7 @@ void Isolate::PromiseReactionJob(Handle<PromiseReactionJobInfo> info,
}
}
} else {
Handle<Object> argv[] = {value, tasks, deferred};
Handle<Object> argv[] = {promise, value, tasks, deferred};
*result = Execution::TryCall(this, promise_handle_fn, undefined,
arraysize(argv), argv, maybe_exception);
}
......
......@@ -1025,6 +1025,7 @@ void PromiseResolveThenableJobInfo::PromiseResolveThenableJobInfoVerify() {
void PromiseReactionJobInfo::PromiseReactionJobInfoVerify() {
Isolate* isolate = GetIsolate();
CHECK(IsPromiseReactionJobInfo());
CHECK(promise()->IsJSPromise());
CHECK(value()->IsObject());
CHECK(tasks()->IsFixedArray() || tasks()->IsCallable());
CHECK(deferred()->IsFixedArray() || deferred()->IsJSObject());
......
......@@ -5746,6 +5746,7 @@ ACCESSORS(PromiseResolveThenableJobInfo, debug_id, Object, kDebugIdOffset)
ACCESSORS(PromiseResolveThenableJobInfo, debug_name, Object, kDebugNameOffset)
ACCESSORS(PromiseResolveThenableJobInfo, context, Context, kContextOffset);
ACCESSORS(PromiseReactionJobInfo, promise, JSPromise, kPromiseOffset);
ACCESSORS(PromiseReactionJobInfo, value, Object, kValueOffset);
ACCESSORS(PromiseReactionJobInfo, tasks, Object, kTasksOffset);
ACCESSORS(PromiseReactionJobInfo, deferred, Object, kDeferredOffset);
......
......@@ -1242,6 +1242,7 @@ void PromiseResolveThenableJobInfo::PromiseResolveThenableJobInfoPrint(
void PromiseReactionJobInfo::PromiseReactionJobInfoPrint(
std::ostream& os) { // NOLINT
HeapObject::PrintHeader(os, "PromiseReactionJobInfo");
os << "\n - promise: " << Brief(promise());
os << "\n - value: " << Brief(value());
os << "\n - tasks: " << Brief(tasks());
os << "\n - deferred: " << Brief(deferred());
......
......@@ -6893,9 +6893,12 @@ class PromiseResolveThenableJobInfo : public Struct {
DISALLOW_IMPLICIT_CONSTRUCTORS(PromiseResolveThenableJobInfo);
};
class JSPromise;
// Struct to hold state required for PromiseReactionJob.
class PromiseReactionJobInfo : public Struct {
public:
DECL_ACCESSORS(promise, JSPromise)
DECL_ACCESSORS(value, Object)
DECL_ACCESSORS(tasks, Object)
DECL_ACCESSORS(deferred, Object)
......@@ -6903,7 +6906,8 @@ class PromiseReactionJobInfo : public Struct {
DECL_ACCESSORS(debug_name, Object)
DECL_ACCESSORS(context, Context)
static const int kValueOffset = Struct::kHeaderSize;
static const int kPromiseOffset = Struct::kHeaderSize;
static const int kValueOffset = kPromiseOffset + kPointerSize;
static const int kTasksOffset = kValueOffset + kPointerSize;
static const int kDeferredOffset = kTasksOffset + kPointerSize;
static const int kDebugIdOffset = kDeferredOffset + kPointerSize;
......
......@@ -57,9 +57,9 @@ RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
}
namespace {
void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value,
Handle<Object> tasks, Handle<Object> deferred,
Handle<Object> status) {
void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise,
Handle<Object> value, Handle<Object> tasks,
Handle<Object> deferred, Handle<Object> status) {
Handle<Object> debug_id = isolate->factory()->undefined_value();
Handle<Object> debug_name = isolate->factory()->undefined_value();
if (isolate->debug()->is_active()) {
......@@ -87,9 +87,9 @@ void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value,
}
}
Handle<PromiseReactionJobInfo> info =
isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred,
debug_id, debug_name,
isolate->native_context());
isolate->factory()->NewPromiseReactionJobInfo(
promise, value, tasks, deferred, debug_id, debug_name,
isolate->native_context());
isolate->EnqueueMicrotask(info);
}
......@@ -111,7 +111,7 @@ void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise,
: promise->reject_reactions(),
isolate);
Handle<Object> deferred(promise->deferred(), isolate);
EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status);
}
PromiseSet(isolate, promise, status->value(), value);
......@@ -145,12 +145,13 @@ RUNTIME_FUNCTION(Runtime_PromiseFulfill) {
RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
HandleScope scope(isolate);
DCHECK(args.length() == 4);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, status, 3);
EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
DCHECK(args.length() == 5);
CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 3);
CONVERT_ARG_HANDLE_CHECKED(Object, status, 4);
EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status);
return isolate->heap()->undefined_value();
}
......
......@@ -1897,13 +1897,14 @@ TEST(AllocatePromiseReactionJobInfo) {
CodeStubAssembler m(data.state());
Node* const context = m.Parameter(kNumParams + 2);
Node* const promise = m.AllocateJSPromise(context);
Node* const tasks = m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1));
m.StoreFixedArrayElement(tasks, 0, m.UndefinedConstant());
Node* const deferred =
m.AllocateFixedArray(FAST_ELEMENTS, m.IntPtrConstant(1));
m.StoreFixedArrayElement(deferred, 0, m.UndefinedConstant());
Node* const info = m.AllocatePromiseReactionJobInfo(m.SmiConstant(1), tasks,
deferred, context);
Node* const info = m.AllocatePromiseReactionJobInfo(m.SmiConstant(1), promise,
tasks, deferred, context);
m.Return(info);
Handle<Code> code = data.GenerateCode();
......@@ -1916,6 +1917,7 @@ TEST(AllocatePromiseReactionJobInfo) {
Handle<PromiseReactionJobInfo> promise_info =
Handle<PromiseReactionJobInfo>::cast(result);
CHECK_EQ(Smi::FromInt(1), promise_info->value());
CHECK(promise_info->promise()->IsJSPromise());
CHECK(promise_info->tasks()->IsFixedArray());
CHECK(promise_info->deferred()->IsFixedArray());
CHECK(promise_info->context()->IsContext());
......
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