lib: comment explaining special-case handling of promises

Promise handling is special-cased for domains and trace_events.
Domains must not add the `domain` property to promises in other
contexts, and trace_events must be emitted from JavaScript as
promises no longer have an AsyncWrap type attached to them.

PR-URL: https://github.com/nodejs/node/pull/39135
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
Stephen Belanger authored and Node.js GitHub Bot committed 2021-07-23 03:54:33 +00:00
1 parent f88da657f1
commit 3fb484f4e3
2 files changed
+4

No files matched your search

+2
View File
@@ -74,6 +74,8 @@ const asyncHook = createHook({
if (process.domain !== null && process.domain !== undefined) {
// If this operation is created while in a domain, let's mark it
pairing.set(asyncId, process.domain[kWeak]);
// Promises from other contexts, such as with the VM module, should not
// have a domain property as it can be used to escape the sandbox.
if (type !== 'PROMISE' || resource instanceof Promise) {
ObjectDefineProperty(resource, 'domain', {
configurable: true,
+2
View File
@@ -31,6 +31,8 @@ const kEnabled = Symbol('enabled');
// twice the async_wrap.Providers list is used to filter the events.
const nativeProviders = new SafeSet(ObjectKeys(async_wrap.Providers));
const typeMemory = new SafeMap();
// Promises are not AsyncWrap resources so they should emit trace_events here.
nativeProviders.delete('PROMISE');
function createHook() {