diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-08 19:54:22 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-05-08 19:54:22 +0800 |
commit | f819ac715858bd61094e101a199f8e1b79496dbb (patch) | |
tree | c3e2ffb8388d4ddee4aaa1a5a5d4d59a2a6b0639 /jsre | |
parent | 15bfae52d253258829c10b14b43b02c73e3f7d04 (diff) | |
parent | d7dabce73291d2bb768625c7e465f2f645980dbf (diff) | |
download | go-tangerine-f819ac715858bd61094e101a199f8e1b79496dbb.tar.gz go-tangerine-f819ac715858bd61094e101a199f8e1b79496dbb.tar.zst go-tangerine-f819ac715858bd61094e101a199f8e1b79496dbb.zip |
Merge pull request #882 from zsfelfoldi/develop
Otto.ToValue concurrency error fixed
Diffstat (limited to 'jsre')
-rw-r--r-- | jsre/jsre.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/jsre/jsre.go b/jsre/jsre.go index 6a7cb1b83..a6dd117a3 100644 --- a/jsre/jsre.go +++ b/jsre/jsre.go @@ -286,7 +286,7 @@ func (self *JSRE) loadScript(call otto.FunctionCall) otto.Value { // uses the "prettyPrint" JS function to format a value func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error) { var method otto.Value - v, err = self.vm.ToValue(v) + v, err = self.ToValue(v) if err != nil { return } @@ -297,8 +297,23 @@ func (self *JSRE) PrettyPrint(v interface{}) (val otto.Value, err error) { return method.Call(method, v) } -// creates an otto value from a go type +// creates an otto value from a go type (serialized version) +func (self *JSRE) ToValue(v interface{}) (otto.Value, error) { + done := make(chan bool) + req := &evalReq{ + fn: func(res *evalResult) { + res.result, res.err = self.vm.ToValue(v) + }, + done: done, + } + self.evalQueue <- req + <-done + return req.res.result, req.res.err +} + +// creates an otto value from a go type (non-serialized version) func (self *JSRE) ToVal(v interface{}) otto.Value { + result, err := self.vm.ToValue(v) if err != nil { fmt.Println("Value unknown:", err) |