@@ -703,34 +703,83 @@ 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 makeTransferable 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 ) {
717
- // Using symbol properties here currently instead of private
718
- // properties because (for now) the performance penalty of
719
- // private fields is still too high.
720
- this [ kKeyObject ] = keyObject ;
721
- this [ kAlgorithm ] = algorithm ;
722
- this [ kExtractable ] = extractable ;
723
- this [ kKeyUsages ] = keyUsages ;
761
+ constructor ( keyObject , algorithm , keyUsages , extractable ) {
762
+ // When constructed during transfer the properties get assigned
763
+ // in the kDeserialize call.
764
+ if ( keyObject ) {
765
+ defineCryptoKeyProperties (
766
+ this ,
767
+ keyObject ,
768
+ algorithm ,
769
+ extractable ,
770
+ keyUsages ,
771
+ ) ;
772
+ }
724
773
725
774
// eslint-disable-next-line no-constructor-return
726
775
return makeTransferable ( this ) ;
727
776
}
728
777
729
778
[ kClone ] ( ) {
730
779
const keyObject = this [ kKeyObject ] ;
731
- const algorithm = this . algorithm ;
732
- const extractable = this . extractable ;
733
- const usages = this . usages ;
780
+ const algorithm = this [ kAlgorithm ] ;
781
+ const extractable = this [ kExtractable ] ;
782
+ const usages = this [ kKeyUsages ] ;
734
783
735
784
return {
736
785
data : {
@@ -744,10 +793,7 @@ class InternalCryptoKey {
744
793
}
745
794
746
795
[ kDeserialize ] ( { keyObject, algorithm, usages, extractable } ) {
747
- this [ kKeyObject ] = keyObject ;
748
- this [ kAlgorithm ] = algorithm ;
749
- this [ kKeyUsages ] = usages ;
750
- this [ kExtractable ] = extractable ;
796
+ defineCryptoKeyProperties ( this , keyObject , algorithm , extractable , usages ) ;
751
797
}
752
798
}
753
799
InternalCryptoKey . prototype . constructor = CryptoKey ;
0 commit comments