Ejemplo n.º 1
0
func Shutdown() {
	for script, _ := range scripts {
		script.Destroy()
	}
	C.JS_DestroyRuntime(jsruntime)
	C.JS_ShutDown()
}
Ejemplo n.º 2
0
func (r *Runtime) init() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	r.goid = goid.Get()

	r.jsrt = C.JS_NewRuntime(C.uint32(r.maxbytes))
	if r.jsrt == nil {
		r.initChan <- false
		return
	}

	r.workChan = make(chan jswork, 20)
	r.closeChan = make(chan int, 1)
	r.ctxDisposeChan = make(chan *Context, 50)
	r.objDisposeChan = make(chan *Object, 100)
	r.aryDisposeChan = make(chan *Array, 100)
	r.valDisposeChan = make(chan *Value, 100)
	r.sptDisposeChan = make(chan *Script, 100)

	runtime.SetFinalizer(r, func(r *Runtime) {
		r.Dispose()
	})

	r.initChan <- true

L:
	for {
		select {
		case work := <-r.workChan:
			work.callback()
			work.resultChan <- 1
		case ctx := <-r.ctxDisposeChan:
			C.JS_DestroyContext(ctx.jscx)
		case obj := <-r.objDisposeChan:
			C.JS_RemoveObjectRoot(obj.cx.jscx, &obj.obj)
		case ary := <-r.aryDisposeChan:
			C.JS_RemoveObjectRoot(ary.cx.jscx, &ary.obj)
		case val := <-r.valDisposeChan:
			C.JS_RemoveValueRoot(val.cx.jscx, &val.val)
		case spt := <-r.sptDisposeChan:
			C.JS_RemoveObjectRoot(spt.cx.jscx, &spt.obj)
		case _ = <-r.closeChan:
			break L
		}
	}

	C.JS_DestroyRuntime(r.jsrt)
}