mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-14 12:23:43 +00:00
research: evaluate moejs extension compatibility and performance
This commit is contained in:
1 parent
be0a395447
commit
941fda7d13
29 files changed
+1688
No files matched your search
@@ -0,0 +1,22 @@
|
||||
//go:build !moejs
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dop251/goja"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
source := "1+1"
|
||||
if len(os.Args) > 1 {
|
||||
source = os.Args[1]
|
||||
}
|
||||
rt := goja.New()
|
||||
v, e := rt.RunString(source)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
fmt.Println(v.Export())
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//go:build moejs
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/MoeForge/moejs"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
source := "1+1"
|
||||
if len(os.Args) > 1 {
|
||||
source = os.Args[1]
|
||||
}
|
||||
rt := moejs.NewRuntime(moejs.Options{MutableIntrinsics: true})
|
||||
script, e := moejs.CompileScript("size", source)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
v, e := rt.RunScript(script)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
out, e := rt.ToGo(v)
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
fmt.Println(out)
|
||||
}
|
||||
Reference in new issue
Block a user