MCPcopy Index your code
hub / github.com/nodejs/node / createEnumConverter

Function createEnumConverter

lib/internal/webidl.js:629–646  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

627 * @returns {Converter}
628 */
629function 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.

Callers 3

locks.jsFile · 0.85
webidl.jsFile · 0.85
compression.jsFile · 0.85

Calls 4

makeExceptionFunction · 0.85
makeOptionsFunction · 0.85
toStringFunction · 0.70
hasMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…