Skip to content

Commit 1737352

Browse files
Stephen BelangerMylesBorins
Stephen Belanger
authored andcommitted
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: #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>
1 parent 5500ae9 commit 1737352

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/domain.js

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ const asyncHook = createHook({
7474
if (process.domain !== null && process.domain !== undefined) {
7575
// If this operation is created while in a domain, let's mark it
7676
pairing.set(asyncId, process.domain[kWeak]);
77+
// Promises from other contexts, such as with the VM module, should not
78+
// have a domain property as it can be used to escape the sandbox.
7779
if (type !== 'PROMISE' || resource instanceof Promise) {
7880
ObjectDefineProperty(resource, 'domain', {
7981
configurable: true,

lib/internal/trace_events_async_hooks.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const kEnabled = Symbol('enabled');
3131
// twice the async_wrap.Providers list is used to filter the events.
3232
const nativeProviders = new SafeSet(ObjectKeys(async_wrap.Providers));
3333
const typeMemory = new SafeMap();
34+
35+
// Promises are not AsyncWrap resources so they should emit trace_events here.
3436
nativeProviders.delete('PROMISE');
3537

3638
function createHook() {

0 commit comments

Comments
 (0)