main.go 753 B

123456789101112131415161718192021222324252627282930313233343536
  1. //go:generate go-bindata -prefix=static static/...
  2. package main
  3. import (
  4. "fmt"
  5. "github.com/cryptix/go/logging"
  6. "github.com/olebedev/go-duktape"
  7. )
  8. func main() {
  9. vm := duktape.NewContext()
  10. const stubs = `var self = {}, console = {log:print,warn:print,error:print,info:print}`
  11. if vm.PevalString(stubs) != 0 {
  12. panic(vm.SafeToString(-1))
  13. }
  14. rt, err := Asset("react-tools.js")
  15. logging.CheckFatal(err)
  16. vm.PushString(string(rt))
  17. vm.PushString("jsx")
  18. if vm.Pcompile(0) != 0 {
  19. panic(vm.SafeToString(-1))
  20. }
  21. if vm.Pcall(0) != 0 {
  22. panic(vm.SafeToString(-1))
  23. }
  24. // vm.PushGlobalObject()
  25. if vm.PevalString(`print("fromDuktape");Object.keys(this);Object.keys(self)`) != 0 {
  26. panic(vm.SafeToString(-1))
  27. }
  28. fmt.Println(vm.SafeToString(-1))
  29. }