@depup/jsdom 28.1.0-depup.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (538) hide show
  1. package/LICENSE.txt +22 -0
  2. package/README.md +38 -0
  3. package/changes.json +38 -0
  4. package/lib/api.js +373 -0
  5. package/lib/generated/event-sets.js +115 -0
  6. package/lib/generated/idl/AbortController.js +143 -0
  7. package/lib/generated/idl/AbortSignal.js +249 -0
  8. package/lib/generated/idl/AbstractRange.js +171 -0
  9. package/lib/generated/idl/AddEventListenerOptions.js +53 -0
  10. package/lib/generated/idl/AssignedNodesOptions.js +28 -0
  11. package/lib/generated/idl/Attr.js +219 -0
  12. package/lib/generated/idl/BarProp.js +117 -0
  13. package/lib/generated/idl/BeforeUnloadEvent.js +139 -0
  14. package/lib/generated/idl/BinaryType.js +12 -0
  15. package/lib/generated/idl/Blob.js +253 -0
  16. package/lib/generated/idl/BlobCallback.js +30 -0
  17. package/lib/generated/idl/BlobEvent.js +157 -0
  18. package/lib/generated/idl/BlobEventInit.js +43 -0
  19. package/lib/generated/idl/BlobPropertyBag.js +42 -0
  20. package/lib/generated/idl/CDATASection.js +109 -0
  21. package/lib/generated/idl/CanPlayTypeResult.js +12 -0
  22. package/lib/generated/idl/CharacterData.js +455 -0
  23. package/lib/generated/idl/CloseEvent.js +168 -0
  24. package/lib/generated/idl/CloseEventInit.js +65 -0
  25. package/lib/generated/idl/Comment.js +120 -0
  26. package/lib/generated/idl/CompositionEvent.js +219 -0
  27. package/lib/generated/idl/CompositionEventInit.js +32 -0
  28. package/lib/generated/idl/Crypto.js +148 -0
  29. package/lib/generated/idl/CustomElementConstructor.js +34 -0
  30. package/lib/generated/idl/CustomElementRegistry.js +269 -0
  31. package/lib/generated/idl/CustomEvent.js +206 -0
  32. package/lib/generated/idl/CustomEventInit.js +32 -0
  33. package/lib/generated/idl/DOMException.js +222 -0
  34. package/lib/generated/idl/DOMImplementation.js +237 -0
  35. package/lib/generated/idl/DOMParser.js +140 -0
  36. package/lib/generated/idl/DOMRect.js +276 -0
  37. package/lib/generated/idl/DOMRectInit.js +76 -0
  38. package/lib/generated/idl/DOMRectReadOnly.js +285 -0
  39. package/lib/generated/idl/DOMStringMap.js +299 -0
  40. package/lib/generated/idl/DOMTokenList.js +539 -0
  41. package/lib/generated/idl/DeviceMotionEvent.js +183 -0
  42. package/lib/generated/idl/DeviceMotionEventAcceleration.js +145 -0
  43. package/lib/generated/idl/DeviceMotionEventAccelerationInit.js +61 -0
  44. package/lib/generated/idl/DeviceMotionEventInit.js +70 -0
  45. package/lib/generated/idl/DeviceMotionEventRotationRate.js +145 -0
  46. package/lib/generated/idl/DeviceMotionEventRotationRateInit.js +61 -0
  47. package/lib/generated/idl/DeviceOrientationEvent.js +183 -0
  48. package/lib/generated/idl/DeviceOrientationEventInit.js +80 -0
  49. package/lib/generated/idl/Document.js +4511 -0
  50. package/lib/generated/idl/DocumentFragment.js +336 -0
  51. package/lib/generated/idl/DocumentReadyState.js +12 -0
  52. package/lib/generated/idl/DocumentType.js +254 -0
  53. package/lib/generated/idl/Element.js +3720 -0
  54. package/lib/generated/idl/ElementCreationOptions.js +26 -0
  55. package/lib/generated/idl/ElementDefinitionOptions.js +29 -0
  56. package/lib/generated/idl/ElementInternals.js +2152 -0
  57. package/lib/generated/idl/EndingType.js +12 -0
  58. package/lib/generated/idl/ErrorEvent.js +192 -0
  59. package/lib/generated/idl/ErrorEventInit.js +92 -0
  60. package/lib/generated/idl/Event.js +430 -0
  61. package/lib/generated/idl/EventHandlerNonNull.js +36 -0
  62. package/lib/generated/idl/EventInit.js +58 -0
  63. package/lib/generated/idl/EventListener.js +35 -0
  64. package/lib/generated/idl/EventListenerOptions.js +28 -0
  65. package/lib/generated/idl/EventModifierInit.js +221 -0
  66. package/lib/generated/idl/EventTarget.js +259 -0
  67. package/lib/generated/idl/External.js +130 -0
  68. package/lib/generated/idl/File.js +185 -0
  69. package/lib/generated/idl/FileList.js +298 -0
  70. package/lib/generated/idl/FilePropertyBag.js +33 -0
  71. package/lib/generated/idl/FileReader.js +468 -0
  72. package/lib/generated/idl/FocusEvent.js +144 -0
  73. package/lib/generated/idl/FocusEventInit.js +36 -0
  74. package/lib/generated/idl/FormData.js +468 -0
  75. package/lib/generated/idl/Function.js +42 -0
  76. package/lib/generated/idl/GetRootNodeOptions.js +31 -0
  77. package/lib/generated/idl/HTMLAnchorElement.js +1026 -0
  78. package/lib/generated/idl/HTMLAreaElement.js +825 -0
  79. package/lib/generated/idl/HTMLAudioElement.js +111 -0
  80. package/lib/generated/idl/HTMLBRElement.js +156 -0
  81. package/lib/generated/idl/HTMLBaseElement.js +196 -0
  82. package/lib/generated/idl/HTMLBodyElement.js +880 -0
  83. package/lib/generated/idl/HTMLButtonElement.js +525 -0
  84. package/lib/generated/idl/HTMLCanvasElement.js +307 -0
  85. package/lib/generated/idl/HTMLCollection.js +352 -0
  86. package/lib/generated/idl/HTMLDListElement.js +159 -0
  87. package/lib/generated/idl/HTMLDataElement.js +156 -0
  88. package/lib/generated/idl/HTMLDataListElement.js +126 -0
  89. package/lib/generated/idl/HTMLDetailsElement.js +159 -0
  90. package/lib/generated/idl/HTMLDialogElement.js +159 -0
  91. package/lib/generated/idl/HTMLDirectoryElement.js +159 -0
  92. package/lib/generated/idl/HTMLDivElement.js +156 -0
  93. package/lib/generated/idl/HTMLElement.js +3492 -0
  94. package/lib/generated/idl/HTMLEmbedElement.js +381 -0
  95. package/lib/generated/idl/HTMLFieldSetElement.js +332 -0
  96. package/lib/generated/idl/HTMLFontElement.js +239 -0
  97. package/lib/generated/idl/HTMLFormControlsCollection.js +318 -0
  98. package/lib/generated/idl/HTMLFormElement.js +661 -0
  99. package/lib/generated/idl/HTMLFrameElement.js +513 -0
  100. package/lib/generated/idl/HTMLFrameSetElement.js +711 -0
  101. package/lib/generated/idl/HTMLHRElement.js +323 -0
  102. package/lib/generated/idl/HTMLHeadElement.js +111 -0
  103. package/lib/generated/idl/HTMLHeadingElement.js +156 -0
  104. package/lib/generated/idl/HTMLHtmlElement.js +156 -0
  105. package/lib/generated/idl/HTMLIFrameElement.js +689 -0
  106. package/lib/generated/idl/HTMLImageElement.js +906 -0
  107. package/lib/generated/idl/HTMLInputElement.js +1931 -0
  108. package/lib/generated/idl/HTMLLIElement.js +204 -0
  109. package/lib/generated/idl/HTMLLabelElement.js +182 -0
  110. package/lib/generated/idl/HTMLLegendElement.js +169 -0
  111. package/lib/generated/idl/HTMLLinkElement.js +555 -0
  112. package/lib/generated/idl/HTMLMapElement.js +171 -0
  113. package/lib/generated/idl/HTMLMarqueeElement.js +558 -0
  114. package/lib/generated/idl/HTMLMediaElement.js +900 -0
  115. package/lib/generated/idl/HTMLMenuElement.js +159 -0
  116. package/lib/generated/idl/HTMLMetaElement.js +279 -0
  117. package/lib/generated/idl/HTMLMeterElement.js +368 -0
  118. package/lib/generated/idl/HTMLModElement.js +217 -0
  119. package/lib/generated/idl/HTMLOListElement.js +284 -0
  120. package/lib/generated/idl/HTMLObjectElement.js +945 -0
  121. package/lib/generated/idl/HTMLOptGroupElement.js +200 -0
  122. package/lib/generated/idl/HTMLOptionElement.js +379 -0
  123. package/lib/generated/idl/HTMLOptionsCollection.js +513 -0
  124. package/lib/generated/idl/HTMLOutputElement.js +395 -0
  125. package/lib/generated/idl/HTMLParagraphElement.js +156 -0
  126. package/lib/generated/idl/HTMLParamElement.js +279 -0
  127. package/lib/generated/idl/HTMLPictureElement.js +111 -0
  128. package/lib/generated/idl/HTMLPreElement.js +163 -0
  129. package/lib/generated/idl/HTMLProgressElement.js +232 -0
  130. package/lib/generated/idl/HTMLQuoteElement.js +176 -0
  131. package/lib/generated/idl/HTMLScriptElement.js +472 -0
  132. package/lib/generated/idl/HTMLSelectElement.js +993 -0
  133. package/lib/generated/idl/HTMLSlotElement.js +195 -0
  134. package/lib/generated/idl/HTMLSourceElement.js +340 -0
  135. package/lib/generated/idl/HTMLSpanElement.js +111 -0
  136. package/lib/generated/idl/HTMLStyleElement.js +210 -0
  137. package/lib/generated/idl/HTMLTableCaptionElement.js +156 -0
  138. package/lib/generated/idl/HTMLTableCellElement.js +733 -0
  139. package/lib/generated/idl/HTMLTableColElement.js +376 -0
  140. package/lib/generated/idl/HTMLTableElement.js +802 -0
  141. package/lib/generated/idl/HTMLTableRowElement.js +417 -0
  142. package/lib/generated/idl/HTMLTableSectionElement.js +349 -0
  143. package/lib/generated/idl/HTMLTemplateElement.js +124 -0
  144. package/lib/generated/idl/HTMLTextAreaElement.js +1210 -0
  145. package/lib/generated/idl/HTMLTimeElement.js +156 -0
  146. package/lib/generated/idl/HTMLTitleElement.js +155 -0
  147. package/lib/generated/idl/HTMLTrackElement.js +366 -0
  148. package/lib/generated/idl/HTMLUListElement.js +200 -0
  149. package/lib/generated/idl/HTMLUnknownElement.js +109 -0
  150. package/lib/generated/idl/HTMLVideoElement.js +344 -0
  151. package/lib/generated/idl/HashChangeEvent.js +157 -0
  152. package/lib/generated/idl/HashChangeEventInit.js +50 -0
  153. package/lib/generated/idl/Headers.js +418 -0
  154. package/lib/generated/idl/History.js +266 -0
  155. package/lib/generated/idl/InputEvent.js +168 -0
  156. package/lib/generated/idl/InputEventInit.js +68 -0
  157. package/lib/generated/idl/KeyboardEvent.js +445 -0
  158. package/lib/generated/idl/KeyboardEventInit.js +116 -0
  159. package/lib/generated/idl/Location.js +404 -0
  160. package/lib/generated/idl/MessageEvent.js +317 -0
  161. package/lib/generated/idl/MessageEventInit.js +100 -0
  162. package/lib/generated/idl/MimeType.js +156 -0
  163. package/lib/generated/idl/MimeTypeArray.js +326 -0
  164. package/lib/generated/idl/MouseEvent.js +595 -0
  165. package/lib/generated/idl/MouseEventInit.js +189 -0
  166. package/lib/generated/idl/MutationCallback.js +34 -0
  167. package/lib/generated/idl/MutationObserver.js +178 -0
  168. package/lib/generated/idl/MutationObserverInit.js +121 -0
  169. package/lib/generated/idl/MutationRecord.js +229 -0
  170. package/lib/generated/idl/NamedNodeMap.js +529 -0
  171. package/lib/generated/idl/Navigator.js +326 -0
  172. package/lib/generated/idl/Node.js +765 -0
  173. package/lib/generated/idl/NodeFilter.js +75 -0
  174. package/lib/generated/idl/NodeIterator.js +207 -0
  175. package/lib/generated/idl/NodeList.js +302 -0
  176. package/lib/generated/idl/OnBeforeUnloadEventHandlerNonNull.js +42 -0
  177. package/lib/generated/idl/OnErrorEventHandlerNonNull.js +56 -0
  178. package/lib/generated/idl/PageTransitionEvent.js +144 -0
  179. package/lib/generated/idl/PageTransitionEventInit.js +35 -0
  180. package/lib/generated/idl/Performance.js +142 -0
  181. package/lib/generated/idl/Plugin.js +359 -0
  182. package/lib/generated/idl/PluginArray.js +336 -0
  183. package/lib/generated/idl/PointerEvent.js +324 -0
  184. package/lib/generated/idl/PointerEventInit.js +241 -0
  185. package/lib/generated/idl/PopStateEvent.js +144 -0
  186. package/lib/generated/idl/PopStateEventInit.js +32 -0
  187. package/lib/generated/idl/ProcessingInstruction.js +122 -0
  188. package/lib/generated/idl/ProgressEvent.js +170 -0
  189. package/lib/generated/idl/ProgressEventInit.js +65 -0
  190. package/lib/generated/idl/PromiseRejectionEvent.js +157 -0
  191. package/lib/generated/idl/PromiseRejectionEventInit.js +42 -0
  192. package/lib/generated/idl/RadioNodeList.js +296 -0
  193. package/lib/generated/idl/Range.js +643 -0
  194. package/lib/generated/idl/SVGAnimatedPreserveAspectRatio.js +136 -0
  195. package/lib/generated/idl/SVGAnimatedRect.js +136 -0
  196. package/lib/generated/idl/SVGAnimatedString.js +149 -0
  197. package/lib/generated/idl/SVGBoundingBoxOptions.js +64 -0
  198. package/lib/generated/idl/SVGDefsElement.js +109 -0
  199. package/lib/generated/idl/SVGDescElement.js +109 -0
  200. package/lib/generated/idl/SVGElement.js +3157 -0
  201. package/lib/generated/idl/SVGGElement.js +109 -0
  202. package/lib/generated/idl/SVGGraphicsElement.js +139 -0
  203. package/lib/generated/idl/SVGMetadataElement.js +109 -0
  204. package/lib/generated/idl/SVGNumber.js +132 -0
  205. package/lib/generated/idl/SVGPreserveAspectRatio.js +196 -0
  206. package/lib/generated/idl/SVGRect.js +210 -0
  207. package/lib/generated/idl/SVGSVGElement.js +786 -0
  208. package/lib/generated/idl/SVGStringList.js +511 -0
  209. package/lib/generated/idl/SVGSwitchElement.js +109 -0
  210. package/lib/generated/idl/SVGSymbolElement.js +146 -0
  211. package/lib/generated/idl/SVGTitleElement.js +109 -0
  212. package/lib/generated/idl/Screen.js +180 -0
  213. package/lib/generated/idl/ScrollBehavior.js +12 -0
  214. package/lib/generated/idl/ScrollIntoViewOptions.js +45 -0
  215. package/lib/generated/idl/ScrollLogicalPosition.js +14 -0
  216. package/lib/generated/idl/ScrollOptions.js +30 -0
  217. package/lib/generated/idl/ScrollRestoration.js +12 -0
  218. package/lib/generated/idl/Selection.js +571 -0
  219. package/lib/generated/idl/SelectionMode.js +12 -0
  220. package/lib/generated/idl/ShadowRoot.js +189 -0
  221. package/lib/generated/idl/ShadowRootInit.js +30 -0
  222. package/lib/generated/idl/ShadowRootMode.js +12 -0
  223. package/lib/generated/idl/StaticRange.js +123 -0
  224. package/lib/generated/idl/StaticRangeInit.js +72 -0
  225. package/lib/generated/idl/Storage.js +397 -0
  226. package/lib/generated/idl/StorageEvent.js +318 -0
  227. package/lib/generated/idl/StorageEventInit.js +99 -0
  228. package/lib/generated/idl/StyleSheetList.js +300 -0
  229. package/lib/generated/idl/SubmitEvent.js +144 -0
  230. package/lib/generated/idl/SubmitEventInit.js +36 -0
  231. package/lib/generated/idl/SupportedType.js +18 -0
  232. package/lib/generated/idl/Text.js +170 -0
  233. package/lib/generated/idl/TextDecodeOptions.js +28 -0
  234. package/lib/generated/idl/TextDecoder.js +211 -0
  235. package/lib/generated/idl/TextDecoderOptions.js +43 -0
  236. package/lib/generated/idl/TextEncoder.js +176 -0
  237. package/lib/generated/idl/TextEncoderEncodeIntoResult.js +42 -0
  238. package/lib/generated/idl/TextTrackKind.js +12 -0
  239. package/lib/generated/idl/TouchEvent.js +222 -0
  240. package/lib/generated/idl/TouchEventInit.js +89 -0
  241. package/lib/generated/idl/TransitionEvent.js +170 -0
  242. package/lib/generated/idl/TransitionEventInit.js +65 -0
  243. package/lib/generated/idl/TreeWalker.js +255 -0
  244. package/lib/generated/idl/UIEvent.js +235 -0
  245. package/lib/generated/idl/UIEventInit.js +62 -0
  246. package/lib/generated/idl/ValidityState.js +249 -0
  247. package/lib/generated/idl/VisibilityState.js +12 -0
  248. package/lib/generated/idl/VoidFunction.js +26 -0
  249. package/lib/generated/idl/WebSocket.js +480 -0
  250. package/lib/generated/idl/WheelEvent.js +191 -0
  251. package/lib/generated/idl/WheelEventInit.js +71 -0
  252. package/lib/generated/idl/XMLDocument.js +109 -0
  253. package/lib/generated/idl/XMLHttpRequest.js +663 -0
  254. package/lib/generated/idl/XMLHttpRequestEventTarget.js +334 -0
  255. package/lib/generated/idl/XMLHttpRequestResponseType.js +14 -0
  256. package/lib/generated/idl/XMLHttpRequestUpload.js +109 -0
  257. package/lib/generated/idl/XMLSerializer.js +132 -0
  258. package/lib/generated/idl/utils.js +252 -0
  259. package/lib/generated/js-globals.json +332 -0
  260. package/lib/jsdom/browser/Window.js +952 -0
  261. package/lib/jsdom/browser/default-stylesheet.css +415 -0
  262. package/lib/jsdom/browser/not-implemented.js +20 -0
  263. package/lib/jsdom/browser/parser/html.js +208 -0
  264. package/lib/jsdom/browser/parser/index.js +37 -0
  265. package/lib/jsdom/browser/parser/xml.js +202 -0
  266. package/lib/jsdom/browser/resources/async-resource-queue.js +114 -0
  267. package/lib/jsdom/browser/resources/decompress-interceptor.js +184 -0
  268. package/lib/jsdom/browser/resources/jsdom-dispatcher.js +756 -0
  269. package/lib/jsdom/browser/resources/per-document-resource-loader.js +116 -0
  270. package/lib/jsdom/browser/resources/request-interceptor.js +171 -0
  271. package/lib/jsdom/browser/resources/request-manager.js +33 -0
  272. package/lib/jsdom/browser/resources/resource-queue.js +142 -0
  273. package/lib/jsdom/browser/resources/stream-handler.js +89 -0
  274. package/lib/jsdom/level2/style.js +65 -0
  275. package/lib/jsdom/level3/xpath.js +1875 -0
  276. package/lib/jsdom/living/aborting/AbortController-impl.js +17 -0
  277. package/lib/jsdom/living/aborting/AbortSignal-impl.js +131 -0
  278. package/lib/jsdom/living/attributes/Attr-impl.js +60 -0
  279. package/lib/jsdom/living/attributes/NamedNodeMap-impl.js +78 -0
  280. package/lib/jsdom/living/attributes.js +312 -0
  281. package/lib/jsdom/living/constraint-validation/DefaultConstraintValidation-impl.js +75 -0
  282. package/lib/jsdom/living/constraint-validation/ValidityState-impl.js +66 -0
  283. package/lib/jsdom/living/crypto/Crypto-impl.js +68 -0
  284. package/lib/jsdom/living/cssom/StyleSheetList-impl.js +38 -0
  285. package/lib/jsdom/living/custom-elements/CustomElementRegistry-impl.js +279 -0
  286. package/lib/jsdom/living/custom-elements/ElementInternals-impl.js +56 -0
  287. package/lib/jsdom/living/deviceorientation/DeviceMotionEventAcceleration-impl.js +7 -0
  288. package/lib/jsdom/living/deviceorientation/DeviceMotionEventRotationRate-impl.js +7 -0
  289. package/lib/jsdom/living/documents.js +15 -0
  290. package/lib/jsdom/living/domparsing/DOMParser-impl.js +59 -0
  291. package/lib/jsdom/living/domparsing/InnerHTML-impl.js +30 -0
  292. package/lib/jsdom/living/domparsing/XMLSerializer-impl.js +18 -0
  293. package/lib/jsdom/living/domparsing/parse5-adapter-serialization.js +63 -0
  294. package/lib/jsdom/living/domparsing/serialization.js +36 -0
  295. package/lib/jsdom/living/encoding/TextDecoder-impl.js +25 -0
  296. package/lib/jsdom/living/encoding/TextEncoder-impl.js +26 -0
  297. package/lib/jsdom/living/events/BeforeUnloadEvent-impl.js +12 -0
  298. package/lib/jsdom/living/events/BlobEvent-impl.js +14 -0
  299. package/lib/jsdom/living/events/CloseEvent-impl.js +10 -0
  300. package/lib/jsdom/living/events/CompositionEvent-impl.js +20 -0
  301. package/lib/jsdom/living/events/CustomEvent-impl.js +21 -0
  302. package/lib/jsdom/living/events/DeviceMotionEvent-impl.js +49 -0
  303. package/lib/jsdom/living/events/DeviceOrientationEvent-impl.js +10 -0
  304. package/lib/jsdom/living/events/ErrorEvent-impl.js +14 -0
  305. package/lib/jsdom/living/events/Event-impl.js +195 -0
  306. package/lib/jsdom/living/events/EventModifierMixin-impl.js +24 -0
  307. package/lib/jsdom/living/events/EventTarget-impl.js +438 -0
  308. package/lib/jsdom/living/events/FocusEvent-impl.js +9 -0
  309. package/lib/jsdom/living/events/HashChangeEvent-impl.js +14 -0
  310. package/lib/jsdom/living/events/InputEvent-impl.js +11 -0
  311. package/lib/jsdom/living/events/KeyboardEvent-impl.js +29 -0
  312. package/lib/jsdom/living/events/MessageEvent-impl.js +25 -0
  313. package/lib/jsdom/living/events/MouseEvent-impl.js +72 -0
  314. package/lib/jsdom/living/events/PageTransitionEvent-impl.js +20 -0
  315. package/lib/jsdom/living/events/PointerEvent-impl.js +21 -0
  316. package/lib/jsdom/living/events/PopStateEvent-impl.js +9 -0
  317. package/lib/jsdom/living/events/ProgressEvent-impl.js +14 -0
  318. package/lib/jsdom/living/events/PromiseRejectionEvent-impl.js +14 -0
  319. package/lib/jsdom/living/events/StorageEvent-impl.js +26 -0
  320. package/lib/jsdom/living/events/SubmitEvent-impl.js +13 -0
  321. package/lib/jsdom/living/events/TouchEvent-impl.js +14 -0
  322. package/lib/jsdom/living/events/TransitionEvent-impl.js +10 -0
  323. package/lib/jsdom/living/events/UIEvent-impl.js +43 -0
  324. package/lib/jsdom/living/events/WheelEvent-impl.js +12 -0
  325. package/lib/jsdom/living/fetch/Headers-impl.js +173 -0
  326. package/lib/jsdom/living/fetch/header-list.js +158 -0
  327. package/lib/jsdom/living/fetch/header-types.js +205 -0
  328. package/lib/jsdom/living/fetch/header-utils.js +26 -0
  329. package/lib/jsdom/living/file-api/Blob-impl.js +125 -0
  330. package/lib/jsdom/living/file-api/File-impl.js +12 -0
  331. package/lib/jsdom/living/file-api/FileList-impl.js +15 -0
  332. package/lib/jsdom/living/file-api/FileReader-impl.js +148 -0
  333. package/lib/jsdom/living/geometry/DOMRect-impl.js +39 -0
  334. package/lib/jsdom/living/geometry/DOMRectReadOnly-impl.js +72 -0
  335. package/lib/jsdom/living/helpers/binary-data.js +63 -0
  336. package/lib/jsdom/living/helpers/by-id-cache.js +67 -0
  337. package/lib/jsdom/living/helpers/colors.js +245 -0
  338. package/lib/jsdom/living/helpers/create-element.js +329 -0
  339. package/lib/jsdom/living/helpers/create-event-accessor.js +209 -0
  340. package/lib/jsdom/living/helpers/custom-elements.js +272 -0
  341. package/lib/jsdom/living/helpers/dates-and-times.js +270 -0
  342. package/lib/jsdom/living/helpers/details.js +15 -0
  343. package/lib/jsdom/living/helpers/encoding.js +60 -0
  344. package/lib/jsdom/living/helpers/events.js +24 -0
  345. package/lib/jsdom/living/helpers/focusing.js +104 -0
  346. package/lib/jsdom/living/helpers/form-controls.js +309 -0
  347. package/lib/jsdom/living/helpers/html-constructor.js +78 -0
  348. package/lib/jsdom/living/helpers/internal-constants.js +12 -0
  349. package/lib/jsdom/living/helpers/is-window.js +18 -0
  350. package/lib/jsdom/living/helpers/iterable-weak-set.js +48 -0
  351. package/lib/jsdom/living/helpers/json.js +7 -0
  352. package/lib/jsdom/living/helpers/mutation-observers.js +198 -0
  353. package/lib/jsdom/living/helpers/namespaces.js +16 -0
  354. package/lib/jsdom/living/helpers/node.js +108 -0
  355. package/lib/jsdom/living/helpers/number-and-date-inputs.js +195 -0
  356. package/lib/jsdom/living/helpers/ordered-set.js +104 -0
  357. package/lib/jsdom/living/helpers/page-transition-event.js +9 -0
  358. package/lib/jsdom/living/helpers/runtime-script-errors.js +75 -0
  359. package/lib/jsdom/living/helpers/shadow-dom.js +285 -0
  360. package/lib/jsdom/living/helpers/strings.js +168 -0
  361. package/lib/jsdom/living/helpers/style-rules.js +404 -0
  362. package/lib/jsdom/living/helpers/stylesheets.js +148 -0
  363. package/lib/jsdom/living/helpers/svg/basic-types.js +41 -0
  364. package/lib/jsdom/living/helpers/svg/render.js +46 -0
  365. package/lib/jsdom/living/helpers/system-colors.js +147 -0
  366. package/lib/jsdom/living/helpers/text.js +19 -0
  367. package/lib/jsdom/living/helpers/traversal.js +72 -0
  368. package/lib/jsdom/living/helpers/validate-names.js +65 -0
  369. package/lib/jsdom/living/hr-time/Performance-impl.js +22 -0
  370. package/lib/jsdom/living/interfaces.js +252 -0
  371. package/lib/jsdom/living/mutation-observer/MutationObserver-impl.js +95 -0
  372. package/lib/jsdom/living/mutation-observer/MutationRecord-impl.js +37 -0
  373. package/lib/jsdom/living/navigator/MimeType-impl.js +3 -0
  374. package/lib/jsdom/living/navigator/MimeTypeArray-impl.js +21 -0
  375. package/lib/jsdom/living/navigator/Navigator-impl.js +29 -0
  376. package/lib/jsdom/living/navigator/NavigatorConcurrentHardware-impl.js +8 -0
  377. package/lib/jsdom/living/navigator/NavigatorCookies-impl.js +7 -0
  378. package/lib/jsdom/living/navigator/NavigatorID-impl.js +37 -0
  379. package/lib/jsdom/living/navigator/NavigatorLanguage-impl.js +9 -0
  380. package/lib/jsdom/living/navigator/NavigatorOnLine-impl.js +7 -0
  381. package/lib/jsdom/living/navigator/NavigatorPlugins-impl.js +8 -0
  382. package/lib/jsdom/living/navigator/Plugin-impl.js +3 -0
  383. package/lib/jsdom/living/navigator/PluginArray-impl.js +23 -0
  384. package/lib/jsdom/living/node-document-position.js +10 -0
  385. package/lib/jsdom/living/node-type.js +16 -0
  386. package/lib/jsdom/living/node.js +331 -0
  387. package/lib/jsdom/living/nodes/CDATASection-impl.js +16 -0
  388. package/lib/jsdom/living/nodes/CharacterData-impl.js +118 -0
  389. package/lib/jsdom/living/nodes/ChildNode-impl.js +80 -0
  390. package/lib/jsdom/living/nodes/Comment-impl.js +20 -0
  391. package/lib/jsdom/living/nodes/DOMImplementation-impl.js +120 -0
  392. package/lib/jsdom/living/nodes/DOMStringMap-impl.js +64 -0
  393. package/lib/jsdom/living/nodes/DOMTokenList-impl.js +171 -0
  394. package/lib/jsdom/living/nodes/Document-impl.js +1000 -0
  395. package/lib/jsdom/living/nodes/DocumentFragment-impl.js +44 -0
  396. package/lib/jsdom/living/nodes/DocumentOrShadowRoot-impl.js +28 -0
  397. package/lib/jsdom/living/nodes/DocumentType-impl.js +24 -0
  398. package/lib/jsdom/living/nodes/Element-impl.js +584 -0
  399. package/lib/jsdom/living/nodes/ElementCSSInlineStyle-impl.js +22 -0
  400. package/lib/jsdom/living/nodes/ElementContentEditable-impl.js +7 -0
  401. package/lib/jsdom/living/nodes/GlobalEventHandlers-impl.js +81 -0
  402. package/lib/jsdom/living/nodes/HTMLAnchorElement-impl.js +50 -0
  403. package/lib/jsdom/living/nodes/HTMLAreaElement-impl.js +43 -0
  404. package/lib/jsdom/living/nodes/HTMLAudioElement-impl.js +9 -0
  405. package/lib/jsdom/living/nodes/HTMLBRElement-impl.js +9 -0
  406. package/lib/jsdom/living/nodes/HTMLBaseElement-impl.js +44 -0
  407. package/lib/jsdom/living/nodes/HTMLBodyElement-impl.js +12 -0
  408. package/lib/jsdom/living/nodes/HTMLButtonElement-impl.js +79 -0
  409. package/lib/jsdom/living/nodes/HTMLCanvasElement-impl.js +136 -0
  410. package/lib/jsdom/living/nodes/HTMLCollection-impl.js +96 -0
  411. package/lib/jsdom/living/nodes/HTMLDListElement-impl.js +9 -0
  412. package/lib/jsdom/living/nodes/HTMLDataElement-impl.js +9 -0
  413. package/lib/jsdom/living/nodes/HTMLDataListElement-impl.js +20 -0
  414. package/lib/jsdom/living/nodes/HTMLDetailsElement-impl.js +35 -0
  415. package/lib/jsdom/living/nodes/HTMLDialogElement-impl.js +9 -0
  416. package/lib/jsdom/living/nodes/HTMLDirectoryElement-impl.js +9 -0
  417. package/lib/jsdom/living/nodes/HTMLDivElement-impl.js +9 -0
  418. package/lib/jsdom/living/nodes/HTMLElement-impl.js +211 -0
  419. package/lib/jsdom/living/nodes/HTMLEmbedElement-impl.js +8 -0
  420. package/lib/jsdom/living/nodes/HTMLFieldSetElement-impl.js +43 -0
  421. package/lib/jsdom/living/nodes/HTMLFontElement-impl.js +9 -0
  422. package/lib/jsdom/living/nodes/HTMLFormControlsCollection-impl.js +33 -0
  423. package/lib/jsdom/living/nodes/HTMLFormElement-impl.js +248 -0
  424. package/lib/jsdom/living/nodes/HTMLFrameElement-impl.js +266 -0
  425. package/lib/jsdom/living/nodes/HTMLFrameSetElement-impl.js +12 -0
  426. package/lib/jsdom/living/nodes/HTMLHRElement-impl.js +9 -0
  427. package/lib/jsdom/living/nodes/HTMLHeadElement-impl.js +9 -0
  428. package/lib/jsdom/living/nodes/HTMLHeadingElement-impl.js +9 -0
  429. package/lib/jsdom/living/nodes/HTMLHtmlElement-impl.js +9 -0
  430. package/lib/jsdom/living/nodes/HTMLHyperlinkElementUtils-impl.js +368 -0
  431. package/lib/jsdom/living/nodes/HTMLIFrameElement-impl.js +9 -0
  432. package/lib/jsdom/living/nodes/HTMLImageElement-impl.js +127 -0
  433. package/lib/jsdom/living/nodes/HTMLInputElement-impl.js +1097 -0
  434. package/lib/jsdom/living/nodes/HTMLLIElement-impl.js +9 -0
  435. package/lib/jsdom/living/nodes/HTMLLabelElement-impl.js +94 -0
  436. package/lib/jsdom/living/nodes/HTMLLegendElement-impl.js +18 -0
  437. package/lib/jsdom/living/nodes/HTMLLinkElement-impl.js +107 -0
  438. package/lib/jsdom/living/nodes/HTMLMapElement-impl.js +13 -0
  439. package/lib/jsdom/living/nodes/HTMLMarqueeElement-impl.js +9 -0
  440. package/lib/jsdom/living/nodes/HTMLMediaElement-impl.js +138 -0
  441. package/lib/jsdom/living/nodes/HTMLMenuElement-impl.js +9 -0
  442. package/lib/jsdom/living/nodes/HTMLMetaElement-impl.js +9 -0
  443. package/lib/jsdom/living/nodes/HTMLMeterElement-impl.js +180 -0
  444. package/lib/jsdom/living/nodes/HTMLModElement-impl.js +9 -0
  445. package/lib/jsdom/living/nodes/HTMLOListElement-impl.js +22 -0
  446. package/lib/jsdom/living/nodes/HTMLObjectElement-impl.js +26 -0
  447. package/lib/jsdom/living/nodes/HTMLOptGroupElement-impl.js +9 -0
  448. package/lib/jsdom/living/nodes/HTMLOptionElement-impl.js +146 -0
  449. package/lib/jsdom/living/nodes/HTMLOptionsCollection-impl.js +110 -0
  450. package/lib/jsdom/living/nodes/HTMLOrSVGElement-impl.js +88 -0
  451. package/lib/jsdom/living/nodes/HTMLOutputElement-impl.js +88 -0
  452. package/lib/jsdom/living/nodes/HTMLParagraphElement-impl.js +9 -0
  453. package/lib/jsdom/living/nodes/HTMLParamElement-impl.js +9 -0
  454. package/lib/jsdom/living/nodes/HTMLPictureElement-impl.js +9 -0
  455. package/lib/jsdom/living/nodes/HTMLPreElement-impl.js +9 -0
  456. package/lib/jsdom/living/nodes/HTMLProgressElement-impl.js +72 -0
  457. package/lib/jsdom/living/nodes/HTMLQuoteElement-impl.js +9 -0
  458. package/lib/jsdom/living/nodes/HTMLScriptElement-impl.js +255 -0
  459. package/lib/jsdom/living/nodes/HTMLSelectElement-impl.js +283 -0
  460. package/lib/jsdom/living/nodes/HTMLSlotElement-impl.js +59 -0
  461. package/lib/jsdom/living/nodes/HTMLSourceElement-impl.js +8 -0
  462. package/lib/jsdom/living/nodes/HTMLSpanElement-impl.js +9 -0
  463. package/lib/jsdom/living/nodes/HTMLStyleElement-impl.js +76 -0
  464. package/lib/jsdom/living/nodes/HTMLTableCaptionElement-impl.js +9 -0
  465. package/lib/jsdom/living/nodes/HTMLTableCellElement-impl.js +73 -0
  466. package/lib/jsdom/living/nodes/HTMLTableColElement-impl.js +9 -0
  467. package/lib/jsdom/living/nodes/HTMLTableElement-impl.js +236 -0
  468. package/lib/jsdom/living/nodes/HTMLTableRowElement-impl.js +88 -0
  469. package/lib/jsdom/living/nodes/HTMLTableSectionElement-impl.js +61 -0
  470. package/lib/jsdom/living/nodes/HTMLTemplateElement-impl.js +67 -0
  471. package/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js +244 -0
  472. package/lib/jsdom/living/nodes/HTMLTimeElement-impl.js +9 -0
  473. package/lib/jsdom/living/nodes/HTMLTitleElement-impl.js +18 -0
  474. package/lib/jsdom/living/nodes/HTMLTrackElement-impl.js +13 -0
  475. package/lib/jsdom/living/nodes/HTMLUListElement-impl.js +9 -0
  476. package/lib/jsdom/living/nodes/HTMLUnknownElement-impl.js +9 -0
  477. package/lib/jsdom/living/nodes/HTMLVideoElement-impl.js +17 -0
  478. package/lib/jsdom/living/nodes/LinkStyle-impl.js +2 -0
  479. package/lib/jsdom/living/nodes/Node-impl.js +1179 -0
  480. package/lib/jsdom/living/nodes/NodeList-impl.js +43 -0
  481. package/lib/jsdom/living/nodes/NonDocumentTypeChildNode-impl.js +28 -0
  482. package/lib/jsdom/living/nodes/NonElementParentNode-impl.js +11 -0
  483. package/lib/jsdom/living/nodes/ParentNode-impl.js +90 -0
  484. package/lib/jsdom/living/nodes/ProcessingInstruction-impl.js +22 -0
  485. package/lib/jsdom/living/nodes/RadioNodeList-impl.js +49 -0
  486. package/lib/jsdom/living/nodes/SVGDefsElement-impl.js +9 -0
  487. package/lib/jsdom/living/nodes/SVGDescElement-impl.js +9 -0
  488. package/lib/jsdom/living/nodes/SVGElement-impl.js +64 -0
  489. package/lib/jsdom/living/nodes/SVGGElement-impl.js +9 -0
  490. package/lib/jsdom/living/nodes/SVGGraphicsElement-impl.js +16 -0
  491. package/lib/jsdom/living/nodes/SVGMetadataElement-impl.js +9 -0
  492. package/lib/jsdom/living/nodes/SVGSVGElement-impl.js +40 -0
  493. package/lib/jsdom/living/nodes/SVGSwitchElement-impl.js +9 -0
  494. package/lib/jsdom/living/nodes/SVGSymbolElement-impl.js +9 -0
  495. package/lib/jsdom/living/nodes/SVGTests-impl.js +42 -0
  496. package/lib/jsdom/living/nodes/SVGTitleElement-impl.js +9 -0
  497. package/lib/jsdom/living/nodes/ShadowRoot-impl.js +41 -0
  498. package/lib/jsdom/living/nodes/Slotable-impl.js +48 -0
  499. package/lib/jsdom/living/nodes/Text-impl.js +96 -0
  500. package/lib/jsdom/living/nodes/WindowEventHandlers-impl.js +14 -0
  501. package/lib/jsdom/living/nodes/XMLDocument-impl.js +4 -0
  502. package/lib/jsdom/living/range/AbstractRange-impl.js +43 -0
  503. package/lib/jsdom/living/range/Range-impl.js +902 -0
  504. package/lib/jsdom/living/range/StaticRange-impl.js +39 -0
  505. package/lib/jsdom/living/range/boundary-point.js +47 -0
  506. package/lib/jsdom/living/selection/Selection-impl.js +358 -0
  507. package/lib/jsdom/living/svg/SVGAnimatedPreserveAspectRatio-impl.js +24 -0
  508. package/lib/jsdom/living/svg/SVGAnimatedRect-impl.js +122 -0
  509. package/lib/jsdom/living/svg/SVGAnimatedString-impl.js +42 -0
  510. package/lib/jsdom/living/svg/SVGListBase.js +195 -0
  511. package/lib/jsdom/living/svg/SVGNumber-impl.js +48 -0
  512. package/lib/jsdom/living/svg/SVGPreserveAspectRatio-impl.js +100 -0
  513. package/lib/jsdom/living/svg/SVGRect-impl.js +143 -0
  514. package/lib/jsdom/living/svg/SVGStringList-impl.js +16 -0
  515. package/lib/jsdom/living/traversal/NodeIterator-impl.js +107 -0
  516. package/lib/jsdom/living/traversal/TreeWalker-impl.js +217 -0
  517. package/lib/jsdom/living/traversal/helpers.js +44 -0
  518. package/lib/jsdom/living/webidl/DOMException-impl.js +46 -0
  519. package/lib/jsdom/living/websockets/WebSocket-impl.js +211 -0
  520. package/lib/jsdom/living/webstorage/Storage-impl.js +102 -0
  521. package/lib/jsdom/living/window/BarProp-impl.js +10 -0
  522. package/lib/jsdom/living/window/External-impl.js +9 -0
  523. package/lib/jsdom/living/window/History-impl.js +148 -0
  524. package/lib/jsdom/living/window/Location-impl.js +227 -0
  525. package/lib/jsdom/living/window/Screen-impl.js +13 -0
  526. package/lib/jsdom/living/window/SessionHistory.js +163 -0
  527. package/lib/jsdom/living/window/navigation.js +87 -0
  528. package/lib/jsdom/living/window-properties.js +241 -0
  529. package/lib/jsdom/living/xhr/FormData-impl.js +191 -0
  530. package/lib/jsdom/living/xhr/XMLHttpRequest-impl.js +1057 -0
  531. package/lib/jsdom/living/xhr/XMLHttpRequestEventTarget-impl.js +17 -0
  532. package/lib/jsdom/living/xhr/XMLHttpRequestUpload-impl.js +4 -0
  533. package/lib/jsdom/living/xhr/multipart-form-data.js +99 -0
  534. package/lib/jsdom/living/xhr/xhr-sync-worker.js +51 -0
  535. package/lib/jsdom/living/xhr/xhr-utils.js +206 -0
  536. package/lib/jsdom/utils.js +105 -0
  537. package/lib/jsdom/virtual-console.js +46 -0
  538. package/package.json +143 -0
