diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-18 20:46:30 +0100 |
commit | bfaf210d87e90016f8f2521657bd04686170aa43 (patch) | |
tree | e9711cb2f72174058d88ce2d52a76239e3c54c62 /src/html/env.nim | |
parent | 1fbe17eeddefb87bf8e819be7792ae7a6482d8f8 (diff) | |
download | chawan-bfaf210d87e90016f8f2521657bd04686170aa43.tar.gz |
Add JS support to documents
Diffstat (limited to 'src/html/env.nim')
-rw-r--r-- | src/html/env.nim | 26 |
1 files changed, 26 insertions, 0 deletions
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() |