* Creates a converter for a Web IDL enum type. * @see https://webidl.spec.whatwg.org/#es-enumeration * @param {string} name Enum identifier. * @param {string[]} values Enum values. * @returns {Converter}
(name, values)
| 627 | * @returns {Converter} |
| 628 | */ |
| 629 | function createEnumConverter(name, values) { |
| 630 | const E = new SafeSet(new SafeArrayIterator(values)); |
| 631 | |
| 632 | return function(V, options = kEmptyObject) { |
| 633 | // Web IDL enumeration step 1: convert V with ToString. |
| 634 | const S = toString(V, options); |
| 635 | |
| 636 | // Step 2: throw unless S is one of the enumeration values. |
| 637 | if (!E.has(S)) { |
| 638 | throw makeException( |
| 639 | `'${S}' is not a valid enum value of type ${name}.`, |
| 640 | makeOptions(options, options.context, 'ERR_INVALID_ARG_VALUE')); |
| 641 | } |
| 642 | |
| 643 | // Step 3: return the matching enumeration value. |
| 644 | return S; |
| 645 | }; |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * Returns the context used when converting a dictionary member. |
no test coverage detected
searching dependent graphs…