Support instances of `EventTarget` as a `signal` (#1001)
Co-authored-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
c86886249a
commit
1f4f85e1bb
|
@ -82,9 +82,8 @@ export default class Request extends Body {
|
|||
signal = init.signal;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-eq-null, eqeqeq
|
||||
if (signal != null && !isAbortSignal(signal)) {
|
||||
throw new TypeError('Expected signal to be an instanceof AbortSignal');
|
||||
throw new TypeError('Expected signal to be an instanceof AbortSignal or EventTarget');
|
||||
}
|
||||
|
||||
this[INTERNALS] = {
|
||||
|
|
|
@ -74,8 +74,10 @@ export function isFormData(object) {
|
|||
*/
|
||||
export const isAbortSignal = object => {
|
||||
return (
|
||||
typeof object === 'object' &&
|
||||
object[NAME] === 'AbortSignal'
|
||||
typeof object === 'object' && (
|
||||
object[NAME] === 'AbortSignal' ||
|
||||
object[NAME] === 'EventTarget'
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1021,7 +1021,7 @@ describe('node-fetch', () => {
|
|||
return result;
|
||||
});
|
||||
|
||||
it('should throw a TypeError if a signal is not of type AbortSignal', () => {
|
||||
it('should throw a TypeError if a signal is not of type AbortSignal or EventTarget', () => {
|
||||
return Promise.all([
|
||||
expect(fetch(`${base}inspect`, {signal: {}}))
|
||||
.to.be.eventually.rejected
|
||||
|
|
Loading…
Reference in New Issue