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

Function createSequenceConverter

lib/internal/webidl.js:773–824  ·  view source on GitHub ↗

* Creates a converter for a Web IDL sequence type. * @see https://webidl.spec.whatwg.org/#es-sequence * @param {Converter} converter Element converter. * @returns {Converter}

(converter)

Source from the content-addressed store, hash-verified

771 * @returns {Converter}
772 */
773function createSequenceConverter(converter) {
774 return function(V, options = kEmptyObject) {
775 // Web IDL sequence conversion step 1: require an ECMA-262 Object.
776 if (type(V) !== 'Object') {
777 throw makeException(
778 'cannot be converted to sequence.',
779 options);
780 }
781
782 // Step 2: GetMethod(V, %Symbol.iterator%).
783 const method = V[SymbolIterator];
784 // Step 3: throw if the iterator method is undefined, null, or not callable.
785 if (typeof method !== 'function') {
786 throw makeException(
787 'cannot be converted to sequence.',
788 options);
789 }
790
791 // Step 4 and create-sequence step 1: get the iterator record.
792 const iterator = FunctionPrototypeCall(method, V);
793 const nextMethod = iterator?.next;
794 if (typeof nextMethod !== 'function') {
795 throw makeException(
796 'cannot be converted to sequence.',
797 options);
798 }
799
800 // Create-sequence step 2: initialize i to 0.
801 const idlSequence = [];
802 while (true) {
803 // Step 3.1: IteratorStepValue(iteratorRecord).
804 const next = FunctionPrototypeCall(nextMethod, iterator);
805 if (type(next) !== 'Object') {
806 throw makeException(
807 'cannot be converted to sequence.',
808 options);
809 }
810 // Step 3.2: IteratorComplete applies ToBoolean(done).
811 if (next.done) {
812 break;
813 }
814 // Step 3.3: convert next to an IDL value of type T.
815 const idlValue = converter(
816 next.value,
817 makeOptions(options, sequenceElementContext(idlSequence.length, options)),
818 );
819 // Step 3.4: store the value and advance i.
820 ArrayPrototypePush(idlSequence, idlValue);
821 }
822 return idlSequence;
823 };
824}
825
826/**
827 * Creates a converter for a Web IDL interface type.

Callers 4

webidl.jsFile · 0.85
blob.jsFile · 0.85
webidl.jsFile · 0.85

Calls 5

makeExceptionFunction · 0.85
converterFunction · 0.85
makeOptionsFunction · 0.85
sequenceElementContextFunction · 0.85
typeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…