mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
lib: validate sequence iterator objects
Reject primitive iterator factory results before accessing next, as required by GetIteratorFromMethod. Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65844 Reviewed-By: Jason Zhang <xzha4350@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
This commit is contained in:
1 parent
0a9225dd16
commit
70458d593d
2 files changed
+39
-1
No files matched your search
@@ -835,7 +835,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.',
|
||||
|
||||
@@ -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 {
|
||||
#brand;
|
||||
|
||||
Reference in new issue
Block a user