Replace javascript module otto with goja (#4631)

* Move plugin javascript to own package with goja
* Use javascript package in scraper

Remove otto
This commit is contained in:
WithoutPants
2024-03-14 11:03:40 +11:00
committed by GitHub
parent 49cd214c9d
commit 9ceea952b6
12 changed files with 381 additions and 288 deletions

25
pkg/javascript/util.go Normal file
View File

@@ -0,0 +1,25 @@
package javascript
import (
"fmt"
"time"
)
type Util struct{}
func (u *Util) sleepFunc(ms int64) {
time.Sleep(time.Millisecond * time.Duration(ms))
}
func (u *Util) AddToVM(globalName string, vm *VM) error {
util := vm.NewObject()
if err := util.Set("Sleep", u.sleepFunc); err != nil {
return fmt.Errorf("unable to set sleep func: %w", err)
}
if err := vm.Set(globalName, util); err != nil {
return fmt.Errorf("unable to set util: %w", err)
}
return nil
}