async_hooks: clean up usage in internal code

Instead of exposing internals of async_hooks & async_wrap throughout
the code base, create necessary helper methods within the internal
async_hooks that allows easy usage by Node.js internals. This stops
every single internal user of async_hooks from importing a ton of
functions, constants and internal Aliased Buffers from C++ async_wrap.

Adds functions initHooksExist, afterHooksExist, and destroyHooksExist
to determine whether the related emit methods need to be triggered.

Adds clearDefaultTriggerAsyncId and clearAsyncIdStack on the JS side
as an alternative to always calling C++.

Moves async_id_symbol and trigger_async_id_symbol to internal
async_hooks as they are never used in C++.

Renames newUid to newAsyncId for added clarity of its purpose.

Adjusts usage throughout the codebase, as well as in a couple of tests.

PR-URL: https://github.com/nodejs/node/pull/18720
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Anatoli Papirovski 2018-02-11 16:35:59 -05:00
parent 7748865cd3
commit e9ac80bb39
No known key found for this signature in database
GPG key ID: 614E2E1ABEB4B2C0
20 changed files with 141 additions and 122 deletions

View file

@ -1,7 +1,8 @@
'use strict';
// Flags: --expose-internals
const common = require('../common');
const assert = require('assert');
const async_id_symbol = process.binding('async_wrap').async_id_symbol;
const { async_id_symbol } = require('internal/async_hooks').symbols;
const http = require('http');
// Regression test for https://github.com/nodejs/node/issues/13325