| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3d0f97e commit bdfbdda
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -577,10 +577,13 @@ function normalizeAlgorithm(algorithm, op) { | |||
| 577 | 577 | return { name: algName }; | |
| 578 | 578 | ||
| 579 | 579 | // 6. | |
| 580 | - const normalizedAlgorithm = webidl.converters[desiredType](algorithm, { | ||
| 581 | - prefix: 'Failed to normalize algorithm', | ||
| 582 | - context: 'passed algorithm', | ||
| 583 | - }); | ||
| 580 | + const normalizedAlgorithm = webidl.converters[desiredType]( | ||
| 581 | + { __proto__: algorithm, name: algName }, | ||
| 582 | + { | ||
| 583 | + prefix: 'Failed to normalize algorithm', | ||
| 584 | + context: 'passed algorithm', | ||
| 585 | + }, | ||
| 586 | + ); | ||
| 584 | 587 | // 7. | |
| 585 | 588 | normalizedAlgorithm.name = algName; | |
| 586 | 589 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,3 +17,35 @@ const { | |||
| 17 | 17 | assert.strictEqual(normalizeAlgorithm(algorithm, 'sign') !== algorithm, true); | |
| 18 | 18 | assert.deepStrictEqual(algorithm, { name: 'ECDSA', hash: 'SHA-256' }); | |
| 19 | 19 | } | |
| 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 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments