js_rt_runtime.go 524 B

1234567891011121314151617181920212223242526272829303132
  1. package ngjsvm
  2. import "github.com/dop251/goja"
  3. type JSRtRuntime struct {
  4. isReg bool
  5. env *JSEnv
  6. }
  7. func (j *JSRtRuntime) Dispose() {
  8. }
  9. func (j *JSRtRuntime) RegisterRt(name string, env *JSEnv) (goja.Value, error) {
  10. j.env = env
  11. fmap := map[string]interface{}{
  12. "quit": j.J_quit,
  13. }
  14. obj := j.env.BuildObject(name, fmap)
  15. j.isReg = true
  16. return obj, nil
  17. }
  18. func (j *JSRtRuntime) IsRegistered() bool {
  19. return j.isReg
  20. }
  21. func (j *JSRtRuntime) J_quit(v ...goja.Value) {
  22. if !j.isReg {
  23. return
  24. }
  25. j.env.JSCallQuit()
  26. }