@@ -166,19 +166,25 @@ static void DestroyAsyncIdsCallback(void* arg) { |
166 | 166 | } |
167 | 167 |
|
168 | 168 |
|
169 | | -void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) { |
| 169 | +void Emit(Environment* env, double async_id, AsyncHooks::Fields type, |
| 170 | + Local<Function> fn) { |
170 | 171 | AsyncHooks* async_hooks = env->async_hooks(); |
171 | 172 |
|
172 | | - if (async_hooks->fields()[AsyncHooks::kPromiseResolve] == 0) |
| 173 | + if (async_hooks->fields()[type] == 0) |
173 | 174 | return; |
174 | 175 |
|
175 | 176 | Local<Value> async_id_value = Number::New(env->isolate(), async_id); |
176 | | - Local<Function> fn = env->async_hooks_promise_resolve_function(); |
177 | 177 | FatalTryCatch try_catch(env); |
178 | 178 | USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)); |
179 | 179 | } |
180 | 180 |
|
181 | 181 |
|
| 182 | +void AsyncWrap::EmitPromiseResolve(Environment* env, double async_id) { |
| 183 | + Emit(env, async_id, AsyncHooks::kPromiseResolve, |
| 184 | + env->async_hooks_promise_resolve_function()); |
| 185 | +} |
| 186 | + |
| 187 | + |
182 | 188 | void AsyncWrap::EmitTraceEventBefore() { |
183 | 189 | switch (provider_type()) { |
184 | 190 | #define V(PROVIDER) \ |
@@ -195,15 +201,8 @@ void AsyncWrap::EmitTraceEventBefore() { |
195 | 201 |
|
196 | 202 |
|
197 | 203 | void AsyncWrap::EmitBefore(Environment* env, double async_id) { |
198 | | - AsyncHooks* async_hooks = env->async_hooks(); |
199 | | - |
200 | | - if (async_hooks->fields()[AsyncHooks::kBefore] == 0) |
201 | | - return; |
202 | | - |
203 | | - Local<Value> async_id_value = Number::New(env->isolate(), async_id); |
204 | | - Local<Function> fn = env->async_hooks_before_function(); |
205 | | - FatalTryCatch try_catch(env); |
206 | | - USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)); |
| 204 | + Emit(env, async_id, AsyncHooks::kBefore, |
| 205 | + env->async_hooks_before_function()); |
207 | 206 | } |
208 | 207 |
|
209 | 208 |
|
@@ -223,17 +222,10 @@ void AsyncWrap::EmitTraceEventAfter() { |
223 | 222 |
|
224 | 223 |
|
225 | 224 | void AsyncWrap::EmitAfter(Environment* env, double async_id) { |
226 | | - AsyncHooks* async_hooks = env->async_hooks(); |
227 | | - |
228 | | - if (async_hooks->fields()[AsyncHooks::kAfter] == 0) |
229 | | - return; |
230 | | - |
231 | 225 | // If the user's callback failed then the after() hooks will be called at the |
232 | 226 | // end of _fatalException(). |
233 | | - Local<Value> async_id_value = Number::New(env->isolate(), async_id); |
234 | | - Local<Function> fn = env->async_hooks_after_function(); |
235 | | - FatalTryCatch try_catch(env); |
236 | | - USE(fn->Call(env->context(), Undefined(env->isolate()), 1, &async_id_value)); |
| 227 | + Emit(env, async_id, AsyncHooks::kAfter, |
| 228 | + env->async_hooks_after_function()); |
237 | 229 | } |
238 | 230 |
|
239 | 231 | class PromiseWrap : public AsyncWrap { |
|