@@ -703,32 +703,81 @@ ObjectDefineProperties(CryptoKey.prototype, {
703
703
} ,
704
704
} ) ;
705
705
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
+
706
755
// All internal code must use new InternalCryptoKey to create
707
756
// CryptoKey instances. The CryptoKey class is exposed to end
708
757
// user code but is not permitted to be constructed directly.
709
758
// Using markTransferMode also allows the CryptoKey to be
710
759
// cloned to Workers.
711
760
class InternalCryptoKey {
712
- constructor (
713
- keyObject ,
714
- algorithm ,
715
- keyUsages ,
716
- extractable ) {
761
+ constructor ( keyObject , algorithm , keyUsages , extractable ) {
717
762
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
+ }
725
774
}
726
775
727
776
[ kClone ] ( ) {
728
777
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 ] ;
732
781
733
782
return {
734
783
data : {
@@ -742,10 +791,7 @@ class InternalCryptoKey {
742
791
}
743
792
744
793
[ 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 ) ;
749
795
}
750
796
}
751
797
InternalCryptoKey . prototype . constructor = CryptoKey ;
0 commit comments