File tree 2 files changed +33
-11
lines changed
2 files changed +33
-11
lines changed Original file line number Diff line number Diff line change @@ -200,11 +200,22 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
200
200
*/
201
201
abort ( ) : void {
202
202
if (
203
- this . readyState === XMLHttpRequest . HEADERS_RECEIVED ||
204
- this . readyState === XMLHttpRequest . LOADING
203
+ this . readyState === XMLHttpRequest . UNSENT ||
204
+ this . readyState === XMLHttpRequest . OPENED ||
205
+ this . readyState === XMLHttpRequest . DONE ||
206
+ ! this . #client
205
207
) {
206
- this . #client ?. abort ( ) ;
208
+ return ;
207
209
}
210
+
211
+ this . #client. destroy ( ) ;
212
+
213
+ this . #readyState = XMLHttpRequest . UNSENT ;
214
+
215
+ this . dispatchEvent ( new ProgressEvent ( 'abort' ) ) ;
216
+ this . upload . dispatchEvent ( new ProgressEvent ( 'abort' ) ) ;
217
+
218
+ this . #client = null ;
208
219
}
209
220
210
221
/**
@@ -314,14 +325,6 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
314
325
protocol
315
326
} ) ;
316
327
317
- this . #client. addListener ( 'abort' , ( ) => {
318
- this . dispatchEvent ( new ProgressEvent ( 'abort' ) ) ;
319
- this . upload . dispatchEvent ( new ProgressEvent ( 'abort' ) ) ;
320
-
321
- this . #client = null ;
322
- this . #readyState = XMLHttpRequest . UNSENT ;
323
- } ) ;
324
-
325
328
this . #client. addListener ( 'error' , ( ) => {
326
329
this . dispatchEvent ( new ProgressEvent ( 'error' ) ) ;
327
330
this . upload . dispatchEvent ( new ProgressEvent ( 'error' ) ) ;
Original file line number Diff line number Diff line change @@ -65,6 +65,25 @@ describe('XMLHttpRequest', () => {
65
65
baseURL = null ;
66
66
} ) ;
67
67
68
+ describe ( 'abort()' , ( ) => {
69
+ it ( 'basic use case' , ( done ) => {
70
+ const client = new XMLHttpRequest ( ) ;
71
+
72
+ client . addEventListener ( 'abort' , ( event ) => {
73
+ expect ( event . type ) . toBe ( 'abort' ) ;
74
+ expect ( client . readyState ) . toBe ( XMLHttpRequest . UNSENT ) ;
75
+
76
+ done ( ) ;
77
+ } ) ;
78
+ client . addEventListener ( 'loadstart' , ( ) => {
79
+ client . abort ( ) ;
80
+ } ) ;
81
+
82
+ client . open ( 'GET' , `${ baseURL } /?body=abort` ) ;
83
+ client . send ( ) ;
84
+ } ) ;
85
+ } ) ;
86
+
68
87
describe ( "addEventListener(event: 'error')" , ( ) => {
69
88
it ( 'basic use case' , ( done ) => {
70
89
const client = new XMLHttpRequest ( ) ;
You can’t perform that action at this time.
0 commit comments