@@ -703,32 +703,81 @@ ObjectDefineProperties(CryptoKey.prototype, {
703703 } ,
704704} ) ;
705705
706+ /**
707+ * @param {InternalCryptoKey } key
708+ * @param {KeyObject } keyObject
709+ * @param {object } algorithm
710+ * @param {boolean } extractable
711+ * @param {Set<string> } keyUsages
712+ */
713+ function defineCryptoKeyProperties (
714+ key ,
715+ keyObject ,
716+ algorithm ,
717+ extractable ,
718+ keyUsages ,
719+ ) {
720+ // Using symbol properties here currently instead of private
721+ // properties because (for now) the performance penalty of
722+ // private fields is still too high.
723+ ObjectDefineProperties ( key , {
724+ [ kKeyObject ] : {
725+ __proto__ : null ,
726+ value : keyObject ,
727+ enumerable : false ,
728+ configurable : false ,
729+ writable : false ,
730+ } ,
731+ [ kAlgorithm ] : {
732+ __proto__ : null ,
733+ value : algorithm ,
734+ enumerable : false ,
735+ configurable : false ,
736+ writable : false ,
737+ } ,
738+ [ kExtractable ] : {
739+ __proto__ : null ,
740+ value : extractable ,
741+ enumerable : false ,
742+ configurable : false ,
743+ writable : false ,
744+ } ,
745+ [ kKeyUsages ] : {
746+ __proto__ : null ,
747+ value : keyUsages ,
748+ enumerable : false ,
749+ configurable : false ,
750+ writable : false ,
751+ } ,
752+ } ) ;
753+ }
754+
706755// All internal code must use new InternalCryptoKey to create
707756// CryptoKey instances. The CryptoKey class is exposed to end
708757// user code but is not permitted to be constructed directly.
709758// Using markTransferMode also allows the CryptoKey to be
710759// cloned to Workers.
711760class InternalCryptoKey {
712- constructor (
713- keyObject ,
714- algorithm ,
715- keyUsages ,
716- extractable ) {
761+ constructor ( keyObject , algorithm , keyUsages , extractable ) {
717762 markTransferMode ( this , true , false ) ;
718- // Using symbol properties here currently instead of private
719- // properties because (for now) the performance penalty of
720- // private fields is still too high.
721- this [ kKeyObject ] = keyObject ;
722- this [ kAlgorithm ] = algorithm ;
723- this [ kExtractable ] = extractable ;
724- this [ kKeyUsages ] = keyUsages ;
763+ // When constructed during transfer the properties get assigned
764+ // in the kDeserialize call.
765+ if ( keyObject ) {
766+ defineCryptoKeyProperties (
767+ this ,
768+ keyObject ,
769+ algorithm ,
770+ extractable ,
771+ keyUsages ,
772+ ) ;
773+ }
725774 }
726775
727776 [ kClone ] ( ) {
728777 const keyObject = this [ kKeyObject ] ;
729- const algorithm = this . algorithm ;
730- const extractable = this . extractable ;
731- const usages = this . usages ;
778+ const algorithm = this [ kAlgorithm ] ;
779+ const extractable = this [ kExtractable ] ;
780+ const usages = this [ kKeyUsages ] ;
732781
733782 return {
734783 data : {
@@ -742,10 +791,7 @@ class InternalCryptoKey {
742791 }
743792
744793 [ kDeserialize ] ( { keyObject, algorithm, usages, extractable } ) {
745- this [ kKeyObject ] = keyObject ;
746- this [ kAlgorithm ] = algorithm ;
747- this [ kKeyUsages ] = usages ;
748- this [ kExtractable ] = extractable ;
794+ defineCryptoKeyProperties ( this , keyObject , algorithm , extractable , usages ) ;
749795 }
750796}
751797InternalCryptoKey . prototype . constructor = CryptoKey ;
0 commit comments