Skip to content

Commit

Permalink
always set a signal on Request
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke authored and JakeChampion committed Aug 2, 2021
1 parent 7727e50 commit d1d09fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion fetch.js
Expand Up @@ -370,7 +370,12 @@ export function Request(input, options) {
}
this.method = normalizeMethod(options.method || this.method || 'GET')
this.mode = options.mode || this.mode || null
this.signal = options.signal || this.signal
this.signal = options.signal || this.signal || (function () {
if ('AbortController' in global) {
var ctrl = new AbortController();
return ctrl.signal;
}
}());
this.referrer = null

if ((this.method === 'GET' || this.method === 'HEAD') && body) {
Expand Down
15 changes: 14 additions & 1 deletion test/test.js
Expand Up @@ -1147,7 +1147,20 @@ exercise.forEach(function(exerciseMode) {
})

featureDependent(suite, exerciseMode !== 'native' || support.aborting, 'aborting', function() {
test('initially aborted signal', function() {
test('Request init creates an AbortSignal without option', function() {
var request = new Request('/request')
assert.ok(request.signal);
assert.equal(request.signal.aborted, false);
})

test('Request init passes AbortSignal from option', function () {
var controller = new AbortController()
var request = new Request('/request', {signal: controller.signal})
assert.ok(request.signal);
assert.deepEqual(controller.signal, request.signal);
})

test('initially aborted signal', function () {
var controller = new AbortController()
controller.abort()

Expand Down

0 comments on commit d1d09fb

Please sign in to comment.