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

preserve dictionary key name in webidl errors #3176

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/web/fetch/webidl.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ webidl.sequenceConverter = function (converter) {
if (webidl.util.Type(V) !== 'Object') {
throw webidl.errors.exception({
header: prefix,
message: `${argument} (${webidl.util.Stringify(V)}) is not an Object.`
message: `${argument} (${webidl.util.Stringify(V)}) is not iterable.`
})
}

Expand Down Expand Up @@ -390,7 +390,7 @@ webidl.dictionaryConverter = function (converters) {
// When this happens, do not perform a conversion,
// and do not assign the key a value.
if (required || hasDefault || value !== undefined) {
value = converter(value, prefix, argument)
value = converter(value, prefix, `${argument}.${key}`)

if (
options.allowedValues &&
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 an Object.')
TypeError('Headers contructor: init (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 an Object.')
TypeError('Headers contructor: init ("undici") is not iterable.')
)
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/types/dispatcher.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IncomingHttpHeaders } from 'http'
import { Duplex, Readable, Writable } from 'stream'
import { expectAssignable, expectType } from 'tsd'
import { Dispatcher } from '../..'
import { Dispatcher, Headers } from '../..'
import { URL } from 'url'
import { Blob } from 'buffer'

Expand Down
13 changes: 11 additions & 2 deletions test/webidl/errors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { test } = require('node:test')
const { test, describe } = require('node:test')
const assert = require('node:assert')
const { Headers } = require('../..')
const { Headers, MessageEvent } = require('../..')

test('ByteString', (t) => {
const name = Symbol('')
Expand All @@ -21,3 +21,12 @@ test('ByteString', (t) => {
)
}
})

describe('dictionary converters', () => {
test('error message retains property name', () => {
assert.throws(
() => new MessageEvent('message', { source: 1 }),
new TypeError('MessageEvent constructor: Expected eventInitDict.source ("1") to be an instance of MessagePort.')
)
})
})
10 changes: 5 additions & 5 deletions test/websocket/messageevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ test('test/parallel/test-worker-message-port.js', () => {

assert.throws(() => new MessageEvent('message', { source: 1 }), {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict ("1") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.source ("1") to be an instance of MessagePort.'
})
assert.throws(() => new MessageEvent('message', { source: {} }), {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict ("{}") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.source ("{}") to be an instance of MessagePort.'
})
assert.throws(() => new MessageEvent('message', { ports: 0 }), {
constructor: TypeError,
message: 'MessageEvent constructor: eventInitDict (0) is not an Object.'
message: 'MessageEvent constructor: eventInitDict.ports (0) is not iterable.'
})
assert.throws(() => new MessageEvent('message', { ports: [null] }), {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict ("null") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.ports ("null") to be an instance of MessagePort.'
})
assert.throws(() =>
new MessageEvent('message', { ports: [{}] })
, {
constructor: TypeError,
message: 'MessageEvent constructor: Expected eventInitDict ("{}") to be an instance of MessagePort.'
message: 'MessageEvent constructor: Expected eventInitDict.ports ("{}") to be an instance of MessagePort.'
})

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