diff --git a/lib/web/fetch/webidl.js b/lib/web/fetch/webidl.js index 96ec7767a1a..13cafae6f1b 100644 --- a/lib/web/fetch/webidl.js +++ b/lib/web/fetch/webidl.js @@ -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 ( @@ -270,7 +271,7 @@ webidl.sequenceConverter = function (converter) { break } - seq.push(converter(value, prefix, argument)) + seq.push(converter(value, prefix, `${argument}[${index++}]`)) } return seq diff --git a/test/fetch/headers.js b/test/fetch/headers.js index b5574ac03df..8536dea7175 100644 --- a/test/fetch/headers.js +++ b/test/fetch/headers.js @@ -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.') ) }) @@ -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.') ) }) }) diff --git a/test/webidl/errors.js b/test/webidl/errors.js index 20a73a765a3..c5406c35325 100644 --- a/test/webidl/errors.js +++ b/test/webidl/errors.js @@ -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.') + ) + }) +}) diff --git a/test/websocket/messageevent.js b/test/websocket/messageevent.js index ae8c2227336..36cc5971e6d 100644 --- a/test/websocket/messageevent.js +++ b/test/websocket/messageevent.js @@ -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)