(name string, manager *ScriptManager)
| 24 | } |
| 25 | |
| 26 | func NewScriptEngine(name string, manager *ScriptManager) *ScriptEngine { |
| 27 | rt := goja.New() |
| 28 | rt.SetFieldNameMapper(goja.UncapFieldNameMapper()) |
| 29 | |
| 30 | engine := &ScriptEngine{ |
| 31 | runtime: rt, |
| 32 | name: name, |
| 33 | manager: manager, |
| 34 | functions: make(map[string]goja.Callable), |
| 35 | } |
| 36 | |
| 37 | consoleObj := rt.NewObject() |
| 38 | consoleObj.Set("log", func(call goja.FunctionCall) goja.Value { return goja.Undefined() }) |
| 39 | consoleObj.Set("warn", func(call goja.FunctionCall) goja.Value { return goja.Undefined() }) |
| 40 | consoleObj.Set("error", func(call goja.FunctionCall) goja.Value { return goja.Undefined() }) |
| 41 | consoleObj.Set("info", func(call goja.FunctionCall) goja.Value { return goja.Undefined() }) |
| 42 | consoleObj.Set("debug", func(call goja.FunctionCall) goja.Value { return goja.Undefined() }) |
| 43 | rt.Set("console", consoleObj) |
| 44 | |
| 45 | return engine |
| 46 | } |
| 47 | |
| 48 | func NewScriptEngineFromPath(scriptPath string, manager *ScriptManager) (*ScriptEngine, error) { |
| 49 | abs, err := filepath.Abs(scriptPath) |
no outgoing calls
no test coverage detected