//create engine func NewEngine() *Engine { self_ := C.V8_NewEngine(-1, -1) engine_ := &Engine{ self: self_, disposed: false, aliveContext: make(map[int]*Context), aliveScript: make(map[int]*Script), aliveUnboundScript: make(map[int]*UnboundScript), aliveValue: make(map[int32]*Value), //contextId : 0, //scriptId : 0, //unboundScriptId : 0, //valueId : 0, } engine_.SetOwner() runtime.SetFinalizer(engine_, func(e *Engine) { if traceDispose { println("V8_Engine_Dispose()", e.self) } if !e.disposed { C.V8_Engine_Dispose(e.self) } }) return engine_ }
func (engine_ *Engine) Disposed(forceAll bool) { engine_.checkDisposedException() if forceAll { //TODO: Disposed context /*foreach (var aliveContext in _aliveContexts) { JsContext.jscontext_dispose(aliveContext.Value.Handle); } _aliveContexts.Clear(); //TODO: Disposed script foreach (var aliveScript in _aliveScripts) { JsScript.jsscript_dispose(aliveScript.Value.Handle); }*/ /*for _ , ctx_ := range engine_.aliveContext { ctx_.Disposed() } for _, scp_ := range engine_.aliveScript { scp_.Disposed() } for _, uscp_ := range engine_.aliveUnboundScript { uscp_.Disposed() } for _, val_ := range engine_.aliveValue { val_.Disposed(); }*/ } if !engine_.disposed { C.V8_Engine_Dispose(engine_.self) } engine_.disposed = true }