Skip to content

Commit

Permalink
fix: allow third party AbortControllers (#1609)
Browse files Browse the repository at this point in the history
* fix: allow third party AbortControllers

* fix: lint

Co-authored-by: Matthew Aitken <matthew@Matthews-MacBook-Air.local>
  • Loading branch information
KhafraDev and Matthew Aitken committed Aug 19, 2022
1 parent 8549a94 commit 417e7ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/fetch/request.js
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
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)
})

0 comments on commit 417e7ab

Please sign in to comment.