about summary refs log blame commit diff stats
path: root/src/html/env.nim
blob: 29b1de09bfa644d08b472d0100a2e4c687eb25a7 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                     
                       














                                             
                          


                       
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(
    console: console(),
    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.addconsoleModule()
    ctx.addDOMModule()
    ctx.addURLModule()
    ctx.addHTMLModule()