@@ -723,9 +723,19 @@ const validateByteSource = hideStackFrames((val, name) => {
723723 val ) ;
724724} ) ;
725725
726- // CryptoJob constructors can synchronously throw while running their native
727- // AdditionalConfig hook. WebCrypto needs those operation-specific setup
728- // failures to reject with an OperationError.
726+ /**
727+ * @template T
728+ * @typedef {{ run(): Promise<T> } } WebCryptoJob
729+ */
730+
731+ /**
732+ * CryptoJob constructors can synchronously throw while running their native
733+ * AdditionalConfig hook. WebCrypto needs those operation-specific setup
734+ * failures to reject with an OperationError.
735+ * @template T
736+ * @param {() => WebCryptoJob<T> } getJob
737+ * @returns {Promise<T> }
738+ */
729739function jobPromise ( getJob ) {
730740 try {
731741 return getJob ( ) . run ( ) ;
@@ -736,10 +746,14 @@ function jobPromise(getJob) {
736746 }
737747}
738748
739- // Temporarily shadow inherited then accessors on WebCrypto result objects.
740- // Promise resolution reads "then" synchronously for thenable assimilation.
741- // Returning an own undefined data property keeps that lookup from reaching
742- // user-mutated prototypes.
749+ /**
750+ * Temporarily shadow inherited then accessors on WebCrypto result objects.
751+ * Promise resolution reads "then" synchronously for thenable assimilation.
752+ * Returning an own undefined data property keeps that lookup from reaching
753+ * user-mutated prototypes.
754+ * @param {unknown } value
755+ * @returns {boolean }
756+ */
743757function prepareWebCryptoResult ( value ) {
744758 if ( ( value === null || typeof value !== 'object' ) &&
745759 typeof value !== 'function' ) {
@@ -751,12 +765,27 @@ function prepareWebCryptoResult(value) {
751765 return true ;
752766}
753767
754- // Remove the temporary then property installed by prepareWebCryptoResult().
768+ /**
769+ * Remove the temporary then property installed by prepareWebCryptoResult().
770+ * @param {{ then?: unknown } } value
771+ * @returns {void }
772+ */
755773function cleanupWebCryptoResult ( value ) {
756774 delete value . then ;
757775}
758776
759- // Resolve a WebCrypto promise while inherited then accessors are shadowed.
777+ /**
778+ * @template T
779+ * @typedef {(value: T | PromiseLike<T>) => void } WebCryptoResolve
780+ */
781+
782+ /**
783+ * Resolve a WebCrypto promise while inherited then accessors are shadowed.
784+ * @template T
785+ * @param {WebCryptoResolve<T> } resolve
786+ * @param {T | PromiseLike<T> } value
787+ * @returns {void }
788+ */
760789function resolveWebCryptoResult ( resolve , value ) {
761790 const shouldCleanupResult = prepareWebCryptoResult ( value ) ;
762791 try {
@@ -767,7 +796,17 @@ function resolveWebCryptoResult(resolve, value) {
767796 }
768797}
769798
770- // Run a WebCrypto promise reaction and settle the outer promise.
799+ /**
800+ * Run a WebCrypto promise reaction and settle the outer promise.
801+ * @template T
802+ * @template TResult
803+ * @param {((value: T) => TResult | PromiseLike<TResult>) | undefined } handler
804+ * @param {WebCryptoResolve<T | TResult> } resolve
805+ * @param {(reason?: unknown) => void } reject
806+ * @param {T } value
807+ * @param {boolean } isRejected
808+ * @returns {void }
809+ */
771810function settleJobPromise ( handler , resolve , reject , value , isRejected ) {
772811 try {
773812 if ( typeof handler === 'function' ) {
@@ -782,9 +821,18 @@ function settleJobPromise(handler, resolve, reject, value, isRejected) {
782821 }
783822}
784823
785- // Promise.prototype.then gets promise.constructor to determine the result
786- // promise's species. These promises are internal WebCrypto intermediates, so
787- // make that lookup stay on the promise itself instead of user-mutated state.
824+ /**
825+ * Promise.prototype.then gets promise.constructor to determine the result
826+ * promise's species. These promises are internal WebCrypto intermediates, so
827+ * make that lookup stay on the promise itself instead of user-mutated state.
828+ * @template T
829+ * @template [TResult1=T]
830+ * @template [TResult2=never]
831+ * @param {Promise<T> } promise
832+ * @param {((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined } [onFulfilled]
833+ * @param {((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined } [onRejected]
834+ * @returns {Promise<TResult1 | TResult2> }
835+ */
788836function jobPromiseThen ( promise , onFulfilled , onRejected ) {
789837 const {
790838 promise : resultPromise ,
0 commit comments