Files

35 lines
791 B
Go
Raw Permalink Normal View History

2025-02-02 17:03:27 +08:00
package console
import (
2025-02-04 15:00:59 +08:00
"github.com/sagernet/sing-box/script/jsc"
2025-02-02 17:03:27 +08:00
"github.com/sagernet/sing-box/script/modules/require"
"github.com/dop251/goja"
)
const ModuleName = "console"
2025-02-04 15:00:59 +08:00
type Module struct {
runtime *goja.Runtime
console jsc.Class[*Module, *Console]
2025-02-02 17:03:27 +08:00
}
2025-02-04 15:00:59 +08:00
func Require(runtime *goja.Runtime, module *goja.Object) {
m := &Module{
runtime: runtime,
2025-02-02 17:03:27 +08:00
}
2025-02-04 15:00:59 +08:00
m.console = createConsole(m)
exports := module.Get("exports").(*goja.Object)
exports.Set("Console", m.console.ToValue())
2025-02-02 17:03:27 +08:00
}
2025-02-04 15:00:59 +08:00
func Enable(runtime *goja.Runtime) {
exports := require.Require(runtime, ModuleName).ToObject(runtime)
classConsole := jsc.GetClass[*Module, *Console](runtime, exports, "Console")
runtime.Set("console", NewConsole(classConsole))
2025-02-02 17:03:27 +08:00
}
2025-02-04 15:00:59 +08:00
func (m *Module) Runtime() *goja.Runtime {
return m.runtime
2025-02-02 17:03:27 +08:00
}