@@ -299,27 +299,31 @@ function defaultTriggerAsyncIdScope(triggerAsyncId, block, ...args) { |
299 | 299 | } |
300 | 300 | } |
301 | 301 |
|
| 302 | +function hasHooks(key) { |
| 303 | + return async_hook_fields[key] > 0; |
| 304 | +} |
| 305 | + |
302 | 306 | function enabledHooksExist() { |
303 | | - return async_hook_fields[kCheck] > 0; |
| 307 | + return hasHooks(kCheck); |
304 | 308 | } |
305 | 309 |
|
306 | 310 | function initHooksExist() { |
307 | | - return async_hook_fields[kInit] > 0; |
| 311 | + return hasHooks(kInit); |
308 | 312 | } |
309 | 313 |
|
310 | 314 | function afterHooksExist() { |
311 | | - return async_hook_fields[kAfter] > 0; |
| 315 | + return hasHooks(kAfter); |
312 | 316 | } |
313 | 317 |
|
314 | 318 | function destroyHooksExist() { |
315 | | - return async_hook_fields[kDestroy] > 0; |
| 319 | + return hasHooks(kDestroy); |
316 | 320 | } |
317 | 321 |
|
318 | 322 |
|
319 | 323 | function emitInitScript(asyncId, type, triggerAsyncId, resource) { |
320 | 324 | // Short circuit all checks for the common case. Which is that no hooks have |
321 | 325 | // been set. Do this to remove performance impact for embedders (and core). |
322 | | - if (async_hook_fields[kInit] === 0) |
| 326 | + if (!hasHooks(kInit)) |
323 | 327 | return; |
324 | 328 |
|
325 | 329 | if (triggerAsyncId === null) { |
@@ -333,13 +337,13 @@ function emitInitScript(asyncId, type, triggerAsyncId, resource) { |
333 | 337 | function emitBeforeScript(asyncId, triggerAsyncId) { |
334 | 338 | pushAsyncIds(asyncId, triggerAsyncId); |
335 | 339 |
|
336 | | - if (async_hook_fields[kBefore] > 0) |
| 340 | + if (hasHooks(kBefore)) |
337 | 341 | emitBeforeNative(asyncId); |
338 | 342 | } |
339 | 343 |
|
340 | 344 |
|
341 | 345 | function emitAfterScript(asyncId) { |
342 | | - if (async_hook_fields[kAfter] > 0) |
| 346 | + if (hasHooks(kAfter)) |
343 | 347 | emitAfterNative(asyncId); |
344 | 348 |
|
345 | 349 | popAsyncIds(asyncId); |
@@ -348,7 +352,7 @@ function emitAfterScript(asyncId) { |
348 | 352 |
|
349 | 353 | function emitDestroyScript(asyncId) { |
350 | 354 | // Return early if there are no destroy callbacks, or invalid asyncId. |
351 | | - if (async_hook_fields[kDestroy] === 0 || asyncId <= 0) |
| 355 | + if (!hasHooks(kDestroy) || asyncId <= 0) |
352 | 356 | return; |
353 | 357 | async_wrap.queueDestroyAsyncId(asyncId); |
354 | 358 | } |
@@ -364,7 +368,7 @@ function clearAsyncIdStack() { |
364 | 368 |
|
365 | 369 |
|
366 | 370 | function hasAsyncIdStack() { |
367 | | - return async_hook_fields[kStackLength] > 0; |
| 371 | + return hasHooks(kStackLength); |
368 | 372 | } |
369 | 373 |
|
370 | 374 |
|
|