@@ -668,9 +668,19 @@ const validateByteSource = hideStackFrames((val, name) => {
668668 val ) ;
669669} ) ;
670670
671- // CryptoJob constructors can synchronously throw while running their native
672- // AdditionalConfig hook. WebCrypto needs those operation-specific setup
673- // failures to reject with an OperationError.
671+ /**
672+ * @template T
673+ * @typedef {{ run(): Promise<T> } } WebCryptoJob
674+ */
675+
676+ /**
677+ * CryptoJob constructors can synchronously throw while running their native
678+ * AdditionalConfig hook. WebCrypto needs those operation-specific setup
679+ * failures to reject with an OperationError.
680+ * @template T
681+ * @param {() => WebCryptoJob<T> } getJob
682+ * @returns {Promise<T> }
683+ */
674684function jobPromise ( getJob ) {
675685 try {
676686 return getJob ( ) . run ( ) ;
@@ -681,10 +691,14 @@ function jobPromise(getJob) {
681691 }
682692}
683693
684- // Temporarily shadow inherited then accessors on WebCrypto result objects.
685- // Promise resolution reads "then" synchronously for thenable assimilation.
686- // Returning an own undefined data property keeps that lookup from reaching
687- // user-mutated prototypes.
694+ /**
695+ * Temporarily shadow inherited then accessors on WebCrypto result objects.
696+ * Promise resolution reads "then" synchronously for thenable assimilation.
697+ * Returning an own undefined data property keeps that lookup from reaching
698+ * user-mutated prototypes.
699+ * @param {unknown } value
700+ * @returns {boolean }
701+ */
688702function prepareWebCryptoResult ( value ) {
689703 if ( ( value === null || typeof value !== 'object' ) &&
690704 typeof value !== 'function' ) {
@@ -696,12 +710,27 @@ function prepareWebCryptoResult(value) {
696710 return true ;
697711}
698712
699- // Remove the temporary then property installed by prepareWebCryptoResult().
713+ /**
714+ * Remove the temporary then property installed by prepareWebCryptoResult().
715+ * @param {{ then?: unknown } } value
716+ * @returns {void }
717+ */
700718function cleanupWebCryptoResult ( value ) {
701719 delete value . then ;
702720}
703721
704- // Resolve a WebCrypto promise while inherited then accessors are shadowed.
722+ /**
723+ * @template T
724+ * @typedef {(value: T | PromiseLike<T>) => void } WebCryptoResolve
725+ */
726+
727+ /**
728+ * Resolve a WebCrypto promise while inherited then accessors are shadowed.
729+ * @template T
730+ * @param {WebCryptoResolve<T> } resolve
731+ * @param {T | PromiseLike<T> } value
732+ * @returns {void }
733+ */
705734function resolveWebCryptoResult ( resolve , value ) {
706735 const shouldCleanupResult = prepareWebCryptoResult ( value ) ;
707736 try {
@@ -712,7 +741,17 @@ function resolveWebCryptoResult(resolve, value) {
712741 }
713742}
714743
715- // Run a WebCrypto promise reaction and settle the outer promise.
744+ /**
745+ * Run a WebCrypto promise reaction and settle the outer promise.
746+ * @template T
747+ * @template TResult
748+ * @param {((value: T) => TResult | PromiseLike<TResult>) | undefined } handler
749+ * @param {WebCryptoResolve<T | TResult> } resolve
750+ * @param {(reason?: unknown) => void } reject
751+ * @param {T } value
752+ * @param {boolean } isRejected
753+ * @returns {void }
754+ */
716755function settleJobPromise ( handler , resolve , reject , value , isRejected ) {
717756 try {
718757 if ( typeof handler === 'function' ) {
@@ -727,9 +766,18 @@ function settleJobPromise(handler, resolve, reject, value, isRejected) {
727766 }
728767}
729768
730- // Promise.prototype.then gets promise.constructor to determine the result
731- // promise's species. These promises are internal WebCrypto intermediates, so
732- // make that lookup stay on the promise itself instead of user-mutated state.
769+ /**
770+ * Promise.prototype.then gets promise.constructor to determine the result
771+ * promise's species. These promises are internal WebCrypto intermediates, so
772+ * make that lookup stay on the promise itself instead of user-mutated state.
773+ * @template T
774+ * @template [TResult1=T]
775+ * @template [TResult2=never]
776+ * @param {Promise<T> } promise
777+ * @param {((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined } [onFulfilled]
778+ * @param {((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null | undefined } [onRejected]
779+ * @returns {Promise<TResult1 | TResult2> }
780+ */
733781function jobPromiseThen ( promise , onFulfilled , onRejected ) {
734782 const {
735783 promise : resultPromise ,
0 commit comments