2017-09-01 20:17:34 +00:00
|
|
|
package promise
|
2017-07-13 11:04:47 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-08 11:55:17 +00:00
|
|
|
"github.com/status-im/status-go/geth/jail/internal/loop"
|
|
|
|
"github.com/status-im/status-go/geth/jail/internal/timers"
|
|
|
|
"github.com/status-im/status-go/geth/jail/internal/vm"
|
2017-07-13 11:04:47 +00:00
|
|
|
)
|
|
|
|
|
2017-09-08 11:55:17 +00:00
|
|
|
func Define(vm *vm.VM, l *loop.Loop) error {
|
2017-07-13 11:04:47 +00:00
|
|
|
if v, err := vm.Get("Promise"); err != nil {
|
|
|
|
return err
|
|
|
|
} else if !v.IsUndefined() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := timers.Define(vm, l); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s, err := vm.Compile("promise-bundle.js", src)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := vm.Run(s); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|