diff options
-rw-r--r-- | src/html/chadombuilder.nim | 16 | ||||
-rw-r--r-- | src/js/javascript.nim | 7 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/html/chadombuilder.nim b/src/html/chadombuilder.nim index f089b134..da10af20 100644 --- a/src/html/chadombuilder.nim +++ b/src/html/chadombuilder.nim @@ -187,7 +187,6 @@ proc newChaDOMBuilder(url: URL, window: Window): ChaDOMBuilder = #TODO isSVGIntegrationPoint (SVG support) ) -#TODO we shouldn't allow passing nil to window proc parseHTML*(inputStream: Stream, window: Window, url: URL, charsets: seq[Charset] = @[], canReinterpret = true): Document = let builder = newChaDOMBuilder(url, window) @@ -204,13 +203,20 @@ proc parseHTML*(inputStream: Stream, window: Window, url: URL, proc newDOMParser(): DOMParser {.jsctor.} = new(result) -proc parseFromString(parser: DOMParser, str: string, t: string): +proc parseFromString(ctx: JSContext, parser: DOMParser, str, t: string): Result[Document, JSError] {.jsfunc.} = case t of "text/html": - #TODO window should be stored in DOMParser somehow. Setting it to nil - # is wrong. - let url = newURL("about:blank").get + let global = JS_GetGlobalObject(ctx) + let window = if ctx.hasClass(Window): + fromJS[Window](ctx, global).get(nil) + else: + Window(nil) + JS_FreeValue(ctx, global) + let url = if window != nil and window.document != nil: + window.document.url + else: + newURL("about:blank").get let res = parseHTML(newStringStream(str), Window(nil), url) return ok(res) of "text/xml", "application/xml", "application/xhtml+xml", "image/svg+xml": diff --git a/src/js/javascript.nim b/src/js/javascript.nim index 345054dd..bedb18e5 100644 --- a/src/js/javascript.nim +++ b/src/js/javascript.nim @@ -239,11 +239,8 @@ func getClass*(ctx: JSContext, class: string): JSClassID = # This function *should* never fail. ctx.getOpaque().creg[class] -func findClass*(ctx: JSContext, class: string): Option[JSClassID] = - let opaque = ctx.getOpaque() - if class in opaque.creg: - return some(opaque.creg[class]) - return none(JSClassID) +func hasClass*(ctx: JSContext, class: type): bool = + return $class in ctx.getOpaque().creg func newJSCFunction*(ctx: JSContext, name: string, fun: JSCFunction, argc: int = 0, proto = JS_CFUNC_generic, magic = 0): JSValue = |