Skip to content
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
11 changes: 10 additions & 1 deletion lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ webidl.converters.RequestInfo = function (V) {
return webidl.converters.USVString(V)
}

webidl.converters.AbortSignal = webidl.interfaceConverter(
AbortSignal
)

// https://fetch.spec.whatwg.org/#requestinit
webidl.converters.RequestInit = webidl.dictionaryConverter([
{
Expand Down Expand Up @@ -909,7 +913,12 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
},
{
key: 'signal',
converter: webidl.converters.any
converter: webidl.nullableConverter(
(signal) => webidl.converters.AbortSignal(
signal,
{ strict: false }
)
)
},
{
key: 'window',
Expand Down
16 changes: 15 additions & 1 deletion test/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
const { test } = require('tap')
const {
Request,
Headers
Headers,
fetch
} = require('../../')
const { kState } = require('../../lib/fetch/symbols.js')
const hasSignalReason = !!~process.version.localeCompare('v16.14.0', undefined, { numeric: true })
Expand Down Expand Up @@ -421,3 +422,16 @@ test('invalid RequestInit values', (t) => {

t.end()
})

test('RequestInit.signal option', async (t) => {
t.throws(() => {
// eslint-disable-next-line no-new
new Request('http://asd', {
signal: true
})
}, TypeError)

await t.rejects(fetch('http://asd', {
signal: false
}), TypeError)
})