From 840da5ac1f5ad82bc19909f7702eaba6f1b635af Mon Sep 17 00:00:00 2001 From: Matthew Aitken Date: Thu, 18 Aug 2022 14:12:22 -0400 Subject: [PATCH 1/2] fix: allow third party AbortControllers --- lib/fetch/request.js | 11 ++++++++++- test/fetch/request.js | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/fetch/request.js b/lib/fetch/request.js index 06c2374135d..08f9fc6a752 100644 --- a/lib/fetch/request.js +++ b/lib/fetch/request.js @@ -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([ { @@ -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', diff --git a/test/fetch/request.js b/test/fetch/request.js index 216d7e03bbb..407effd286b 100644 --- a/test/fetch/request.js +++ b/test/fetch/request.js @@ -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 }) @@ -421,3 +422,15 @@ test('invalid RequestInit values', (t) => { t.end() }) + +test('RequestInit.signal option', async (t) => { + t.throws(() => { + new Request('http://asd', { + signal: true + }) + }, TypeError) + + await t.rejects(fetch('http://asd', { + signal: false + }), TypeError) +}) \ No newline at end of file From 5ea95f4493fe167b2f04b57ef80f935dba7b81b2 Mon Sep 17 00:00:00 2001 From: Matthew Aitken Date: Thu, 18 Aug 2022 14:23:01 -0400 Subject: [PATCH 2/2] fix: lint --- test/fetch/request.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/fetch/request.js b/test/fetch/request.js index 407effd286b..a76b19ed30f 100644 --- a/test/fetch/request.js +++ b/test/fetch/request.js @@ -425,6 +425,7 @@ test('invalid RequestInit values', (t) => { test('RequestInit.signal option', async (t) => { t.throws(() => { + // eslint-disable-next-line no-new new Request('http://asd', { signal: true }) @@ -433,4 +434,4 @@ test('RequestInit.signal option', async (t) => { await t.rejects(fetch('http://asd', { signal: false }), TypeError) -}) \ No newline at end of file +})