diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-13 17:41:02 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-13 17:42:08 +0200 |
commit | 1cfe1655e1ef6f7ae69b9c87731d571e1ef3ca8c (patch) | |
tree | f62e05768e4a4205710cb9727b40b8d0cb04f632 /src/html | |
parent | 9ff482dd8d5b1b252e77712e9418b5b253f4bbf8 (diff) | |
download | chawan-1cfe1655e1ef6f7ae69b9c87731d571e1ef3ca8c.tar.gz |
Refactor Console
* merge dom.console & client.Console * move client-specific stuff out of Console (into callbacks when necessary)
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 43 | ||||
-rw-r--r-- | src/html/env.nim | 6 |
2 files changed, 6 insertions, 43 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 008a4e8a..3931ae69 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -17,6 +17,7 @@ import img/bitmap import img/painter import img/path import img/png +import js/console import js/domexception import js/error import js/fromjs @@ -91,7 +92,7 @@ type Window* = ref object of EventTarget attrs*: WindowAttributes - console* {.jsget.}: console + console* {.jsget.}: Console navigator* {.jsget.}: Navigator settings*: EnvironmentSettings loader*: Option[FileLoader] @@ -110,13 +111,6 @@ type MimeTypeArray* = object - # "For historical reasons, console is lowercased." - # Also, for a more practical reason: so the javascript macros don't confuse - # this and the Client console. - # TODO: merge those two - console* = ref object - err*: Stream - NamedNodeMap = ref object element: Element attrlist: seq[Attr] @@ -372,7 +366,6 @@ jsDestructor(PluginArray) jsDestructor(MimeTypeArray) jsDestructor(Window) -jsDestructor(console) jsDestructor(Element) jsDestructor(HTMLElement) jsDestructor(HTMLInputElement) @@ -2698,34 +2691,6 @@ proc fetchClassicScript(element: HTMLScriptElement, url: URL, let script = createClassicScript(source, url, options, false) element.markAsReady(ScriptResult(t: RESULT_SCRIPT, script: script)) -proc log*(console: console, ss: varargs[string]) {.jsfunc.} = - var s = "" - for i in 0..<ss.len: - s &= ss[i] - console.err.write(ss[i]) - if i != ss.high: - s &= ' ' - console.err.write(' ') - console.err.write('\n') - console.err.flush() - -proc clear*(console: console) {.jsfunc.} = - # Do nothing. By design, we do not allow buffers to clear the console. - discard - -# For now, these are the same as log(). -proc debug*(console: console, ss: varargs[string]) {.jsfunc.} = - console.log(ss) - -proc error*(console: console, ss: varargs[string]) {.jsfunc.} = - console.log(ss) - -proc info*(console: console, ss: varargs[string]) {.jsfunc.} = - console.log(ss) - -proc warn*(console: console, ss: varargs[string]) {.jsfunc.} = - console.log(ss) - proc execute*(element: HTMLScriptElement) = let document = element.document if document != element.preparationTimeDocument: @@ -3037,10 +3002,6 @@ proc jsReflectSet(ctx: JSContext, this, val: JSValue, magic: cint): JSValue {.cd element.attrulgz(entry.attrname, x.get) return JS_DupValue(ctx, val) -proc addconsoleModule*(ctx: JSContext) = - #TODO console should not have a prototype - ctx.registerType(console, nointerface = true) - func getReflectFunctions(tags: set[TagType]): seq[TabGetSet] = for tag in tags: if tag in TagReflectMap: diff --git a/src/html/env.nim b/src/html/env.nim index 49f6bba3..24e1482d 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -7,6 +7,7 @@ import html/dom import html/event import io/promise import js/base64 +import js/console import js/domexception import js/error import js/intl @@ -130,7 +131,7 @@ proc addScripting*(window: Window, selector: Selector[int]) = ctx.setGlobal(global, window) JS_FreeValue(ctx, global) ctx.addDOMExceptionModule() - ctx.addconsoleModule() + ctx.addConsoleModule() ctx.addNavigatorModule() ctx.addEventModule() ctx.addDOMModule() @@ -150,9 +151,10 @@ proc runJSJobs*(window: Window) = proc newWindow*(scripting: bool, selector: Selector[int], attrs: WindowAttributes, navigate: proc(url: URL) = nil, loader = none(FileLoader)): Window = + let err = newFileStream(stderr) let window = Window( attrs: attrs, - console: console(err: newFileStream(stderr)), + console: newConsole(err), navigator: Navigator(), loader: loader, settings: EnvironmentSettings( |