Skip to content

Commit

Permalink
lib: comment explaining special-case handling of promises
Browse files Browse the repository at this point in the history
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: #39135
Backport-PR-URL: #39742
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
Qard authored and MylesBorins committed Aug 31, 2021
1 parent 5500ae9 commit 1737352
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/domain.js
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/trace_events_async_hooks.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 1737352

Please sign in to comment.