Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/diagnostics_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
ObjectDefineProperty,
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
Promise,
ReflectApply,
SafeFinalizationRegistry,
SafeMap,
Expand Down Expand Up @@ -375,6 +376,10 @@ class TracingChannel {
asyncStart.publish(context);
// TODO: Is there a way to have asyncEnd _after_ the continuation?
asyncEnd.publish(context);
}

function rejectAndRethrow(err) {
reject(err);
throw err;
}

Expand All @@ -396,7 +401,12 @@ class TracingChannel {
context.result = result;
return result;
}
return result.then(resolve, reject);
// TODO(qard): Not realm safe? Should be a construct.name check?
if (result.constructor === Promise) {
Comment on lines +404 to +405
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require('internal/util/types').isPromise()?

return result.then(resolve, rejectAndRethrow);
}
result.then(resolve, reject);
return result;
} catch (err) {
context.error = err;
error.publish(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ResolvedThenable {
then(resolve) {
return new ResolvedThenable(resolve(this.#result));
}
customMethod() {
return this.#result;
}
}

const channel = dc.tracingChannel('test');
Expand Down Expand Up @@ -49,7 +52,10 @@ const result = channel.tracePromise(common.mustCall(function(value) {
}), input, thisArg, expectedResult);

assert(result instanceof ResolvedThenable);
assert.notStrictEqual(result, innerThenable);
// With branching then, the original thenable is returned directly so that
// extra methods defined on it remain accessible to the caller.
assert.strictEqual(result, innerThenable);
assert.deepStrictEqual(result.customMethod(), expectedResult);
result.then(common.mustCall((value) => {
assert.deepStrictEqual(value, expectedResult);
}));
Loading