@@ -0,0 +1,1057 @@
1
+ "use strict";
2
+
3
+ const { Worker, receiveMessageOnPort, MessageChannel } = require("node:worker_threads");
4
+ const { inspect } = require("util");
5
+ const { parseURL, serializeURL } = require("whatwg-url");
6
+ const { getBOMEncoding, labelToName, legacyHookDecode } = require("@exodus/bytes/encoding.js");
7
+ const tough = require("tough-cookie");
8
+ const { MIMEType } = require("whatwg-mimetype");
9
+ const DOMException = require("../../../generated/idl/DOMException");
10
+ const idlUtils = require("../../../generated/idl/utils");
11
+ const Document = require("../../../generated/idl/Document");
12
+ const Blob = require("../../../generated/idl/Blob");
13
+ const FormData = require("../../../generated/idl/FormData");
14
+ const XMLHttpRequestUpload = require("../../../generated/idl/XMLHttpRequestUpload");
15
+ const ProgressEvent = require("../../../generated/idl/ProgressEvent");
16
+ const { isHeaderName, isHeaderValue, normalizeHeaderValue } = require("../fetch/header-utils");
17
+ const HeaderList = require("../fetch/header-list");
18
+ const { isForbiddenRequestHeader } = require("../fetch/header-types");
19
+ const { performFetch, isNetworkError } = require("./xhr-utils");
20
+ const XMLHttpRequestEventTargetImpl = require("./XMLHttpRequestEventTarget-impl").implementation;
21
+ const { parseIntoDocument } = require("../../browser/parser");
22
+ const { fragmentSerialization } = require("../domparsing/serialization");
23
+ const { copyToArrayBufferInTargetRealmDestructively, concatTypedArrays } = require("../helpers/binary-data");
24
+ const { setupForSimpleEventAccessors } = require("../helpers/create-event-accessor");
25
+ const { utf8Encode, utf8Decode } = require("../helpers/encoding");
26
+ const { fireAnEvent } = require("../helpers/events");
27
+ const { parseJSONFromBytes } = require("../helpers/json");
28
+ const { asciiCaseInsensitiveMatch } = require("../helpers/strings");
29
+ const { serializeEntryList } = require("./multipart-form-data");
30
+
31
+ const syncWorkerFile = require.resolve("./xhr-sync-worker.js");
32
+
33
+ // TODO: simplify after dropping Node.js v20 support
34
+ function trimUint8Array(arr, newSize) {
35
+ if (arr.buffer.transfer) {
36
+ return new Uint8Array(arr.buffer.transfer(newSize));
37
+ }
38
+ return arr.slice(0, newSize);
39
+ }
40
+
41
+ let syncWorker = null;
42
+
43
+ function getSyncWorker() {
44
+ if (!syncWorker) {
45
+ syncWorker = new Worker(syncWorkerFile);
46
+ syncWorker.unref();
47
+ syncWorker.on("exit", () => {
48
+ syncWorker = null;
49
+ });
50
+ }
51
+ return syncWorker;
52
+ }
53
+
54
+ const SYNC_WORKER_TIMEOUT_MS = 2 * 60 * 1000;
55
+
56
+ // Sends a serialized XHR request to the persistent worker thread and synchronously blocks
57
+ // until it responds. The synchronization works as follows:
58
+ //
59
+ // - A SharedArrayBuffer is shared between the main thread and the worker, used as a signal.
60
+ // - Atomics.wait() blocks the main thread until the worker writes to the shared buffer.
61
+ // - The worker does the actual async fetch, then posts the response via a MessagePort and
62
+ // signals completion by writing to the SharedArrayBuffer with Atomics.store()/notify().
63
+ // - After waking, receiveMessageOnPort() synchronously reads the response from the port.
64
+ function sendSyncWorkerRequest(config) {
65
+ const sharedBuffer = new SharedArrayBuffer(4);
66
+ const int32 = new Int32Array(sharedBuffer);
67
+ const { port1, port2 } = new MessageChannel();
68
+
69
+ getSyncWorker().postMessage({ sharedBuffer, responsePort: port2, config }, [port2]);
70
+
71
+ const waitResult = Atomics.wait(int32, 0, 0, SYNC_WORKER_TIMEOUT_MS);
72
+ if (waitResult === "timed-out") {
73
+ throw new Error("Sync XHR worker timed out");
74
+ }
75
+
76
+ const msg = receiveMessageOnPort(port1);
77
+ if (!msg) {
78
+ throw new Error("No response received from sync XHR worker");
79
+ }
80
+ return msg.message;
81
+ }
82
+
83
+ const READY_STATES = Object.freeze({
84
+ UNSENT: 0,
85
+ OPENED: 1,
86
+ HEADERS_RECEIVED: 2,
87
+ LOADING: 3,
88
+ DONE: 4
89
+ });
90
+
91
+ const tokenRegexp = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
92
+
93
+ const allowedRequestMethods = new Set(["OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"]);
94
+ const forbiddenRequestMethods = new Set(["TRACK", "TRACE", "CONNECT"]);
95
+
96
+ // Helper functions for error handling
97
+
98
+ function dispatchError(xhr, errMessage) {
99
+ // Store the error message for sync XHR worker to serialize
100
+ xhr._error = errMessage;
101
+ requestErrorSteps(xhr, "error", DOMException.create(xhr._globalObject, [errMessage, "NetworkError"]));
102
+ }
103
+
104
+ function requestErrorSteps(xhr, event, exception) {
105
+ const { upload } = xhr;
106
+
107
+ xhr.readyState = READY_STATES.DONE;
108
+ xhr._send = false;
109
+
110
+ setResponseToNetworkError(xhr);
111
+
112
+ if (xhr._synchronous) {
113
+ throw exception;
114
+ }
115
+
116
+ fireAnEvent("readystatechange", xhr);
117
+
118
+ if (!xhr._uploadComplete) {
119
+ xhr._uploadComplete = true;
120
+
121
+ if (xhr._uploadListener) {
122
+ fireAnEvent(event, upload, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
123
+ fireAnEvent("loadend", upload, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
124
+ }
125
+ }
126
+
127
+ fireAnEvent(event, xhr, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
128
+ fireAnEvent("loadend", xhr, ProgressEvent, { loaded: 0, total: 0, lengthComputable: false });
129
+ }
130
+
131
+ function setResponseToNetworkError(xhr) {
132
+ xhr._responseBytes =
133
+ xhr._responseCache =
134
+ xhr._responseTextCache =
135
+ xhr._responseXMLCache = null;
136
+
137
+ xhr._responseHeaders = new HeaderList();
138
+ xhr.status = 0;
139
+ xhr.statusText = "";
140
+ }
141
+
142
+ class XMLHttpRequestImpl extends XMLHttpRequestEventTargetImpl {
143
+ constructor(window) {
144
+ super(window);
145
+
146
+ const { _ownerDocument } = this;
147
+
148
+ this.upload = XMLHttpRequestUpload.createImpl(window);
149
+
150
+ // Public WebIDL properties
151
+ this.readyState = READY_STATES.UNSENT;
152
+ this.responseURL = "";
153
+ this.status = 0;
154
+ this.statusText = "";
155
+
156
+ // Request configuration
157
+ this._synchronous = false;
158
+ this._withCredentials = false;
159
+ this._mimeType = null;
160
+ this._auth = null;
161
+ this._method = undefined;
162
+ this._responseType = "";
163
+ this._requestHeaders = new HeaderList();
164
+ this._referrer = _ownerDocument.URL;
165
+ this._url = "";
166
+ this._timeout = 0;
167
+ this._body = undefined;
168
+ this._preflight = false;
169
+ this._overrideMIMEType = null;
170
+ this._overrideCharset = null;
171
+ this._requestManager = _ownerDocument._requestManager;
172
+ this._dispatcher = window._dispatcher;
173
+ this._cookieJar = _ownerDocument._cookieJar;
174
+ this._encoding = _ownerDocument._encoding;
175
+ this._origin = window._origin;
176
+ this._userAgent = window.navigator.userAgent;
177
+
178
+ // Runtime/response state
179
+ this._beforeSend = false;
180
+ this._send = false;
181
+ this._controller = null;
182
+ this._timeoutStart = 0;
183
+ this._timeoutId = 0;
184
+ this._timeoutFn = null;
185
+ this._responseBytes = null;
186
+ this._responseCache = null;
187
+ this._responseTextCache = null;
188
+ this._responseXMLCache = null;
189
+ this._responseHeaders = new HeaderList();
190
+ this._filteredResponseHeaders = new Set();
191
+ this._error = "";
192
+ this._uploadComplete = false;
193
+ this._uploadListener = false;
194
+ // Signifies that we're calling abort() from xhr-utils.js because of a window shutdown.
195
+ // In that case the termination reason is "fatal", not "end-user abort".
196
+ this._abortError = false;
197
+ this._bufferStepSize = 1 * 1024 * 1024; // pre-allocate buffer increase step size. init value is 1MB
198
+ this._totalReceivedChunkSize = 0;
199
+ }
200
+
201
+ get responseType() {
202
+ return this._responseType;
203
+ }
204
+ set responseType(responseType) {
205
+ if (this.readyState === READY_STATES.LOADING || this.readyState === READY_STATES.DONE) {
206
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
207
+ }
208
+ if (this.readyState === READY_STATES.OPENED && this._synchronous) {
209
+ throw DOMException.create(this._globalObject, [
210
+ "The object does not support the operation or argument.",
211
+ "InvalidAccessError"
212
+ ]);
213
+ }
214
+ this._responseType = responseType;
215
+ }
216
+
217
+ get response() {
218
+ if (this._responseCache) {
219
+ // Needed because of: https://github.com/jsdom/webidl2js/issues/149
220
+ return idlUtils.tryWrapperForImpl(this._responseCache);
221
+ }
222
+ let res;
223
+
224
+ const responseBytes = this._responseBytes?.slice(0, this._totalReceivedChunkSize) ?? null;
225
+
226
+ switch (this.responseType) {
227
+ case "":
228
+ case "text": {
229
+ res = this.responseText;
230
+ break;
231
+ }
232
+ case "arraybuffer": {
233
+ if (!responseBytes) {
234
+ return null;
235
+ }
236
+ res = copyToArrayBufferInTargetRealmDestructively(responseBytes.buffer, this._globalObject);
237
+ break;
238
+ }
239
+ case "blob": {
240
+ if (!responseBytes) {
241
+ return null;
242
+ }
243
+ const contentType = finalMIMEType(this);
244
+ res = Blob.createImpl(this._globalObject, [
245
+ [new Uint8Array(responseBytes)],
246
+ { type: contentType || "" }
247
+ ]);
248
+ break;
249
+ }
250
+ case "document": {
251
+ res = this.responseXML;
252
+ break;
253
+ }
254
+ case "json": {
255
+ if (this.readyState !== READY_STATES.DONE || !responseBytes) {
256
+ res = null;
257
+ }
258
+
259
+ try {
260
+ res = parseJSONFromBytes(responseBytes);
261
+ } catch {
262
+ res = null;
263
+ }
264
+ break;
265
+ }
266
+ }
267
+ this._responseCache = res;
268
+ // Needed because of: https://github.com/jsdom/webidl2js/issues/149
269
+ return idlUtils.tryWrapperForImpl(res);
270
+ }
271
+ get responseText() {
272
+ if (this.responseType !== "" && this.responseType !== "text") {
273
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
274
+ }
275
+ if (this.readyState !== READY_STATES.LOADING && this.readyState !== READY_STATES.DONE) {
276
+ return "";
277
+ }
278
+ if (this._responseTextCache) {
279
+ return this._responseTextCache;
280
+ }
281
+ const responseBytes = this._responseBytes?.slice(0, this._totalReceivedChunkSize) ?? null;
282
+ if (!responseBytes) {
283
+ return "";
284
+ }
285
+
286
+ const fallbackEncodingLabel = finalCharset(this) || getBOMEncoding(responseBytes) || "UTF-8";
287
+ const res = legacyHookDecode(responseBytes, fallbackEncodingLabel);
288
+
289
+ this._responseTextCache = res;
290
+ return res;
291
+ }
292
+ get responseXML() {
293
+ if (this.responseType !== "" && this.responseType !== "document") {
294
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
295
+ }
296
+ if (this.readyState !== READY_STATES.DONE) {
297
+ return null;
298
+ }
299
+ if (this._responseXMLCache) {
300
+ return this._responseXMLCache;
301
+ }
302
+ const responseBytes = this._responseBytes?.slice(0, this._totalReceivedChunkSize) ?? null;
303
+ if (!responseBytes) {
304
+ return null;
305
+ }
306
+
307
+ const contentType = finalMIMEType(this);
308
+ let isHTML = false;
309
+ let isXML = false;
310
+ const parsed = MIMEType.parse(contentType);
311
+ if (parsed) {
312
+ isHTML = parsed.isHTML();
313
+ isXML = parsed.isXML();
314
+ if (!isXML && !isHTML) {
315
+ return null;
316
+ }
317
+ }
318
+
319
+ if (this.responseType === "" && isHTML) {
320
+ return null;
321
+ }
322
+
323
+ const encoding = finalCharset(this) || labelToName(getBOMEncoding(responseBytes)) || "UTF-8";
324
+ const resText = legacyHookDecode(responseBytes, encoding);
325
+
326
+ if (!resText) {
327
+ return null;
328
+ }
329
+ const res = Document.createImpl(this._globalObject, [], {
330
+ options: {
331
+ url: this._url,
332
+ lastModified: new Date(this._responseHeaders.get("last-modified")),
333
+ parsingMode: isHTML ? "html" : "xml",
334
+ cookieJar: { setCookieSync: () => undefined, getCookieStringSync: () => "" },
335
+ encoding,
336
+ parseOptions: this._ownerDocument._parseOptions
337
+ }
338
+ });
339
+ try {
340
+ parseIntoDocument(resText, res);
341
+ } catch {
342
+ this._responseXMLCache = null;
343
+ return null;
344
+ }
345
+ res.close();
346
+ this._responseXMLCache = res;
347
+ return res;
348
+ }
349
+
350
+ get timeout() {
351
+ return this._timeout;
352
+ }
353
+ set timeout(val) {
354
+ if (this._synchronous) {
355
+ throw DOMException.create(this._globalObject, [
356
+ "The object does not support the operation or argument.",
357
+ "InvalidAccessError"
358
+ ]);
359
+ }
360
+ this._timeout = val;
361
+ clearTimeout(this._timeoutId);
362
+ if (val > 0 && this._timeoutFn) {
363
+ this._timeoutId = setTimeout(
364
+ this._timeoutFn,
365
+ Math.max(0, val - ((new Date()).getTime() - this._timeoutStart))
366
+ );
367
+ } else {
368
+ this._timeoutFn = null;
369
+ this._timeoutStart = 0;
370
+ }
371
+ }
372
+
373
+ get withCredentials() {
374
+ return this._withCredentials;
375
+ }
376
+ set withCredentials(val) {
377
+ if (!(this.readyState === READY_STATES.UNSENT || this.readyState === READY_STATES.OPENED)) {
378
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
379
+ }
380
+ if (this._send) {
381
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
382
+ }
383
+ this._withCredentials = val;
384
+ }
385
+
386
+ abort() {
387
+ // Terminate the request
388
+ clearTimeout(this._timeoutId);
389
+ this._timeoutFn = null;
390
+ this._timeoutStart = 0;
391
+
392
+ if (this._controller) {
393
+ this._controller.abort();
394
+ this._controller = null;
395
+ }
396
+
397
+ if (this._abortError) {
398
+ // Special case that ideally shouldn't be going through the public API at all.
399
+ // Run the https://xhr.spec.whatwg.org/#handle-errors "fatal" steps.
400
+ this.readyState = READY_STATES.DONE;
401
+ this._send = false;
402
+ setResponseToNetworkError(this);
403
+ return;
404
+ }
405
+
406
+ if ((this.readyState === READY_STATES.OPENED && this._send) ||
407
+ this.readyState === READY_STATES.HEADERS_RECEIVED ||
408
+ this.readyState === READY_STATES.LOADING) {
409
+ requestErrorSteps(this, "abort");
410
+ }
411
+
412
+ if (this.readyState === READY_STATES.DONE) {
413
+ this.readyState = READY_STATES.UNSENT;
414
+
415
+ setResponseToNetworkError(this);
416
+ }
417
+ }
418
+ getAllResponseHeaders() {
419
+ if (this.readyState === READY_STATES.UNSENT || this.readyState === READY_STATES.OPENED) {
420
+ return "";
421
+ }
422
+ const result = [];
423
+ for (const [key, value] of this._responseHeaders) {
424
+ const lcKey = key.toLowerCase();
425
+ if (!this._filteredResponseHeaders.has(lcKey)) {
426
+ result.push(`${lcKey}: ${value}`);
427
+ }
428
+ }
429
+ return result.join("\r\n");
430
+ }
431
+
432
+ getResponseHeader(header) {
433
+ if (this.readyState === READY_STATES.UNSENT || this.readyState === READY_STATES.OPENED) {
434
+ return null;
435
+ }
436
+ const lcHeader = header.toLowerCase();
437
+ if (this._filteredResponseHeaders.has(lcHeader)) {
438
+ return null;
439
+ }
440
+ return this._responseHeaders.get(lcHeader);
441
+ }
442
+
443
+ open(method, url, asynchronous, user, password) {
444
+ const { _ownerDocument } = this;
445
+ if (!_ownerDocument) {
446
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
447
+ }
448
+
449
+ if (!tokenRegexp.test(method)) {
450
+ throw DOMException.create(this._globalObject, [
451
+ "The string did not match the expected pattern.",
452
+ "SyntaxError"
453
+ ]);
454
+ }
455
+ const upperCaseMethod = method.toUpperCase();
456
+ if (forbiddenRequestMethods.has(upperCaseMethod)) {
457
+ throw DOMException.create(this._globalObject, ["The operation is insecure.", "SecurityError"]);
458
+ }
459
+
460
+ if (this._controller && typeof this._controller.abort === "function") {
461
+ this._controller.abort();
462
+ }
463
+
464
+ if (allowedRequestMethods.has(upperCaseMethod)) {
465
+ method = upperCaseMethod;
466
+ }
467
+ if (typeof asynchronous !== "undefined") {
468
+ this._synchronous = !asynchronous;
469
+ } else {
470
+ this._synchronous = false;
471
+ }
472
+ if (this._responseType && this._synchronous) {
473
+ throw DOMException.create(this._globalObject, [
474
+ "The object does not support the operation or argument.",
475
+ "InvalidAccessError"
476
+ ]);
477
+ }
478
+ if (this._synchronous && this._timeout) {
479
+ throw DOMException.create(this._globalObject, [
480
+ "The object does not support the operation or argument.",
481
+ "InvalidAccessError"
482
+ ]);
483
+ }
484
+ this._method = method;
485
+
486
+ const urlRecord = parseURL(url, { baseURL: _ownerDocument.baseURL() });
487
+ if (!urlRecord) {
488
+ throw DOMException.create(this._globalObject, [
489
+ "The string did not match the expected pattern.",
490
+ "SyntaxError"
491
+ ]);
492
+ }
493
+
494
+ if (user || (password && !urlRecord.username)) {
495
+ this._auth = {
496
+ user,
497
+ pass: password
498
+ };
499
+ urlRecord.username = "";
500
+ urlRecord.password = "";
501
+ }
502
+
503
+ this._url = serializeURL(urlRecord);
504
+ this._requestHeaders = new HeaderList();
505
+ this._preflight = false;
506
+
507
+ this._send = false;
508
+ this._uploadListener = false;
509
+ this._body = undefined;
510
+ this._abortError = false;
511
+
512
+ this._responseBytes = null;
513
+ this._responseCache = null;
514
+ this._responseTextCache = null;
515
+ this._responseXMLCache = null;
516
+ this._responseHeaders = new HeaderList();
517
+ this._totalReceivedChunkSize = 0;
518
+ this.responseURL = "";
519
+ this.status = 0;
520
+ this.statusText = "";
521
+
522
+ readyStateChange(this, READY_STATES.OPENED);
523
+ }
524
+
525
+ overrideMimeType(mime) {
526
+ if (this.readyState === READY_STATES.LOADING || this.readyState === READY_STATES.DONE) {
527
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
528
+ }
529
+
530
+ this._overrideMIMEType = "application/octet-stream";
531
+
532
+ // Waiting for better spec: https://github.com/whatwg/xhr/issues/157
533
+ const parsed = MIMEType.parse(mime);
534
+ if (parsed) {
535
+ this._overrideMIMEType = parsed.essence;
536
+
537
+ const charset = parsed.parameters.get("charset");
538
+ if (charset) {
539
+ this._overrideCharset = labelToName(charset);
540
+ }
541
+ }
542
+ }
543
+
544
+ // TODO: Add support for URLSearchParams and ReadableStream
545
+ send(body) {
546
+ const { upload, _ownerDocument } = this;
547
+ // Not per spec, but per tests: https://github.com/whatwg/xhr/issues/65
548
+ if (!_ownerDocument) {
549
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
550
+ }
551
+
552
+ if (this.readyState !== READY_STATES.OPENED || this._send) {
553
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
554
+ }
555
+
556
+ this._beforeSend = true;
557
+
558
+ try {
559
+ if (this._method === "GET" || this._method === "HEAD") {
560
+ body = null;
561
+ }
562
+
563
+ if (body !== null) {
564
+ let extractedContentType = null;
565
+
566
+ if (Document.isImpl(body)) {
567
+ // Note: our utf8Encode() does both USVString conversion and UTF-8 encoding.
568
+ this._body = utf8Encode(fragmentSerialization(body, { requireWellFormed: false }));
569
+ } else {
570
+ const { body: extractedBody, type } = extractBody(body);
571
+ this._body = extractedBody;
572
+ extractedContentType = type;
573
+ }
574
+
575
+ const originalAuthorContentType = this._requestHeaders.get("content-type");
576
+
577
+ if (originalAuthorContentType !== null) {
578
+ if (Document.isImpl(body) || typeof body === "string") {
579
+ const parsed = MIMEType.parse(originalAuthorContentType);
580
+ if (parsed) {
581
+ const charset = parsed.parameters.get("charset");
582
+ if (charset && !asciiCaseInsensitiveMatch(charset, "UTF-8")) {
583
+ parsed.parameters.set("charset", "UTF-8");
584
+ this._requestHeaders.set("Content-Type", parsed.toString());
585
+ }
586
+ }
587
+ }
588
+ } else if (Document.isImpl(body)) {
589
+ if (body._parsingMode === "html") {
590
+ this._requestHeaders.set("Content-Type", "text/html;charset=UTF-8");
591
+ } else {
592
+ this._requestHeaders.set("Content-Type", "application/xml;charset=UTF-8");
593
+ }
594
+ } else if (extractedContentType !== null) {
595
+ this._requestHeaders.set("Content-Type", extractedContentType);
596
+ }
597
+ }
598
+ } finally {
599
+ if (this._beforeSend) {
600
+ this._beforeSend = false;
601
+ } else {
602
+ throw DOMException.create(this._globalObject, ["The object is in an invalid state.", "InvalidStateError"]);
603
+ }
604
+ }
605
+
606
+ if (Object.keys(upload._eventListeners).length > 0) {
607
+ this._uploadListener = true;
608
+ }
609
+
610
+ // request doesn't like zero-length bodies
611
+ if (this._body && this._body.byteLength === 0) {
612
+ this._body = null;
613
+ }
614
+
615
+ // Per XHR spec step 11: "If req's body is null, then set this's upload complete flag."
616
+ // This prevents upload events from firing for GET/HEAD and other bodyless requests.
617
+ // Note: this._body may be undefined (for GET/HEAD) or null (for zero-length bodies).
618
+ if (!this._body) {
619
+ this._uploadComplete = true;
620
+ }
621
+
622
+ if (this._synchronous) {
623
+ this._adoptSerializedResponse(sendSyncWorkerRequest(this._serializeRequest()));
624
+
625
+ this.readyState = READY_STATES.LOADING;
626
+
627
+ if (this._error) {
628
+ dispatchError(this, this._error);
629
+ throw DOMException.create(this._globalObject, [this._error, "NetworkError"]);
630
+ } else {
631
+ const contentLength = this._responseHeaders.get("content-length") || "0";
632
+ const byteLength = parseInt(contentLength) || this._responseBytes.length;
633
+ const progressObj = { lengthComputable: false };
634
+ if (byteLength !== 0) {
635
+ progressObj.total = byteLength;
636
+ progressObj.loaded = byteLength;
637
+ progressObj.lengthComputable = true;
638
+ }
639
+ fireAnEvent("progress", this, ProgressEvent, progressObj);
640
+ readyStateChange(this, READY_STATES.DONE);
641
+ fireAnEvent("load", this, ProgressEvent, progressObj);
642
+ fireAnEvent("loadend", this, ProgressEvent, progressObj);
643
+ }
644
+ } else {
645
+ this._send = true;
646
+ this._totalReceivedChunkSize = 0;
647
+ this._bufferStepSize = 1 * 1024 * 1024;
648
+
649
+ if (body !== null && body !== "") {
650
+ this._uploadComplete = false;
651
+ } else {
652
+ this._uploadComplete = true;
653
+ }
654
+
655
+ // State for upload progress - use this._body which is the processed Uint8Array
656
+ const uploadTotal = this._body ? this._body.byteLength : 0;
657
+ const uploadProgress = {
658
+ lengthComputable: uploadTotal > 0,
659
+ total: uploadTotal,
660
+ loaded: 0
661
+ };
662
+
663
+ // Create abort controller BEFORE firing loadstart so open() called in
664
+ // loadstart handler can properly abort this request
665
+ const abortController = new AbortController();
666
+ this._controller = abortController;
667
+
668
+ // Register with request manager so window.close()/stop() can abort this request
669
+ const requestManagerEntry = {
670
+ abort: () => {
671
+ this._abortError = true;
672
+ abortController.abort();
673
+ }
674
+ };
675
+ if (this._requestManager) {
676
+ this._requestManager.add(requestManagerEntry);
677
+ }
678
+
679
+ // Per XHR spec, fire loadstart on xhr first, then on upload.
680
+ fireAnEvent("loadstart", this, ProgressEvent);
681
+
682
+ if (!this._uploadComplete && this._uploadListener) {
683
+ fireAnEvent("loadstart", upload, ProgressEvent, uploadProgress);
684
+ }
685
+
686
+ // Per XHR spec: "If this's state is not opened or this's send() flag is unset, return."
687
+ // Also check if this request was aborted (e.g., by open() called in loadstart handler)
688
+ if (this.readyState !== READY_STATES.OPENED || !this._send || abortController.signal.aborted) {
689
+ if (this._requestManager) {
690
+ this._requestManager.remove(requestManagerEntry);
691
+ }
692
+ return;
693
+ }
694
+
695
+ // Async fetch and body streaming
696
+ (async () => {
697
+ try {
698
+ const response = await performFetch(
699
+ this._dispatcher,
700
+ {
701
+ url: this._url,
702
+ method: this._method,
703
+ requestHeaders: this._requestHeaders,
704
+ body: this._body,
705
+ origin: this._origin,
706
+ referrer: this._referrer,
707
+ userAgent: this._userAgent,
708
+ withCredentials: this._withCredentials,
709
+ auth: this._auth,
710
+ cookieJar: this._cookieJar,
711
+ uploadListener: this._uploadListener
712
+ },
713
+ abortController.signal
714
+ );
715
+
716
+ // Handle network errors (includes CORS failures)
717
+ if (isNetworkError(response)) {
718
+ if (abortController.signal.aborted) {
719
+ // Request was aborted - don't fire error events
720
+ return;
721
+ }
722
+ dispatchError(this, response.error?.message || "Network error");
723
+ return;
724
+ }
725
+
726
+ // Fire upload complete events
727
+ if (!this._uploadComplete) {
728
+ this._uploadComplete = true;
729
+ if (this._uploadListener) {
730
+ uploadProgress.loaded = uploadProgress.total;
731
+ fireAnEvent("progress", upload, ProgressEvent, uploadProgress);
732
+ fireAnEvent("load", upload, ProgressEvent, uploadProgress);
733
+ fireAnEvent("loadend", upload, ProgressEvent, uploadProgress);
734
+ }
735
+ }
736
+
737
+ // Process response headers (CORS filtering done by performFetch)
738
+ const { headers, filteredResponseHeaders } = response;
739
+
740
+ this.responseURL = response.url;
741
+ this.status = response.status;
742
+ this.statusText = response.statusText;
743
+ this._responseHeaders = headers;
744
+ this._filteredResponseHeaders = filteredResponseHeaders;
745
+
746
+ // Set up progress tracking
747
+ // If content-encoding is set, the body was compressed and we report decompressed bytes,
748
+ // so lengthComputable must be false (method b from the XHR spec)
749
+ const contentEncoding = headers.get("content-encoding");
750
+ const contentLength = headers.get("content-length") || "0";
751
+ const bufferLength = parseInt(contentLength) || 0;
752
+ const progressObj = { lengthComputable: false, loaded: 0, total: 0 };
753
+ if (bufferLength !== 0 && !contentEncoding) {
754
+ progressObj.total = bufferLength;
755
+ progressObj.lengthComputable = true;
756
+ }
757
+
758
+ // Pre-allocate buffer
759
+ this._responseBytes = new Uint8Array(this._bufferStepSize);
760
+ this._responseCache = null;
761
+ this._responseTextCache = null;
762
+ this._responseXMLCache = null;
763
+
764
+ readyStateChange(this, READY_STATES.HEADERS_RECEIVED);
765
+
766
+ // Track progress for deduplication
767
+ let lastProgressReported;
768
+
769
+ // Stream the response body
770
+ if (response.body) {
771
+ for await (const chunk of response.body) {
772
+ // Check if aborted
773
+ if (abortController.signal.aborted) {
774
+ break;
775
+ }
776
+
777
+ // Store decompressed bytes
778
+ this._totalReceivedChunkSize += chunk.length;
779
+ if (this._totalReceivedChunkSize >= this._bufferStepSize) {
780
+ this._bufferStepSize *= 2;
781
+ while (this._totalReceivedChunkSize >= this._bufferStepSize) {
782
+ this._bufferStepSize *= 2;
783
+ }
784
+ const tmpBuf = new Uint8Array(this._bufferStepSize);
785
+ tmpBuf.set(this._responseBytes);
786
+ this._responseBytes = tmpBuf;
787
+ }
788
+ this._responseBytes.set(chunk, this._totalReceivedChunkSize - chunk.length);
789
+ this._responseCache = null;
790
+ this._responseTextCache = null;
791
+ this._responseXMLCache = null;
792
+
793
+ if (this.readyState === READY_STATES.HEADERS_RECEIVED) {
794
+ this.readyState = READY_STATES.LOADING;
795
+ }
796
+ fireAnEvent("readystatechange", this);
797
+
798
+ progressObj.loaded = this._totalReceivedChunkSize;
799
+ if (lastProgressReported !== progressObj.loaded) {
800
+ lastProgressReported = progressObj.loaded;
801
+ fireAnEvent("progress", this, ProgressEvent, progressObj);
802
+ }
803
+ }
804
+ }
805
+
806
+ // Request complete - trim the pre-allocated buffer to actual size (zero-copy when available)
807
+ if (this._responseBytes) {
808
+ this._responseBytes = trimUint8Array(this._responseBytes, this._totalReceivedChunkSize);
809
+ }
810
+ clearTimeout(this._timeoutId);
811
+ this._timeoutFn = null;
812
+ this._timeoutStart = 0;
813
+ this._controller = null;
814
+
815
+ if (this._requestManager) {
816
+ this._requestManager.remove(requestManagerEntry);
817
+ }
818
+
819
+ // Don't fire completion events if aborted
820
+ if (abortController.signal.aborted) {
821
+ return;
822
+ }
823
+
824
+ // Fire final progress if not already fired with this loaded value
825
+ if (lastProgressReported !== progressObj.loaded) {
826
+ fireAnEvent("progress", this, ProgressEvent, progressObj);
827
+ }
828
+ readyStateChange(this, READY_STATES.DONE);
829
+ fireAnEvent("load", this, ProgressEvent, progressObj);
830
+ fireAnEvent("loadend", this, ProgressEvent, progressObj);
831
+ } catch (err) {
832
+ this._controller = null;
833
+ if (this._requestManager) {
834
+ this._requestManager.remove(requestManagerEntry);
835
+ }
836
+ // Don't fire error events if aborted
837
+ if (!abortController.signal.aborted) {
838
+ dispatchError(this, err.message || String(err));
839
+ }
840
+ }
841
+ })();
842
+
843
+ if (this.timeout > 0) {
844
+ this._timeoutStart = (new Date()).getTime();
845
+ this._timeoutFn = () => {
846
+ this._controller?.abort();
847
+ if (!(this.readyState === READY_STATES.UNSENT ||
848
+ (this.readyState === READY_STATES.OPENED && !this._send) ||
849
+ this.readyState === READY_STATES.DONE)) {
850
+ this._send = false;
851
+ let stateChanged = false;
852
+ if (!this._uploadComplete) {
853
+ fireAnEvent("progress", upload, ProgressEvent);
854
+ readyStateChange(this, READY_STATES.DONE);
855
+ fireAnEvent("timeout", upload, ProgressEvent);
856
+ fireAnEvent("loadend", upload, ProgressEvent);
857
+ stateChanged = true;
858
+ }
859
+ fireAnEvent("progress", this, ProgressEvent);
860
+ if (!stateChanged) {
861
+ readyStateChange(this, READY_STATES.DONE);
862
+ }
863
+ fireAnEvent("timeout", this, ProgressEvent);
864
+ fireAnEvent("loadend", this, ProgressEvent);
865
+ }
866
+ this.readyState = READY_STATES.UNSENT;
867
+ };
868
+ this._timeoutId = setTimeout(this._timeoutFn, this.timeout);
869
+ }
870
+ }
871
+ }
872
+
873
+ setRequestHeader(header, value) {
874
+ if (this.readyState !== READY_STATES.OPENED) {
875
+ throw DOMException.create(
876
+ this._globalObject,
877
+ ["setRequestHeader() can only be called in the OPENED state.", "InvalidStateError"]
878
+ );
879
+ }
880
+ if (this._send) {
881
+ throw DOMException.create(
882
+ this._globalObject,
883
+ ["setRequestHeader() cannot be called after send()", "InvalidStateError"]
884
+ );
885
+ }
886
+
887
+ value = normalizeHeaderValue(value);
888
+
889
+ if (!isHeaderName(header)) {
890
+ throw DOMException.create(this._globalObject, ["Invalid header name", "SyntaxError"]);
891
+ }
892
+ if (!isHeaderValue(value)) {
893
+ throw DOMException.create(this._globalObject, ["Invalid header value", "SyntaxError"]);
894
+ }
895
+
896
+ if (isForbiddenRequestHeader(header, value)) {
897
+ return;
898
+ }
899
+
900
+ this._requestHeaders.combine(header, value);
901
+ }
902
+
903
+ // Serialization methods for sync XHR worker communication
904
+
905
+ // Called in main process before spawning sync worker
906
+ _serializeRequest() {
907
+ return {
908
+ method: this._method,
909
+ url: this._url,
910
+ body: this._body,
911
+ requestHeaders: this._requestHeaders.toJSON(),
912
+ withCredentials: this._withCredentials,
913
+ mimeType: this._mimeType,
914
+ auth: this._auth,
915
+ responseType: this._responseType,
916
+ timeout: this._timeout,
917
+ preflight: this._preflight,
918
+ cookieJar: this._cookieJar.serializeSync(),
919
+ encoding: this._encoding,
920
+ origin: this._origin,
921
+ referrer: this._referrer,
922
+ userAgent: this._userAgent
923
+ };
924
+ }
925
+
926
+ // Called in main process after sync worker returns
927
+ _adoptSerializedResponse(response) {
928
+ this.status = response.status;
929
+ this.statusText = response.statusText;
930
+ this.responseURL = response.responseURL;
931
+
932
+ if (response.responseBytes) {
933
+ this._responseBytes = trimUint8Array(response.responseBytes, response.totalReceivedChunkSize);
934
+ this._totalReceivedChunkSize = response.totalReceivedChunkSize;
935
+ }
936
+ this._responseHeaders = HeaderList.fromJSON(response.responseHeaders);
937
+ this._filteredResponseHeaders = response.filteredResponseHeaders;
938
+ this._error = response.error || "";
939
+ this._uploadComplete = response.uploadComplete;
940
+
941
+ if (response.cookieJar) {
942
+ this._cookieJar = tough.CookieJar.deserializeSync(
943
+ response.cookieJar,
944
+ this._ownerDocument._cookieJar.store
945
+ );
946
+ }
947
+ }
948
+
949
+ // Called in worker to set up XHR from serialized config
950
+ _adoptSerializedRequest(config) {
951
+ this._method = config.method;
952
+ this._url = config.url;
953
+ this._body = config.body;
954
+ this._requestHeaders = HeaderList.fromJSON(config.requestHeaders);
955
+ this._synchronous = false; // Run as async in worker
956
+ this._withCredentials = config.withCredentials;
957
+ this._mimeType = config.mimeType;
958
+ this._auth = config.auth;
959
+ this._responseType = config.responseType;
960
+ this._timeout = config.timeout;
961
+ this._preflight = config.preflight;
962
+ this._cookieJar = config.cookieJar ?
963
+ tough.CookieJar.deserializeSync(config.cookieJar) :
964
+ null;
965
+ this._encoding = config.encoding;
966
+ this._origin = config.origin;
967
+ this._referrer = config.referrer;
968
+ this._userAgent = config.userAgent;
969
+
970
+ this.readyState = READY_STATES.OPENED;
971
+ }
972
+
973
+ // Called in worker to serialize response
974
+ _serializeResponse() {
975
+ let error = this._error;
976
+ if (error && typeof error !== "string") {
977
+ error = error.stack || inspect(error);
978
+ }
979
+
980
+ return {
981
+ status: this.status,
982
+ statusText: this.statusText,
983
+ responseURL: this.responseURL,
984
+ responseBytes: this._responseBytes,
985
+ totalReceivedChunkSize: this._totalReceivedChunkSize,
986
+ responseHeaders: this._responseHeaders.toJSON(),
987
+ filteredResponseHeaders: this._filteredResponseHeaders,
988
+ error,
989
+ uploadComplete: this._uploadComplete,
990
+ cookieJar: this._cookieJar.serializeSync()
991
+ };
992
+ }
993
+ }
994
+
995
+ setupForSimpleEventAccessors(XMLHttpRequestImpl.prototype, ["readystatechange"]);
996
+
997
+ function readyStateChange(xhr, readyState) {
998
+ if (xhr.readyState === readyState) {
999
+ return;
1000
+ }
1001
+
1002
+ xhr.readyState = readyState;
1003
+
1004
+ fireAnEvent("readystatechange", xhr);
1005
+ }
1006
+
1007
+ function finalMIMEType(xhr) {
1008
+ return xhr._overrideMIMEType || xhr._responseHeaders.get("content-type");
1009
+ }
1010
+
1011
+ function finalCharset(xhr) {
1012
+ if (xhr._overrideCharset) {
1013
+ return xhr._overrideCharset;
1014
+ }
1015
+ const parsedContentType = MIMEType.parse(xhr._responseHeaders.get("content-type"));
1016
+ if (parsedContentType) {
1017
+ return labelToName(parsedContentType.parameters.get("charset"));
1018
+ }
1019
+ return null;
1020
+ }
1021
+
1022
+ function extractBody(bodyInit) {
1023
+ // https://fetch.spec.whatwg.org/#concept-bodyinit-extract
1024
+ // We represent the body as a `Uint8Array`.
1025
+
1026
+ if (Blob.isImpl(bodyInit)) {
1027
+ return {
1028
+ body: bodyInit._bytes,
1029
+ type: bodyInit.type === "" ? null : bodyInit.type
1030
+ };
1031
+ } else if (idlUtils.isArrayBuffer(bodyInit)) {
1032
+ return {
1033
+ body: new Uint8Array(bodyInit).slice(0),
1034
+ type: null
1035
+ };
1036
+ } else if (ArrayBuffer.isView(bodyInit)) {
1037
+ return {
1038
+ body: new Uint8Array(bodyInit),
1039
+ type: null
1040
+ };
1041
+ } else if (FormData.isImpl(bodyInit)) {
1042
+ const { boundary, outputChunks } = serializeEntryList(bodyInit._entries);
1043
+
1044
+ return {
1045
+ body: concatTypedArrays(outputChunks),
1046
+ type: "multipart/form-data; boundary=" + utf8Decode(boundary)
1047
+ };
1048
+ }
1049
+
1050
+ // Must be a string
1051
+ return {
1052
+ body: utf8Encode(bodyInit),
1053
+ type: "text/plain;charset=UTF-8"
1054
+ };
1055
+ }
1056
+
1057
+ exports.implementation = XMLHttpRequestImpl;