aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-09-16 03:46:13 +0200
committerbptato <nincsnevem662@gmail.com>2022-09-16 03:48:36 +0200
commit23caa878a3854dd0118792e1c051b5412ec345cc (patch)
tree0294ecb329765ed7f8960182224f397c46407580 /src
parent3f96681261692feedadfb8c488f3908dd80bb01c (diff)
downloadchawan-23caa878a3854dd0118792e1c051b5412ec345cc.tar.gz
Rename jsget/jsset to jsfget/jsfset for functions
The original idea was to use the same pragmas as object members, but unfortunately this doesn't seem to work consistently after all.
Diffstat (limited to 'src')
-rw-r--r--src/bindings/quickjs.nim2
-rw-r--r--src/html/dom.nim10
-rw-r--r--src/js/javascript.nim10
-rw-r--r--src/types/url.nim30
4 files changed, 27 insertions, 25 deletions
diff --git a/src/bindings/quickjs.nim b/src/bindings/quickjs.nim
index 661b08b6..d216f6cf 100644
--- a/src/bindings/quickjs.nim
+++ b/src/bindings/quickjs.nim
@@ -56,7 +56,7 @@ when sizeof(int) < sizeof(int64):
cast[pointer](v)
template JS_MKVAL*(t, val: untyped): JSValue =
- JSValue((uint64(t) shl 32) or uint32(val))
+ JSValue((cast[uint64](t) shl 32) or cast[uint32](val))
template JS_MKPTR*(t, p: untyped): JSValue =
JSValue((cast[uint64](t) shl 32) or cast[uint](p))
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 278a4c5e..acfe2a22 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -228,7 +228,7 @@ iterator children_rev*(node: Node): Element {.inline.} =
yield Element(child)
#TODO TODO TODO this should return a live view instead
-proc children*(node: Node): seq[Element] {.jsget.} =
+proc children*(node: Node): seq[Element] {.jsfget.} =
for child in node.children:
result.add(child)
@@ -448,14 +448,14 @@ func attrb*(element: Element, s: string): bool =
return true
return false
-func innerHTML*(element: Element): string {.jsget.} =
+func innerHTML*(element: Element): string {.jsfget.} =
for child in element.childNodes:
result &= $child
-func outerHTML*(element: Element): string {.jsget.} =
+func outerHTML*(element: Element): string {.jsfget.} =
return $element
-func textContent*(node: Node): string {.jsget.} =
+func textContent*(node: Node): string {.jsfget.} =
case node.nodeType
of DOCUMENT_NODE, DOCUMENT_TYPE_NODE:
return "" #TODO null
@@ -756,7 +756,7 @@ func text*(option: HTMLOptionElement): string =
if child.parentElement.tagType != TAG_SCRIPT: #TODO svg
result &= child.data.stripAndCollapse()
-func value*(option: HTMLOptionElement): string {.jsget.} =
+func value*(option: HTMLOptionElement): string {.jsfget.} =
if option.attrb("value"):
return option.attr("value")
return option.childTextContent.stripAndCollapse()
diff --git a/src/js/javascript.nim b/src/js/javascript.nim
index 4ed14212..798b2180 100644
--- a/src/js/javascript.nim
+++ b/src/js/javascript.nim
@@ -309,7 +309,9 @@ func newJSClass*(ctx: JSContext, cdef: JSClassDefConst, cctor: JSCFunction, func
proc callFunction*(fun: JSObject): JSObject =
result.ctx = fun.ctx
+ let global = JS_GetGlobalObject(fun.ctx)
result.val = JS_Call(fun.ctx, fun.val, JS_UNDEFINED, 0, nil)
+ JS_FreeValue(fun.ctx, global)
proc callFunction*(fun: JSObject, this: JSObject): JSObject =
result.ctx = fun.ctx
@@ -1089,7 +1091,7 @@ macro jsctor*(fun: typed) =
gen.registerFunction()
result = newStmtList(fun)
-macro jsget*(fun: typed) =
+macro jsfget*(fun: typed) =
var gen = setupGenerator(fun)
gen.newName = "js_get_" & gen.funcParams[0][0] & '_' & gen.funcName
gen.thisType = $gen.funcParams[0][1]
@@ -1106,7 +1108,7 @@ macro jsget*(fun: typed) =
gen.registerFunction()
result = newStmtList(fun, jsProc)
-macro jsset*(fun: typed) =
+macro jsfset*(fun: typed) =
var gen = setupGenerator(fun)
gen.newName = "js_set_" & gen.funcParams[0][0] & '_' & gen.funcName
gen.thisType = $gen.funcParams[0][1]
@@ -1151,8 +1153,8 @@ macro jsfunc*(fun: typed) =
gen.registerFunction()
result = newStmtList(fun, jsProc)
-#WARNING footgun ahead: for some reason, these must be declared *after* their
-# macro counterparts, or they override the macros.
+# Having the same names for these and the macros leads to weird bugs, so the
+# macros get an additional f.
template jsget*() {.pragma.}
template jsset*() {.pragma.}
diff --git a/src/types/url.nim b/src/types/url.nim
index ef5c32ae..8d274b57 100644
--- a/src/types/url.nim
+++ b/src/types/url.nim
@@ -965,7 +965,7 @@ proc newURL*(s: string, base: Option[string] = none(string)): URL {.jserr, jscto
url.get.searchParams.initURLSearchParams(url.get.query.get(""))
return url.get
-proc origin*(url: URL): string {.jsget.} =
+proc origin*(url: URL): string {.jsfget.} =
case url.scheme
of "blob":
if url.blob.issome:
@@ -990,39 +990,39 @@ proc origin*(url: URL): string {.jsget.} =
else:
return "null"
-proc protocol*(url: URL): string {.jsget.} =
+proc protocol*(url: URL): string {.jsfget.} =
return url.scheme & ':'
-proc protocol*(url: URL, s: string) {.jsset.} =
+proc protocol*(url: URL, s: string) {.jsfset.} =
discard basicParseUrl(s & ':', url = url, stateOverride = some(SCHEME_START_STATE))
-proc username*(url: URL, username: string) {.jsset.} =
+proc username*(url: URL, username: string) {.jsfset.} =
if not url.canHaveUsernamePasswordPort:
return
url.username = username.percentEncode(UserInfoPercentEncodeSet)
-proc password*(url: URL, password: string) {.jsset.} =
+proc password*(url: URL, password: string) {.jsfset.} =
if not url.canHaveUsernamePasswordPort:
return
url.password = password.percentEncode(UserInfoPercentEncodeSet)
-proc host*(url: URL): string {.jsget.} =
+proc host*(url: URL): string {.jsfget.} =
if url.host.isnone:
return ""
if url.port.isnone:
return url.host.get.serialize()
return url.host.get.serialize() & ':' & $url.port.get
-proc host*(url: URL, s: string) {.jsset.} =
+proc host*(url: URL, s: string) {.jsfset.} =
if url.path.opaque:
return
discard basicParseUrl(s, url = url, stateOverride = some(HOST_STATE))
-proc port*(url: URL): string {.jsget.} =
+proc port*(url: URL): string {.jsfget.} =
if url.port.issome:
return $url.port.get
-proc port*(url: URL, s: string) {.jsset.} =
+proc port*(url: URL, s: string) {.jsfset.} =
if not url.canHaveUsernamePasswordPort:
return
if s == "":
@@ -1030,21 +1030,21 @@ proc port*(url: URL, s: string) {.jsset.} =
else:
discard basicParseUrl(s, url = url, stateOverride = some(PORT_STATE))
-proc pathname*(url: URL): string {.jsget.} =
+proc pathname*(url: URL): string {.jsfget.} =
return url.path.serialize()
-proc pathname*(url: URL, s: string) {.jsset.} =
+proc pathname*(url: URL, s: string) {.jsfset.} =
if url.path.opaque:
return
url.path.ss.setLen(0)
discard basicParseUrl(s, url = url, stateOverride = some(PATH_START_STATE))
-proc search*(url: URL): string {.jsget.} =
+proc search*(url: URL): string {.jsfget.} =
if url.query.get("") == "":
return ""
return "?" & url.query.get
-proc search*(url: URL, s: string) {.jsset.} =
+proc search*(url: URL, s: string) {.jsfset.} =
if s == "":
url.query = none(string)
url.searchParams.list.setLen(0)
@@ -1054,12 +1054,12 @@ proc search*(url: URL, s: string) {.jsset.} =
discard basicParseUrl(s, url = url, stateOverride = some(QUERY_STATE))
url.searchParams.list = parseApplicationXWWWFormUrlEncoded(s)
-proc hash*(url: URL): string {.jsget.} =
+proc hash*(url: URL): string {.jsfget.} =
if url.fragment.get("") == "":
return ""
return '#' & url.fragment.get
-proc hash*(url: URL, s: string) {.jsset.} =
+proc hash*(url: URL, s: string) {.jsfset.} =
if s == "":
url.fragment = none(string)
return