summaryrefslogtreecommitdiff
path: root/lib/async_hooks.js
Commit message (Collapse)AuthorAgeFilesLines
* lib: add trailing commas to all public core modulesAntoine du Hamel2023-02-281-4/+4
| | | | | | | | | | | | PR-URL: https://github.com/nodejs/node/pull/46848 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
* lib: add AsyncLocalStorage.bind() and .snapshot()flakey52023-02-191-0/+8
| | | | | | | PR-URL: https://github.com/nodejs/node/pull/46387 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
* async_hooks: deprecate the AsyncResource.bind asyncResource propertyJames M Snell2023-02-031-3/+11
| | | | | | | | | | | | | Runtime-deprecates the `asyncResource` property that is attached to the wrapper function returned by `asyncResource.bind()`. This property is not expected to align with the equivalent `asyncContext.wrap()` API in the proposed TC39 standard. PR-URL: https://github.com/nodejs/node/pull/46432 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
* async_hooks: remove experimental onPropagate optionJames M Snell2023-02-011-13/+2
| | | | | | | | | | | | | | | | | | | | | | | The `onPropagate` option for `AsyncLocalStorage` is problematic for a couple of reasons: 1. It is not expected to be forwards compatible in any way with the upcoming TC-39 `AsyncContext` proposal. 2. It introduces a non-trivial O(n) cost invoking a JavaScript callback for *every* AsyncResource that is created, including every Promise. While it is still experimental, I recommend removing it while we can revisit the fundamental use cases in light of the coming `AsyncContext` proposal. Refs: https://github.com/nodejs/node/issues/46374 PR-URL: https://github.com/nodejs/node/pull/46386 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
* lib: refactor to use validate functionDeokjin Kim2023-01-141-5/+2
| | | | | | | | | Throwing error after checking type is repeated. So replace it with validate function. PR-URL: https://github.com/nodejs/node/pull/46101 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
* async_hooks: refactor to use `validateObject`Deokjin Kim2023-01-011-3/+2
| | | | | | PR-URL: https://github.com/nodejs/node/pull/46004 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* async_hooks: add hook to stop propagationGerhard Stöbich2022-11-151-4/+19
| | | | | | | | | | Add hook to AsyncLocalStorage to allow user to stop propagation. This is needed to avoid leaking a store if e.g. the store indicates that its operations are finished or it reached its time to live. PR-URL: https://github.com/nodejs/node/pull/45386 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
* async_hooks: use `kEmptyObject`LiviaMedeiros2022-06-111-1/+2
| | | | | | PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
* lib: use null-prototype objects for property descriptorsAntoine du Hamel2022-06-031-0/+2
| | | | | | | | | Refs: https://github.com/nodejs/node/pull/42921 PR-URL: https://github.com/nodejs/node/pull/43270 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
* lib: fix AsyncResource.bind not using 'this' from the caller by defaultRoch Devost2022-03-081-9/+14
| | | | | | | | PR-URL: https://github.com/nodejs/node/pull/42177 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* async_hooks: expose async_wrap providersRafael Gonzaga2021-11-121-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | docs: add asyncWrapProviders api doc tests(async_hooks): use internalBinding for comparisson fix(test-async-wrap): lint error docs: use REPLACEME for asyncWrapProviders update: use freeze and copy for asyncWrapProviders update(async_hooks): use primordials on asyncWrapProviders fix: use common to expect error docs(asyncWrapProviders): rephrase return type fix: lint md fix: lint md docs(async_hooks): typo Co-authored-by: Stephen Belanger <admin@stephenbelanger.com> update(asyncWrapProviders): add __proto__ as null Co-authored-by: Simone Busoli <simone.busoli@gmail.com> Co-authored-by: Michaël Zasso <targos@protonmail.com> test: adjust __proto__ assertion docs: add DEP0111 link PR-URL: https://github.com/nodejs/node/pull/40760 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
* async_hooks: use resource stack for AsyncLocalStorage runStephen Belanger2021-08-311-8/+12
| | | | | | | | | PR-URL: https://github.com/nodejs/node/pull/39890 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
* async_hooks: refactor to avoid unsafe array iterationAntoine du Hamel2021-02-011-8/+7
| | | | | | PR-URL: https://github.com/nodejs/node/pull/37125 Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
* lib: refactor to use validateFunctionZiJian Liu2021-01-271-4/+5
| | | | | | | | | | | add validateFunction and refactor to use validateFunction PR-URL: https://github.com/nodejs/node/pull/37045 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* async_hooks: add thisArg to AsyncResource.bindJames M Snell2021-01-091-4/+9
| | | | | | | | | | | | | | | | | Semver-major Support setting the `thisArg` for AsyncResource.bind and AsyncResource.prototype.bind. If `thisArg` is not set, then `this` will be set to the `AsyncResource` instance. Fixes: https://github.com/nodejs/node/issues/36051 Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/36782 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
* async_hooks: refactor to use more primordialsAntoine du Hamel2020-11-201-7/+13
| | | | | | | | PR-URL: https://github.com/nodejs/node/pull/36168 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
* async_hooks: fix leak in AsyncLocalStorage exitStephen Belanger2020-11-111-7/+11
| | | | | | | | | | | | | | | If exit is called and then run or enterWith are called within the exit function, the als instace should not be added to the storageList additional times. The correct behaviour is to remove the instance from the storageList before executing the exit handler and then to restore it after. PR-URL: https://github.com/nodejs/node/pull/35779 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
* async_hooks: avoid GC tracking of AsyncResource in ALSGerhard Stoebich2020-08-071-2/+6
| | | | | | | | | Manually destroy the AsyncResource created by AsyncLocalStore.run() to avoid unneeded GC tracking in case a destroy hooks is present. PR-URL: https://github.com/nodejs/node/pull/34653 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
* async_hooks: don't read resource if ALS is disabledGerhard Stoebich2020-08-061-1/+1
| | | | | | | | | | | Only call executionAsyncResource() in getStore() if the ALS instance is enabled because the resource is not needed otherwise. PR-URL: https://github.com/nodejs/node/pull/34617 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* async_hooks: avoid unneeded AsyncResource creationGerhard Stoebich2020-08-061-0/+5
| | | | | | | | | | | | | | | Inspired by the callstack at https://github.com/nodejs/node/issues/34556#issuecomment-666743528 If the wanted store is equal to the active store it's not needed to create an AsyncResource. Refs: https://github.com/nodejs/node/issues/34556#issuecomment-666743528 PR-URL: https://github.com/nodejs/node/pull/34616 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
* async_hooks: improve property descriptors in als.bindGerhard Stoebich2020-08-041-1/+5
| | | | | | | | | | | | | | | | | | The length property should be non enumerable to match behavior of normal functions. The asyncResource property is enumerable and therefore it should be also writable to avoid issues like there: https://github.com/nodejs/node/pull/30932#discussion_r379679982 Both properties should be configurable. Refs: https://github.com/nodejs/node/pull/34574 PR-URL: https://github.com/nodejs/node/pull/34620 Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
* async_hooks: add AsyncResource.bind utilityJames M Snell2020-08-031-0/+24
| | | | | | | | | | | | | Creates an internal AsyncResource and binds a function to it, ensuring that the function is invoked within execution context in which bind was called. PR-URL: https://github.com/nodejs/node/pull/34574 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
* async_hooks: move PromiseHook handler to JSStephen Belanger2020-05-091-0/+3
| | | | | | | | | | | | | | | This avoids the need to wrap every promise in an AsyncWrap and also makes it easier to skip the machinery to track destroy events when there's no destroy listener. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/32891 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
* async_hooks: merge run and exit methodsAndrey Pechkurov2020-04-131-18/+2
| | | | | | PR-URL: https://github.com/nodejs/node/pull/31950 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
* async_hooks: prevent sync methods of async storage exiting outer contextStephen Belanger2020-04-131-12/+8
| | | | | | PR-URL: https://github.com/nodejs/node/pull/31950 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
* async_hooks: move to lazy destroy hook registration in AsyncResourceAndrey Pechkurov2020-04-061-1/+2
| | | | | | PR-URL: https://github.com/nodejs/node/pull/32429 Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
* async_hooks: add sync enterWith to ALSStephen Belanger2020-03-091-3/+3
| | | | | | | | | | | | | | | | | This allows transitioning the entire following sync and async execution sub-tree to the given async storage context. With this one can be sure the context binding will remain for any following sync activity and all descending async execution whereas the `run*(...)` methods must wrap everything that is intended to exist within the context. This is helpful for scenarios such as prepending a `'connection'` event to an http server which binds everything that occurs within each request to the given context. This is helpful for APMs to minimize the need for patching and especially adding closures. PR-URL: https://github.com/nodejs/node/pull/31945 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* async_hooks: fix ctx loss after nested ALS callsAndrey Pechkurov2020-03-061-9/+12
| | | | | | | PR-URL: https://github.com/nodejs/node/pull/32085 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* async_hooks: add store arg in AsyncLocalStorageAndrey Pechkurov2020-02-271-8/+6
| | | | | | | | | | | | | | | | | | | | | This commit introduces store as the first argument in AsyncLocalStorage's run methods. The change is motivated by the following expectation: most users are going to use a custom object as the store and an extra Map created by the previous implementation is an overhead for their use case. Important note. This is a backwards incompatible change. It was discussed and agreed an incompatible change is ok since the API is still experimental and the modified methods were only added within the last week so usage will be minimal to none. PR-URL: https://github.com/nodejs/node/pull/31930 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
* async_hooks: introduce async-context APIvdeturckheim2020-02-231-0/+93
| | | | | | | | | | | | | | | | Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/26540 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
* async_hooks: ensure event after been emitted on runInAsyncScopelegendecas2020-02-141-5/+10
| | | | | | | | | | | | | | | | The exception handler user-defined will not automatically emit after for the async resource. Also removes a duplicated case `test-emit-after-uncaught-exception-runInAsyncScope.js` which is identical to test-emit-after-uncaught-exception.js. Refs: https://github.com/nodejs/node/pull/30965 PR-URL: https://github.com/nodejs/node/pull/31784 Fixes: https://github.com/nodejs/node/issues/31783 Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
* async_hooks: add executionAsyncResourceMatteo Collina2020-02-111-1/+3
| | | | | | | | | | | | Remove the need for the destroy hook in the basic APM case. Co-authored-by: Stephen Belanger <admin@stephenbelanger.com> PR-URL: https://github.com/nodejs/node/pull/30959 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* async_hooks: remove internal only error checkingAnatoli Papirovski2020-01-111-0/+6
| | | | | | | | | | | | | | This error checking is mostly unnecessary and is just a Node core developer nicety, rather than something that is needed for the user-land. It can be safely removed without any practical impact while making nextTick, timers, immediates and AsyncResource substantially faster. PR-URL: https://github.com/nodejs/node/pull/30967 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
* async_hooks: ensure proper handling in runInAsyncScopeAnatoli Papirovski2019-12-161-9/+7
| | | | | | | | | | | We should never try to manually run emitAfter in case of an error, the exception handler will do it for us, if we're going to recover. PR-URL: https://github.com/nodejs/node/pull/30965 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
* lib: replace Symbol global by the primordials SymbolSebastien Ahkrin2019-12-081-0/+1
| | | | | | | | | PR-URL: https://github.com/nodejs/node/pull/30737 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* lib: use static Number properties from primordialsMichaël Zasso2019-11-301-1/+2
| | | | | | PR-URL: https://github.com/nodejs/node/pull/30686 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
* lib: flatten access to primordialsMichaël Zasso2019-11-251-2/+4
| | | | | | | | | | | | | | Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
* async_hooks: only emit `after` for AsyncResource if stack not emptyAnna Henningsen2019-10-261-1/+3
| | | | | | | | | | | | | | We clear the async id stack inside the uncaught exception handler and emit `after` events in the process, so we should not emit `after` a second time from the `runInAsyncScope()` code. This should match the behaviour we have in C++. Fixes: https://github.com/nodejs/node/issues/30080 PR-URL: https://github.com/nodejs/node/pull/30087 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
* process: improve queueMicrotask performanceAnatoli Papirovski2019-06-101-11/+15
| | | | | | | | | | | Optimize the hot code paths of queueMicrotask by not creating unnecessary objects, not looking up properties on frozen primordials, etc. PR-URL: https://github.com/nodejs/node/pull/28093 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
* async_hooks: improve AsyncResource performanceAnatoli Papirovski2019-04-051-11/+14
| | | | | | | | | | Accessing symbols is generally quite expensive and so is emitInit, only do both when actually required. PR-URL: https://github.com/nodejs/node/pull/27032 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
* lib: force using primordials for JSON, Math and ReflectMichaël Zasso2019-04-031-0/+2
| | | | | | | | | | | | Use the "no-restricted-globals" ESLint rule to lint for it. PR-URL: https://github.com/nodejs/node/pull/27027 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* async_hooks: remove deprecated emitBefore and emitAfterMatteo Collina2019-03-181-23/+0
| | | | | | | | | | | | | | | | | | AsyncResource.emitBefore and AsyncResource.emitAfter have been deprecated in https://github.com/nodejs/node/pull/18632. This PR removes it all. This commit also updates some embedder tests to use internal APIs. The conditions are still possible for Node.js core developers but not for end users. PR-URL: https://github.com/nodejs/node/pull/26530 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* doc,lib,test: capitalize comment sentencesRuben Bridgewater2018-12-171-1/+1
| | | | | | | | | | | This activates the eslint capitalize comment rule for comments above 50 characters. PR-URL: https://github.com/nodejs/node/pull/24996 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* lib: extract validateString validatorJon Moss2018-08-071-3/+2
| | | | | | | | | | | | | Pulls out a common argument validator to `internal/validators` PR-URL: https://github.com/nodejs/node/pull/22101 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* lib: always show ERR_INVALID_ARG_TYPE received partRuben Bridgewater2018-03-251-1/+1
| | | | | | | | | | | | | | This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
* async_hooks: remove async_wrap from async_hooks.jsDaniel Bevenius2018-03-181-3/+2
| | | | | | | | | | | | | | | | | | | | | | | This commit removes the builtin async_wrap module from lib/async_hooks.js. The motivation for this is that lib/async_hooks.js requires lib/internal/async_hooks which also binds async_wrap. Instead of lib/async_hooks.js also binding async_wrap it now only has to require the internal async_hooks and access it's exports. There might be a very good reason for doing it the current way but the reason is not obvious to me. Hopefully someone can shed some light on this. PR-URL: https://github.com/nodejs/node/pull/19368 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* async_hooks: don't set hook_fields[kTotals] to 0Daniel Bevenius2018-03-111-4/+2
| | | | | | | | | | | | | This commit removes the setting of hook_field[kTotals] to szero in AsyncHook's enable function. As far as I can tell this would not be required if the setting of this field is done with the assignment operator instead of using the addition assignment operator. PR-URL: https://github.com/nodejs/node/pull/19219 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
* lib: port errors to new systemMichaël Zasso2018-03-051-10/+12
| | | | | | | | | | This is a first batch of updates that touches non-underscored modules in lib. PR-URL: https://github.com/nodejs/node/pull/19034 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
* src: fix error message in async_hooks constructorDaniel Bevenius2018-02-281-5/+5
| | | | | | | | | | | | | | | There are two minor issues in the AsyncHook constructor, if the object passed in has an after and/or destroy property that are not functions the errors thrown will still be: TypeError [ERR_ASYNC_CALLBACK]: before must be a function This commit updates the code and adds a unit test. PR-URL: https://github.com/nodejs/node/pull/19000 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matheus Marchini <matheus@sthima.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
* async_hooks: clean up usage in internal codeAnatoli Papirovski2018-02-161-18/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | 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>