Skip to content

Commit aa2df41

Browse files
authored
fix: use a right reference for hooks (#156)
1 parent cb72b67 commit aa2df41

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/patch/xmlhttprequest.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { EventEmitter } from "../misc/event-emitter";
99
import headers from "../misc/headers";
1010
import formData from "./formdata";
11+
import hooks from "../misc/hooks";
1112

1213
const nullify = res => (res === undefined ? null : res);
1314

@@ -143,11 +144,11 @@ const Xhook = function() {
143144
return;
144145
}
145146
//before emitting 4, run all 'after' hooks in sequence
146-
const hooks = xhook.listeners("after");
147+
const afterHooks = hooks.listeners("after");
147148
var process = function() {
148-
if (hooks.length > 0) {
149+
if (afterHooks.length > 0) {
149150
//execute each 'before' hook one at a time
150-
const hook = hooks.shift();
151+
const hook = afterHooks.shift();
151152
if (hook.length === 2) {
152153
hook(request, response);
153154
process();
@@ -207,7 +208,7 @@ const Xhook = function() {
207208

208209
// initialise 'withCredentials' on facade xhr in browsers with it
209210
// or if explicitly told to do so
210-
if ("withCredentials" in xhr || xhook.addWithCredentials) {
211+
if ("withCredentials" in xhr) {
211212
facade.withCredentials = false;
212213
}
213214
facade.status = 0;
@@ -295,10 +296,10 @@ const Xhook = function() {
295296
xhr.send(request.body);
296297
};
297298

298-
const hooks = xhook.listeners("before");
299-
//process hooks sequentially
299+
const beforeHooks = hooks.listeners("before");
300+
//process beforeHooks sequentially
300301
var process = function() {
301-
if (!hooks.length) {
302+
if (!beforeHooks.length) {
302303
return send();
303304
}
304305
//go to next hook OR optionally provide response
@@ -316,7 +317,7 @@ const Xhook = function() {
316317
setReadyState(4);
317318
return;
318319
}
319-
//continue processing until no hooks left
320+
//continue processing until no beforeHooks left
320321
process();
321322
};
322323
//specifically provide headers (readyState 2)
@@ -330,7 +331,7 @@ const Xhook = function() {
330331
setReadyState(3);
331332
};
332333

333-
const hook = hooks.shift();
334+
const hook = beforeHooks.shift();
334335
//async or sync?
335336
if (hook.length === 1) {
336337
done(hook(request));

0 commit comments

Comments
 (0)