abort-during-readystatechange.any.js (662B)
1 "use strict"; 2 setup({ single_test: true }); 3 4 const xhr = new XMLHttpRequest(); 5 6 // In jsdom's implementation, this would cause a crash, as after firing readystatechange for HEADERS_RECEIVED, it would 7 // try to manipulate internal state. But that internal state got cleared during abort(). So jsdom needed to be modified 8 // to check if that internal state had gone away as a result of firing readystatechange, and if so, bail out. 9 10 xhr.addEventListener("readystatechange", () => { 11 if (xhr.readyState === xhr.HEADERS_RECEIVED) { 12 xhr.abort(); 13 } else if (xhr.readyState === xhr.DONE) { 14 done(); 15 } 16 }); 17 18 xhr.open("GET", "/common/blank.html"); 19 xhr.send();