Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajal Khandelwal committed Feb 9, 2021
1 parent 9e10007 commit 5b5e79e
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/node_task_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ using v8::kPromiseResolveAfterResolved;
using v8::Local;
using v8::Maybe;
using v8::Number;
using v8::Nothing;
using v8::Object;
using v8::Promise;
using v8::PromiseRejectEvent;
Expand All @@ -37,7 +36,7 @@ static Maybe<double> GetAssignedPromiseAsyncId(Environment* env,
Local<Value> id_symbol) {
Local<Value> maybe_async_id;
if (!promise->Get(env->context(), id_symbol).ToLocal(&maybe_async_id)) {
return Nothing<double>();
return v8::Just(AsyncWrap::kInvalidAsyncId);
}
return maybe_async_id->IsNumber()
? maybe_async_id->NumberValue(env->context())
Expand All @@ -54,15 +53,15 @@ static Maybe<double> GetAssignedPromiseWrapAsyncId(Environment* env,
Local<Value> promiseWrap = promise->GetInternalField(0);
if (promiseWrap->IsObject()) {
Local<Value> maybe_async_id;
if (!promiseWrap.As<Object>()->Get(env->context(), id_symbol).ToLocal(&maybe_async_id)) {
return Nothing<double>();
if (!promiseWrap.As<Object>()->Get(env->context(), id_symbol)
.ToLocal(&maybe_async_id)) {
return v8::Just(AsyncWrap::kInvalidAsyncId);
}
return maybe_async_id->IsNumber()
? maybe_async_id->NumberValue(env->context())
: v8::Just(AsyncWrap::kInvalidAsyncId);
}
else {
return Nothing<double>();
} else {
return v8::Just(AsyncWrap::kInvalidAsyncId);
}
}

Expand Down Expand Up @@ -116,28 +115,40 @@ void PromiseRejectCallback(PromiseRejectMessage message) {

double async_id = AsyncWrap::kInvalidAsyncId;
double trigger_async_id = AsyncWrap::kInvalidAsyncId;
GetAssignedPromiseAsyncId(env, promise, env->async_id_symbol())
.To(&async_id);
GetAssignedPromiseAsyncId(env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id);

GetAssignedPromiseWrapAsyncId(env, promise, env->async_id_symbol())
.To(&async_id);
GetAssignedPromiseWrapAsyncId(env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id);

TryCatchScope try_catch_async_id(env);

if (!GetAssignedPromiseAsyncId(env, promise, env->async_id_symbol())
.To(&async_id)) return;
if (!GetAssignedPromiseAsyncId(env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id)) return;

if (async_id == AsyncWrap::kInvalidAsyncId &&
trigger_async_id == AsyncWrap::kInvalidAsyncId) {
// That means that promise might be a PromiseWrap, so we'll
// check there as well.
if (!GetAssignedPromiseWrapAsyncId(env, promise, env->async_id_symbol())
.To(&async_id)) return;
if (!GetAssignedPromiseWrapAsyncId(
env, promise, env->trigger_async_id_symbol())
.To(&trigger_async_id)) return;
}

if (async_id != AsyncWrap::kInvalidAsyncId &&
trigger_async_id != AsyncWrap::kInvalidAsyncId) {
env->async_hooks()->push_async_context(
async_id, trigger_async_id, promise);
}

if (try_catch_async_id.HasCaught()) {
// What must be done here?
}

TryCatchScope try_catch(env);
USE(callback->Call(
env->context(), Undefined(isolate), arraysize(args), args));

if (async_id != AsyncWrap::kInvalidAsyncId &&
trigger_async_id != AsyncWrap::kInvalidAsyncId &&
trigger_async_id != AsyncWrap::kInvalidAsyncId &&
env->execution_async_id() == async_id) {
// This condition might not be true if async_hooks was enabled during
// the promise callback execution.
Expand Down

0 comments on commit 5b5e79e

Please sign in to comment.