diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config/config.nim | 7 | ||||
-rw-r--r-- | src/html/dom.nim | 16 | ||||
-rw-r--r-- | src/html/env.nim | 14 | ||||
-rw-r--r-- | src/local/pager.nim | 9 | ||||
-rw-r--r-- | src/types/url.nim | 8 |
5 files changed, 29 insertions, 25 deletions
diff --git a/src/config/config.nim b/src/config/config.nim index f992657f..e5a33f61 100644 --- a/src/config/config.nim +++ b/src/config/config.nim @@ -261,10 +261,11 @@ func getRealKey(key: string): string = realk &= '\\' return realk -proc getter(a: var ActionMap; s: string): Option[string] {.jsgetownprop.} = +proc getter(ctx: JSContext; a: var ActionMap; s: string): JSValue + {.jsgetownprop.} = a.t.withValue(s, p): - return some(p[]) - return none(string) + return ctx.toJS(p[]) + return JS_NULL proc setter(a: var ActionMap; k, v: string) {.jssetprop.} = let k = getRealKey(k) diff --git a/src/html/dom.nim b/src/html/dom.nim index 151e5a6f..e1f841e7 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1977,19 +1977,19 @@ func hasAttributeNS(element: Element; namespace, localName: string): bool {.jsfunc.} = return element.findAttrNS(namespace, localName) != -1 -func getAttribute(element: Element; qualifiedName: string): Option[string] - {.jsfunc.} = +func getAttribute(ctx: JSContext; element: Element; qualifiedName: string): + JSValue {.jsfunc.} = let i = element.findAttr(qualifiedName) if i != -1: - return some(element.attrs[i].value) - return none(string) + return ctx.toJS(element.attrs[i].value) + return JS_NULL -func getAttributeNS(element: Element; namespace, localName: string): - Option[string] {.jsfunc.} = +func getAttributeNS(ctx: JSContext; element: Element; + namespace, localName: string): JSValue {.jsfunc.} = let i = element.findAttrNS(namespace, localName) if i != -1: - return some(element.attrs[i].value) - return none(string) + return ctx.toJS(element.attrs[i].value) + return JS_NULL proc getNamedItem(map: NamedNodeMap; qualifiedName: string): Attr {.jsfunc.} = diff --git a/src/html/env.nim b/src/html/env.nim index d7c91281..cb38fd1c 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -117,16 +117,16 @@ func find(this: Storage; key: string): int = func length(this: var Storage): uint32 {.jsfget.} = return uint32(this.map.len) -func key(this: var Storage; i: uint32): Option[string] {.jsfunc.} = +func key(ctx: JSContext; this: var Storage; i: uint32): JSValue {.jsfunc.} = if int(i) < this.map.len: - return some(this.map[int(i)].value) - return none(string) + return ctx.toJS(this.map[int(i)].value) + return JS_NULL -func getItem(this: var Storage; s: string): Option[string] {.jsfunc.} = +func getItem(ctx: JSContext; this: var Storage; s: string): JSValue {.jsfunc.} = let i = this.find(s) if i != -1: - return some(this.map[i].value) - return none(string) + return ctx.toJS(this.map[i].value) + return JS_NULL func setItem(this: var Storage; key, value: string): Err[DOMException] {.jsfunc.} = @@ -153,7 +153,7 @@ func names(ctx: JSContext; this: var Storage): JSPropertyEnumList func getter(ctx: JSContext; this: var Storage; s: string): JSValue {.jsgetownprop.} = - return ctx.toJS(this.getItem(s)).uninitIfNull() + return ctx.toJS(ctx.getItem(this, s)).uninitIfNull() func setter(this: var Storage; k, v: string): Err[DOMException] {.jssetprop.} = diff --git a/src/local/pager.nim b/src/local/pager.nim index b563ccfc..2d5f7ec4 100644 --- a/src/local/pager.nim +++ b/src/local/pager.nim @@ -2317,12 +2317,13 @@ proc extern(pager: Pager; cmd: string; t = ExternDict(env: JS_UNDEFINED, suspend: true)): bool {.jsfunc.} = return pager.runCommand(cmd, t.suspend, t.wait, t.env) -proc externCapture(pager: Pager; cmd: string): Option[string] {.jsfunc.} = +proc externCapture(ctx: JSContext; pager: Pager; cmd: string): JSValue + {.jsfunc.} = pager.setEnvVars(JS_UNDEFINED) var s: string - if not runProcessCapture(cmd, s): - return none(string) - return some(s) + if runProcessCapture(cmd, s): + return ctx.toJS(s) + return JS_NULL proc externInto(pager: Pager; cmd, ins: string): bool {.jsfunc.} = pager.setEnvVars(JS_UNDEFINED) diff --git a/src/types/url.nim b/src/types/url.nim index cca36eea..c2d6e075 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -12,6 +12,7 @@ import monoucha/javascript import monoucha/jserror import monoucha/libunicode import monoucha/quickjs +import monoucha/tojs import types/opt import utils/luwrap import utils/map @@ -1111,11 +1112,12 @@ proc delete(params: URLSearchParams; name: string) {.jsfunc.} = params.list.delete(i) params.update() -proc get(params: URLSearchParams; name: string): Option[string] {.jsfunc.} = +proc get(ctx: JSContext; params: URLSearchParams; name: string): JSValue + {.jsfunc.} = for it in params.list: if it.name == name: - return some(it.value) - return none(string) + return ctx.toJS(it.value) + return JS_NULL proc getAll(params: URLSearchParams; name: string): seq[string] {.jsfunc.} = result = @[] |