File tree Expand file tree Collapse file tree 2 files changed +39
-4
lines changed
Expand file tree Collapse file tree 2 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -565,10 +565,13 @@ function normalizeAlgorithm(algorithm, op) {
565565 return { name : algName } ;
566566
567567 // 6.
568- const normalizedAlgorithm = webidl . converters [ desiredType ] ( algorithm , {
569- prefix : 'Failed to normalize algorithm' ,
570- context : 'passed algorithm' ,
571- } ) ;
568+ const normalizedAlgorithm = webidl . converters [ desiredType ] (
569+ { __proto__ : algorithm , name : algName } ,
570+ {
571+ prefix : 'Failed to normalize algorithm' ,
572+ context : 'passed algorithm' ,
573+ } ,
574+ ) ;
572575 // 7.
573576 normalizedAlgorithm . name = algName ;
574577
Original file line number Diff line number Diff line change @@ -17,3 +17,35 @@ const {
1717 assert . strictEqual ( normalizeAlgorithm ( algorithm , 'sign' ) !== algorithm , true ) ;
1818 assert . deepStrictEqual ( algorithm , { name : 'ECDSA' , hash : 'SHA-256' } ) ;
1919}
20+
21+ // The algorithm name getter should only be invoked once during
22+ // normalizeAlgorithm, including for algorithms with a non-null desiredType
23+ // where step 6 runs the specialized dictionary converter.
24+ // Refs: https://github.com/web-platform-tests/wpt/pull/57614#pullrequestreview-3808145365
25+ {
26+ let nameReadCount = 0 ;
27+ const algorithm = {
28+ get name ( ) {
29+ nameReadCount ++ ;
30+ return 'AES-GCM' ;
31+ } ,
32+ iv : new Uint8Array ( 12 ) ,
33+ } ;
34+ const normalized = normalizeAlgorithm ( algorithm , 'encrypt' ) ;
35+ assert . strictEqual ( normalized . name , 'AES-GCM' ) ;
36+ assert . strictEqual ( nameReadCount , 1 ) ;
37+ }
38+
39+ {
40+ let nameReadCount = 0 ;
41+ const algorithm = {
42+ get name ( ) {
43+ nameReadCount ++ ;
44+ return 'ECDSA' ;
45+ } ,
46+ hash : 'SHA-256' ,
47+ } ;
48+ const normalized = normalizeAlgorithm ( algorithm , 'sign' ) ;
49+ assert . strictEqual ( normalized . name , 'ECDSA' ) ;
50+ assert . strictEqual ( nameReadCount , 1 ) ;
51+ }
You can’t perform that action at this time.
0 commit comments