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

add index to sequence converter errors #3178

Merged
Merged
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
3 changes: 2 additions & 1 deletion lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ webidl.sequenceConverter = function (converter) {
/** @type {Generator} */
const method = typeof Iterable === 'function' ? Iterable() : V?.[Symbol.iterator]?.()
const seq = []
let index = 0

// 3. If method is undefined, throw a TypeError.
if (
Expand All @@ -270,7 +271,7 @@ webidl.sequenceConverter = function (converter) {
break
}

seq.push(converter(value, prefix, argument))
seq.push(converter(value, prefix, `${argument}[${index++}]`))
}

return seq
Expand Down
4 changes: 2 additions & 2 deletions test/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('Headers initialization', async (t) => {
throws(() => new Headers(['undici', 'fetch', 'fetch']), TypeError)
throws(
() => new Headers([0, 1, 2]),
TypeError('Headers contructor: init (0) is not iterable.')
TypeError('Headers contructor: init[0] (0) is not iterable.')
)
})

Expand All @@ -42,7 +42,7 @@ test('Headers initialization', async (t) => {
const init = ['undici', 'fetch', 'fetch', 'undici']
throws(
() => new Headers(init),
TypeError('Headers contructor: init ("undici") is not iterable.')
TypeError('Headers contructor: init[0] ("undici") is not iterable.')
)
})
})
Expand Down
16 changes: 16 additions & 0 deletions test/webidl/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@ describe('dictionary converters', () => {
)
})
})

describe('sequence converters', () => {
test('retains index', () => {
const { port1 } = new MessageChannel()

assert.throws(
() => new MessageEvent('type', { ports: [{}] }),
new TypeError('MessageEvent constructor: Expected eventInitDict.ports[0] ("{}") to be an instance of MessagePort.')
)

assert.throws(
() => new MessageEvent('type', { ports: [port1, {}] }),
new TypeError('MessageEvent constructor: Expected eventInitDict.ports[1] ("{}") to be an instance of MessagePort.')
)
})
})
4 changes: 2 additions & 2 deletions test/websocket/messageevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ test('test/parallel/test-worker-message-port.js', () => {
})
assert.throws(() => new MessageEvent('message', { ports: [null] }), {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict.ports ("null") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.ports[0] ("null") to be an instance of MessagePort.'
})
assert.throws(() =>
new MessageEvent('message', { ports: [{}] })
, {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict.ports ("{}") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.ports[0] ("{}") to be an instance of MessagePort.'
})

assert(new MessageEvent('message') instanceof Event)
Expand Down
Loading