From bfaf210d87e90016f8f2521657bd04686170aa43 Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 18 Dec 2022 20:46:30 +0100 Subject: Add JS support to documents --- src/html/env.nim | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/html/env.nim (limited to 'src/html/env.nim') diff --git a/src/html/env.nim b/src/html/env.nim new file mode 100644 index 00000000..6db018c9 --- /dev/null +++ b/src/html/env.nim @@ -0,0 +1,26 @@ +import html/dom +import html/htmlparser +import io/loader +import js/javascript +import types/url + +proc newWindow*(scripting: bool, loader = none(FileLoader)): Window = + result = Window( + loader: loader, + settings: EnvironmentSettings( + scripting: scripting + ) + ) + if scripting: + let rt = newJSRuntime() + let ctx = rt.newJSContext() + result.jsrt = rt + result.jsctx = ctx + var global = JS_GetGlobalObject(ctx) + ctx.registerType(Window, asglobal = true) + ctx.setOpaque(global, result) + ctx.setProperty(global, "window", global) + JS_FreeValue(ctx, global) + ctx.addDOMModule() + ctx.addURLModule() + ctx.addHTMLModule() -- cgit 1.4.1-2-gfad0