Add console javascript object for backwards compatibility (#4944)

This commit is contained in:
WithoutPants
2024-06-07 14:53:51 +10:00
committed by GitHub
parent dbfa450ace
commit 60446af145
2 changed files with 38 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import (
"reflect"
"github.com/dop251/goja"
"github.com/stashapp/stash/pkg/logger"
)
type VM struct {
@@ -36,6 +37,17 @@ func (tfm optionalFieldNameMapper) MethodName(t reflect.Type, m reflect.Method)
func NewVM() *VM {
r := goja.New()
// enable console for backwards compatibility
c := console{
Log{
Logger: logger.Logger,
},
}
// there should not be any reason for this to fail
_ = c.AddToVM("console", &VM{Runtime: r})
r.SetFieldNameMapper(optionalFieldNameMapper{goja.TagFieldNameMapper("json", true)})
return &VM{Runtime: r}
}