@@ -715,9 +715,19 @@ const validateByteSource = hideStackFrames((val, name) => { |
715 | 715 | val); |
716 | 716 | }); |
717 | 717 |
|
718 | | -// CryptoJob constructors can synchronously throw while running their native |
719 | | -// AdditionalConfig hook. WebCrypto needs those operation-specific setup |
720 | | -// failures to reject with an OperationError. |
| 718 | +/** |
| 719 | + * @template T |
| 720 | + * @typedef {{ run(): Promise<T> }} WebCryptoJob |
| 721 | + */ |
| 722 | + |
| 723 | +/** |
| 724 | + * CryptoJob constructors can synchronously throw while running their native |
| 725 | + * AdditionalConfig hook. WebCrypto needs those operation-specific setup |
| 726 | + * failures to reject with an OperationError. |
| 727 | + * @template T |
| 728 | + * @param {() => WebCryptoJob<T>} getJob |
| 729 | + * @returns {Promise<T>} |
| 730 | + */ |
721 | 731 | function jobPromise(getJob) { |
722 | 732 | try { |
723 | 733 | return getJob().run(); |
@@ -728,10 +738,14 @@ function jobPromise(getJob) { |
728 | 738 | } |
729 | 739 | } |
730 | 740 |
|
731 | | -// Temporarily shadow inherited then accessors on WebCrypto result objects. |
732 | | -// Promise resolution reads "then" synchronously for thenable assimilation. |
733 | | -// Returning an own undefined data property keeps that lookup from reaching |
734 | | -// user-mutated prototypes. |
| 741 | +/** |
| 742 | + * Temporarily shadow inherited then accessors on WebCrypto result objects. |
| 743 | + * Promise resolution reads "then" synchronously for thenable assimilation. |
| 744 | + * Returning an own undefined data property keeps that lookup from reaching |
| 745 | + * user-mutated prototypes. |
| 746 | + * @param {unknown} value |
| 747 | + * @returns {boolean} |
| 748 | + */ |
735 | 749 | function prepareWebCryptoResult(value) { |
736 | 750 | if ((value === null || typeof value !== 'object') && |
737 | 751 | typeof value !== 'function') { |
@@ -743,12 +757,27 @@ function prepareWebCryptoResult(value) { |
743 | 757 | return true; |
744 | 758 | } |
745 | 759 |
|
746 | | -// Remove the temporary then property installed by prepareWebCryptoResult(). |
| 760 | +/** |
| 761 | + * Remove the temporary then property installed by prepareWebCryptoResult(). |
| 762 | + * @param {{ then?: unknown }} value |
| 763 | + * @returns {void} |
| 764 | + */ |
747 | 765 | function cleanupWebCryptoResult(value) { |
748 | 766 | delete value.then; |
749 | 767 | } |
750 | 768 |
|
751 | | -// Resolve a WebCrypto promise while inherited then accessors are shadowed. |
| 769 | +/** |
| 770 | + * @template T |
| 771 | + * @typedef {(value: T | PromiseLike<T>) => void} WebCryptoResolve |
| 772 | + */ |
| 773 | + |
| 774 | +/** |
| 775 | + * Resolve a WebCrypto promise while inherited then accessors are shadowed. |
| 776 | + * @template T |
| 777 | + * @param {WebCryptoResolve<T>} resolve |
| 778 | + * @param {T | PromiseLike<T>} value |
| 779 | + * @returns {void} |
| 780 | + */ |
752 | 781 | function resolveWebCryptoResult(resolve, value) { |
753 | 782 | const shouldCleanupResult = prepareWebCryptoResult(value); |
754 | 783 | try { |
@@ -759,7 +788,17 @@ function resolveWebCryptoResult(resolve, value) { |
759 | 788 | } |
760 | 789 | } |
761 | 790 |
|
762 | | -// Run a WebCrypto promise reaction and settle the outer promise. |
| 791 | +/** |
| 792 | + * Run a WebCrypto promise reaction and settle the outer promise. |
| 793 | + * @template T |
| 794 | + * @template TResult |
| 795 | + * @param {((value: T) => TResult | PromiseLike<TResult>) | undefined} handler |
| 796 | + * @param {WebCryptoResolve<T | TResult>} resolve |
| 797 | + * @param {(reason?: unknown) => void} reject |
| 798 | + * @param {T} value |
| 799 | + * @param {boolean} isRejected |
| 800 | + * @returns {void} |
| 801 | + */ |
763 | 802 | function settleJobPromise(handler, resolve, reject, value, isRejected) { |
764 | 803 | try { |
765 | 804 | if (typeof handler === 'function') { |
@@ -774,9 +813,18 @@ function settleJobPromise(handler, resolve, reject, value, isRejected) { |
774 | 813 | } |
775 | 814 | } |
776 | 815 |
|
777 | | -// Promise.prototype.then gets promise.constructor to determine the result |
778 | | -// promise's species. These promises are internal WebCrypto intermediates, so |
779 | | -// make that lookup stay on the promise itself instead of user-mutated state. |
| 816 | +/** |
| 817 | + * Promise.prototype.then gets promise.constructor to determine the result |
| 818 | + * promise's species. These promises are internal WebCrypto intermediates, so |
| 819 | + * make that lookup stay on the promise itself instead of user-mutated state. |
| 820 | + * @template T |
| 821 | + * @template [TResult1=T] |
| 822 | + * @template [TResult2=never] |
| 823 | + * @param {Promise<T>} promise |
| 824 | + * @param {((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined} [onFulfilled] |
| 825 | + * @param {((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined} [onRejected] |
| 826 | + * @returns {Promise<TResult1 | TResult2>} |
| 827 | + */ |
780 | 828 | function jobPromiseThen(promise, onFulfilled, onRejected) { |
781 | 829 | const { |
782 | 830 | promise: resultPromise, |
|