* @returns {void}
()
| 7440 | * @returns {void} |
| 7441 | */ |
| 7442 | function parseDescriptors() { |
| 7443 | // 9. Descriptor parser: Let error be no. |
| 7444 | let pError = false; |
| 7445 | |
| 7446 | // 10. Let width be absent. |
| 7447 | // 11. Let density be absent. |
| 7448 | // 12. Let future-compat-h be absent. (We're implementing it now as h) |
| 7449 | /** @type {number | undefined} */ |
| 7450 | let width; |
| 7451 | /** @type {number | undefined} */ |
| 7452 | let density; |
| 7453 | /** @type {number | undefined} */ |
| 7454 | let height; |
| 7455 | /** @type {string | undefined} */ |
| 7456 | let desc; |
| 7457 | |
| 7458 | // 13. For each descriptor in descriptors, run the appropriate set of steps |
| 7459 | // from the following list: |
| 7460 | for (let i = 0; i < descriptors.length; i++) { |
| 7461 | desc = descriptors[i]; |
| 7462 | |
| 7463 | const lastChar = desc[desc.length - 1].charCodeAt(0); |
| 7464 | const value = desc.slice(0, Math.max(0, desc.length - 1)); |
| 7465 | |
| 7466 | // If the descriptor consists of a valid non-negative integer followed by |
| 7467 | // a U+0077 LATIN SMALL LETTER W character |
| 7468 | if ( |
| 7469 | NON_NEGATIVE_INTEGER_REGEXP.test(value) && |
| 7470 | lastChar === SMALL_LETTER_W |
| 7471 | ) { |
| 7472 | // If width and density are not both absent, then let error be yes. |
| 7473 | if (width || density) { |
| 7474 | pError = true; |
| 7475 | } |
| 7476 | |
| 7477 | const intVal = Number.parseInt(value, 10); |
| 7478 | |
| 7479 | // Apply the rules for parsing non-negative integers to the descriptor. |
| 7480 | // If the result is zero, let error be yes. |
| 7481 | // Otherwise, let width be the result. |
| 7482 | if (intVal === 0) { |
| 7483 | pError = true; |
| 7484 | } else { |
| 7485 | width = intVal; |
| 7486 | } |
| 7487 | } |
| 7488 | // If the descriptor consists of a valid floating-point number followed by |
| 7489 | // a U+0078 LATIN SMALL LETTER X character |
| 7490 | else if ( |
| 7491 | FLOATING_POINT_REGEXP.test(value) && |
| 7492 | lastChar === SMALL_LETTER_X |
| 7493 | ) { |
| 7494 | // If width, density and future-compat-h are not all absent, then let error |
| 7495 | // be yes. |
| 7496 | if (width || density || height) { |
| 7497 | pError = true; |
| 7498 | } |
| 7499 |
no test coverage detected