blob: ef0e6601a51093926267f9b0e9c6ec41553c622f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
import html/event
import js/javascript
type
XMLHttpRequestResponseType = enum
TYPE_UNKNOWN = ""
TYPE_ARRAYBUFFER = "arraybuffer"
TYPE_BLOB = "blob"
TYPE_DOCUMENT = "document"
TYPE_JSON = "json"
TYPE_TEXT = "text"
XMLHttpRequestEventTarget = ref object of EventTarget
onloadstart {.jsgetset.}: EventHandler
onprogress {.jsgetset.}: EventHandler
onabort {.jsgetset.}: EventHandler
onerror {.jsgetset.}: EventHandler
onload {.jsgetset.}: EventHandler
ontimeout {.jsgetset.}: EventHandler
onloadend {.jsgetset.}: EventHandler
XMLHttpRequestUpload = ref object of XMLHttpRequestEventTarget
XMLHttpRequest = ref object of XMLHttpRequestEventTarget
onreadystatechange {.jsgetset.}: EventHandler
readyState {.jsget.}: uint16
upload {.jsget.}: XMLHttpRequestUpload
jsDestructor(XMLHttpRequestEventTarget)
jsDestructor(XMLHttpRequestUpload)
jsDestructor(XMLHttpRequest)
func newXMLHttpRequest(): XMLHttpRequest {.jsctor.} =
let upload = XMLHttpRequestUpload()
return XMLHttpRequest(
upload: upload
)
proc open(this: XMLHttpRequest, httpMethod, url: string) {.jsfunc.} =
discard #TODO implement
proc addXMLHttpRequestModule*(ctx: JSContext) =
let eventTargetCID = ctx.getClass("EventTarget")
let xhretCID = ctx.registerType(XMLHttpRequestEventTarget, eventTargetCID)
ctx.registerType(XMLHttpRequestUpload, xhretCID)
ctx.registerType(XMLHttpRequest, xhretCID)
|