@@ -56,7 +56,7 @@ const {
5656} = require ( 'internal/util/types' ) ;
5757
5858const {
59- JSTransferable ,
59+ makeTransferable ,
6060 kClone,
6161 kDeserialize,
6262} = require ( 'internal/worker/js_transferable' ) ;
@@ -630,14 +630,12 @@ function isKeyObject(obj) {
630630}
631631
632632// Our implementation of CryptoKey is a simple wrapper around a KeyObject
633- // that adapts it to the standard interface. This implementation also
634- // extends the JSTransferable class, allowing the CryptoKey to be cloned
635- // to Workers.
633+ // that adapts it to the standard interface.
636634// TODO(@jasnell): Embedder environments like electron may have issues
637635// here similar to other things like URL. A chromium provided CryptoKey
638636// will not be recognized as a Node.js CryptoKey, and vice versa. It
639637// would be fantastic if we could find a way of making those interop.
640- class CryptoKey extends JSTransferable {
638+ class CryptoKey {
641639 constructor ( ) {
642640 throw new ERR_ILLEGAL_CONSTRUCTOR ( ) ;
643641 }
@@ -682,30 +680,6 @@ class CryptoKey extends JSTransferable {
682680 throw new ERR_INVALID_THIS ( 'CryptoKey' ) ;
683681 return ArrayFrom ( this [ kKeyUsages ] ) ;
684682 }
685-
686- [ kClone ] ( ) {
687- const keyObject = this [ kKeyObject ] ;
688- const algorithm = this . algorithm ;
689- const extractable = this . extractable ;
690- const usages = this . usages ;
691-
692- return {
693- data : {
694- keyObject,
695- algorithm,
696- usages,
697- extractable,
698- } ,
699- deserializeInfo : 'internal/crypto/keys:InternalCryptoKey'
700- } ;
701- }
702-
703- [ kDeserialize ] ( { keyObject, algorithm, usages, extractable } ) {
704- this [ kKeyObject ] = keyObject ;
705- this [ kAlgorithm ] = algorithm ;
706- this [ kKeyUsages ] = usages ;
707- this [ kExtractable ] = extractable ;
708- }
709683}
710684
711685ObjectDefineProperties ( CryptoKey . prototype , {
@@ -718,23 +692,50 @@ ObjectDefineProperties(CryptoKey.prototype, {
718692// All internal code must use new InternalCryptoKey to create
719693// CryptoKey instances. The CryptoKey class is exposed to end
720694// user code but is not permitted to be constructed directly.
721- class InternalCryptoKey extends JSTransferable {
695+ // Using makeTransferable also allows the CryptoKey to be
696+ // cloned to Workers.
697+ class InternalCryptoKey {
722698 constructor (
723699 keyObject ,
724700 algorithm ,
725701 keyUsages ,
726702 extractable ) {
727- super ( ) ;
728703 // Using symbol properties here currently instead of private
729704 // properties because (for now) the performance penalty of
730705 // private fields is still too high.
731706 this [ kKeyObject ] = keyObject ;
732707 this [ kAlgorithm ] = algorithm ;
733708 this [ kExtractable ] = extractable ;
734709 this [ kKeyUsages ] = keyUsages ;
710+
711+ // eslint-disable-next-line no-constructor-return
712+ return makeTransferable ( this ) ;
735713 }
736- }
737714
715+ [ kClone ] ( ) {
716+ const keyObject = this [ kKeyObject ] ;
717+ const algorithm = this . algorithm ;
718+ const extractable = this . extractable ;
719+ const usages = this . usages ;
720+
721+ return {
722+ data : {
723+ keyObject,
724+ algorithm,
725+ usages,
726+ extractable,
727+ } ,
728+ deserializeInfo : 'internal/crypto/keys:InternalCryptoKey'
729+ } ;
730+ }
731+
732+ [ kDeserialize ] ( { keyObject, algorithm, usages, extractable } ) {
733+ this [ kKeyObject ] = keyObject ;
734+ this [ kAlgorithm ] = algorithm ;
735+ this [ kKeyUsages ] = usages ;
736+ this [ kExtractable ] = extractable ;
737+ }
738+ }
738739InternalCryptoKey . prototype . constructor = CryptoKey ;
739740ObjectSetPrototypeOf ( InternalCryptoKey . prototype , CryptoKey . prototype ) ;
740741
0 commit comments