Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: always use the same prototype Iterator #2743

Merged
Prev Previous commit
Next Next commit
add test
  • Loading branch information
tsctx committed Feb 12, 2024
commit 740f1aa6565a765df9eb375c4746577316713b48
15 changes: 15 additions & 0 deletions test/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,21 @@ test('Headers as Iterable', async (t) => {

deepStrictEqual([...headers], expected)
})

await t.test('Headers iterator', (t) => {
const HeadersIteratorNext = Function.call.bind(Object.getPrototypeOf(new Headers()[Symbol.iterator]()).next)

const init = [
['a', '1'],
['b', '2']
]

const headers = new Headers(init)
const iterator = headers[Symbol.iterator]()
assert.deepStrictEqual(HeadersIteratorNext(iterator), { value: init[0], done: false })
assert.deepStrictEqual(HeadersIteratorNext(iterator), { value: init[1], done: false })
assert.deepStrictEqual(HeadersIteratorNext(iterator), { value: undefined, done: true })
})
})

test('arg validation', () => {
Expand Down