Skip to content

Commit 5b5e79e

Browse files
author
Sajal Khandelwal
committed
Address feedback
1 parent 9e10007 commit 5b5e79e

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

src/node_task_queue.cc

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ using v8::kPromiseResolveAfterResolved;
2525
using v8::Local;
2626
using v8::Maybe;
2727
using v8::Number;
28-
using v8::Nothing;
2928
using v8::Object;
3029
using v8::Promise;
3130
using v8::PromiseRejectEvent;
@@ -37,7 +36,7 @@ static Maybe<double> GetAssignedPromiseAsyncId(Environment* env,
3736
Local<Value> id_symbol) {
3837
Local<Value> maybe_async_id;
3938
if (!promise->Get(env->context(), id_symbol).ToLocal(&maybe_async_id)) {
40-
return Nothing<double>();
39+
return v8::Just(AsyncWrap::kInvalidAsyncId);
4140
}
4241
return maybe_async_id->IsNumber()
4342
? maybe_async_id->NumberValue(env->context())
@@ -54,15 +53,15 @@ static Maybe<double> GetAssignedPromiseWrapAsyncId(Environment* env,
5453
Local<Value> promiseWrap = promise->GetInternalField(0);
5554
if (promiseWrap->IsObject()) {
5655
Local<Value> maybe_async_id;
57-
if (!promiseWrap.As<Object>()->Get(env->context(), id_symbol).ToLocal(&maybe_async_id)) {
58-
return Nothing<double>();
56+
if (!promiseWrap.As<Object>()->Get(env->context(), id_symbol)
57+
.ToLocal(&maybe_async_id)) {
58+
return v8::Just(AsyncWrap::kInvalidAsyncId);
5959
}
6060
return maybe_async_id->IsNumber()
6161
? maybe_async_id->NumberValue(env->context())
6262
: v8::Just(AsyncWrap::kInvalidAsyncId);
63-
}
64-
else {
65-
return Nothing<double>();
63+
} else {
64+
return v8::Just(AsyncWrap::kInvalidAsyncId);
6665
}
6766
}
6867

@@ -116,28 +115,40 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
116115

117116
double async_id = AsyncWrap::kInvalidAsyncId;
118117
double trigger_async_id = AsyncWrap::kInvalidAsyncId;
119-
GetAssignedPromiseAsyncId(env, promise, env->async_id_symbol())
120-
.To(&async_id);
121-
GetAssignedPromiseAsyncId(env, promise, env->trigger_async_id_symbol())
122-
.To(&trigger_async_id);
123-
124-
GetAssignedPromiseWrapAsyncId(env, promise, env->async_id_symbol())
125-
.To(&async_id);
126-
GetAssignedPromiseWrapAsyncId(env, promise, env->trigger_async_id_symbol())
127-
.To(&trigger_async_id);
128-
118+
TryCatchScope try_catch_async_id(env);
119+
120+
if (!GetAssignedPromiseAsyncId(env, promise, env->async_id_symbol())
121+
.To(&async_id)) return;
122+
if (!GetAssignedPromiseAsyncId(env, promise, env->trigger_async_id_symbol())
123+
.To(&trigger_async_id)) return;
124+
125+
if (async_id == AsyncWrap::kInvalidAsyncId &&
126+
trigger_async_id == AsyncWrap::kInvalidAsyncId) {
127+
// That means that promise might be a PromiseWrap, so we'll
128+
// check there as well.
129+
if (!GetAssignedPromiseWrapAsyncId(env, promise, env->async_id_symbol())
130+
.To(&async_id)) return;
131+
if (!GetAssignedPromiseWrapAsyncId(
132+
env, promise, env->trigger_async_id_symbol())
133+
.To(&trigger_async_id)) return;
134+
}
135+
129136
if (async_id != AsyncWrap::kInvalidAsyncId &&
130137
trigger_async_id != AsyncWrap::kInvalidAsyncId) {
131138
env->async_hooks()->push_async_context(
132139
async_id, trigger_async_id, promise);
133140
}
134141

142+
if (try_catch_async_id.HasCaught()) {
143+
// What must be done here?
144+
}
145+
135146
TryCatchScope try_catch(env);
136147
USE(callback->Call(
137148
env->context(), Undefined(isolate), arraysize(args), args));
138149

139150
if (async_id != AsyncWrap::kInvalidAsyncId &&
140-
trigger_async_id != AsyncWrap::kInvalidAsyncId &&
151+
trigger_async_id != AsyncWrap::kInvalidAsyncId &&
141152
env->execution_async_id() == async_id) {
142153
// This condition might not be true if async_hooks was enabled during
143154
// the promise callback execution.

0 commit comments

Comments
 (0)