(fn, context = { __proto__: null }, thisArg, ...args)
| 535 | } |
| 536 | |
| 537 | tracePromise(fn, context = { __proto__: null }, thisArg, ...args) { |
| 538 | if (!this.hasSubscribers) { |
| 539 | const result = ReflectApply(fn, thisArg, args); |
| 540 | if (typeof result?.then !== 'function') { |
| 541 | emitNonThenableWarning(fn); |
| 542 | } |
| 543 | return result; |
| 544 | } |
| 545 | |
| 546 | const { error } = this; |
| 547 | const continuationWindow = this.#continuationWindow; |
| 548 | |
| 549 | function reject(err) { |
| 550 | context.error = err; |
| 551 | error.publish(context); |
| 552 | // Use continuation window for asyncStart/asyncEnd |
| 553 | // eslint-disable-next-line no-unused-vars |
| 554 | using scope = continuationWindow.withScope(context); |
| 555 | // TODO: Is there a way to have asyncEnd _after_ the continuation? |
| 556 | return PromiseReject(err); |
| 557 | } |
| 558 | |
| 559 | function resolve(result) { |
| 560 | context.result = result; |
| 561 | // Use continuation window for asyncStart/asyncEnd |
| 562 | // eslint-disable-next-line no-unused-vars |
| 563 | using scope = continuationWindow.withScope(context); |
| 564 | // TODO: Is there a way to have asyncEnd _after_ the continuation? |
| 565 | return result; |
| 566 | } |
| 567 | |
| 568 | // eslint-disable-next-line no-unused-vars |
| 569 | using scope = this.#callWindow.withScope(context); |
| 570 | try { |
| 571 | const result = ReflectApply(fn, thisArg, args); |
| 572 | // If the return value is not a thenable, return it directly with a warning. |
| 573 | // Do not publish to asyncStart/asyncEnd. |
| 574 | if (typeof result?.then !== 'function') { |
| 575 | emitNonThenableWarning(fn); |
| 576 | context.result = result; |
| 577 | return result; |
| 578 | } |
| 579 | // For native Promises use PromisePrototypeThen to avoid user overrides. |
| 580 | if (isPromise(result)) { |
| 581 | return PromisePrototypeThen(result, resolve, reject); |
| 582 | } |
| 583 | // For custom thenables, call .then() directly to preserve the thenable type. |
| 584 | return result.then(resolve, reject); |
| 585 | } catch (err) { |
| 586 | context.error = err; |
| 587 | error.publish(context); |
| 588 | throw err; |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | traceCallback(fn, position = -1, context = kEmptyObject, thisArg, ...args) { |
| 593 | if (!this.hasSubscribers) { |
no test coverage detected