Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/internal/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,12 @@ function createSequenceConverter(converter) {

// Step 4 and create-sequence step 1: get the iterator record.
const iterator = FunctionPrototypeCall(method, V);
const nextMethod = iterator?.next;
if (type(iterator) !== 'Object') {
throw makeException(
'cannot be converted to sequence.',
options);
}
const nextMethod = iterator.next;
if (typeof nextMethod !== 'function') {
throw makeException(
'cannot be converted to sequence.',
Expand Down
33 changes: 33 additions & 0 deletions test/parallel/test-internal-webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,39 @@ assert.throws(() => webidl.requiredArguments(1, 2, opts), {
}), []);
}

for (const [prototype, value] of [
[Number.prototype, 1],
[String.prototype, 'iterator'],
[Boolean.prototype, true],
[BigInt.prototype, 1n],
[Symbol.prototype, Symbol()],
]) {
let nextReads = 0;
Object.defineProperty(prototype, 'next', {
configurable: true,
get() {
nextReads++;
return () => ({ done: true });
},
});
try {
const iterable = { [Symbol.iterator]: () => value };
assertInvalidArgType(() => converters['sequence<DOMString>'](iterable));
assertInvalidArgType(() => structuredClone(null, { transfer: iterable }));
assert.strictEqual(nextReads, 0);
} finally {
delete prototype.next;
}
}

{
function iterator() {}
iterator.next = () => ({ done: true });
assert.deepStrictEqual(converters['sequence<DOMString>']({
[Symbol.iterator]: () => iterator,
}), []);
}

{
class Example {}
const converter = webidl.createInterfaceConverter(
Expand Down
Loading