@@ -715,9 +715,19 @@ const validateByteSource = hideStackFrames((val, name) => {
715715 val ) ;
716716} ) ;
717717
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+ */
721731function jobPromise ( getJob ) {
722732 try {
723733 return getJob ( ) . run ( ) ;
@@ -728,10 +738,14 @@ function jobPromise(getJob) {
728738 }
729739}
730740
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+ */
735749function prepareWebCryptoResult ( value ) {
736750 if ( ( value === null || typeof value !== 'object' ) &&
737751 typeof value !== 'function' ) {
@@ -743,12 +757,27 @@ function prepareWebCryptoResult(value) {
743757 return true ;
744758}
745759
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+ */
747765function cleanupWebCryptoResult ( value ) {
748766 delete value . then ;
749767}
750768
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+ */
752781function resolveWebCryptoResult ( resolve , value ) {
753782 const shouldCleanupResult = prepareWebCryptoResult ( value ) ;
754783 try {
@@ -759,7 +788,17 @@ function resolveWebCryptoResult(resolve, value) {
759788 }
760789}
761790
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+ */
763802function settleJobPromise ( handler , resolve , reject , value , isRejected ) {
764803 try {
765804 if ( typeof handler === 'function' ) {
@@ -774,9 +813,18 @@ function settleJobPromise(handler, resolve, reject, value, isRejected) {
774813 }
775814}
776815
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+ */
780828function jobPromiseThen ( promise , onFulfilled , onRejected ) {
781829 const {
782830 promise : resultPromise ,
0 commit comments