@@ -25,7 +25,6 @@ using v8::kPromiseResolveAfterResolved;
25
25
using v8::Local;
26
26
using v8::Maybe;
27
27
using v8::Number;
28
- using v8::Nothing;
29
28
using v8::Object;
30
29
using v8::Promise;
31
30
using v8::PromiseRejectEvent;
@@ -37,7 +36,7 @@ static Maybe<double> GetAssignedPromiseAsyncId(Environment* env,
37
36
Local<Value> id_symbol) {
38
37
Local<Value> maybe_async_id;
39
38
if (!promise->Get (env->context (), id_symbol).ToLocal (&maybe_async_id)) {
40
- return Nothing< double >( );
39
+ return v8::Just (AsyncWrap:: kInvalidAsyncId );
41
40
}
42
41
return maybe_async_id->IsNumber ()
43
42
? maybe_async_id->NumberValue (env->context ())
@@ -54,15 +53,15 @@ static Maybe<double> GetAssignedPromiseWrapAsyncId(Environment* env,
54
53
Local<Value> promiseWrap = promise->GetInternalField (0 );
55
54
if (promiseWrap->IsObject ()) {
56
55
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 );
59
59
}
60
60
return maybe_async_id->IsNumber ()
61
61
? maybe_async_id->NumberValue (env->context ())
62
62
: v8::Just (AsyncWrap::kInvalidAsyncId );
63
- }
64
- else {
65
- return Nothing<double >();
63
+ } else {
64
+ return v8::Just (AsyncWrap::kInvalidAsyncId );
66
65
}
67
66
}
68
67
@@ -116,28 +115,40 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
116
115
117
116
double async_id = AsyncWrap::kInvalidAsyncId ;
118
117
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
+
129
136
if (async_id != AsyncWrap::kInvalidAsyncId &&
130
137
trigger_async_id != AsyncWrap::kInvalidAsyncId ) {
131
138
env->async_hooks ()->push_async_context (
132
139
async_id, trigger_async_id, promise);
133
140
}
134
141
142
+ if (try_catch_async_id.HasCaught ()) {
143
+ // What must be done here?
144
+ }
145
+
135
146
TryCatchScope try_catch (env);
136
147
USE (callback->Call (
137
148
env->context (), Undefined (isolate), arraysize (args), args));
138
149
139
150
if (async_id != AsyncWrap::kInvalidAsyncId &&
140
- trigger_async_id != AsyncWrap::kInvalidAsyncId &&
151
+ trigger_async_id != AsyncWrap::kInvalidAsyncId &&
141
152
env->execution_async_id () == async_id) {
142
153
// This condition might not be true if async_hooks was enabled during
143
154
// the promise callback execution.
0 commit comments