diff options
author | zelig <viktor.tron@gmail.com> | 2015-03-15 14:13:39 +0800 |
---|---|---|
committer | zelig <viktor.tron@gmail.com> | 2015-03-15 14:13:39 +0800 |
commit | da44097800caf2e20ec8e067f8700e59a43a5e06 (patch) | |
tree | 59caea58032056fbc42395cf3a1eb53f5f75e46c /javascript/javascript_runtime.go | |
parent | 2a5fbced7fb1fe976367f3f9f334c6ca657e7917 (diff) | |
download | go-tangerine-da44097800caf2e20ec8e067f8700e59a43a5e06.tar.gz go-tangerine-da44097800caf2e20ec8e067f8700e59a43a5e06.tar.zst go-tangerine-da44097800caf2e20ec8e067f8700e59a43a5e06.zip |
jsre:
- require became loadScript(), no require is supplied
- bignumber_js.go: heredoc v2.0.3 minified fixed for otto Regexp incompatibility https://github.com/robertkrimen/otto#regular-expression-incompatibility
- bignumber.min.js also updated in mist/assets/ext
- ethereum_js.go: latest master minified
- assetPath in constructor
- Eval/Exec/Handle/ToVal nice API
- jsre tests
Diffstat (limited to 'javascript/javascript_runtime.go')
-rw-r--r-- | javascript/javascript_runtime.go | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go deleted file mode 100644 index 0a137f72a..000000000 --- a/javascript/javascript_runtime.go +++ /dev/null @@ -1,103 +0,0 @@ -package javascript - -import ( - "fmt" - "io/ioutil" - "os" - "path" - "path/filepath" - - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/xeth" - "github.com/obscuren/otto" -) - -var jsrelogger = logger.NewLogger("JSRE") - -type JSRE struct { - Vm *otto.Otto - xeth *xeth.XEth - - objectCb map[string][]otto.Value -} - -func (jsre *JSRE) LoadExtFile(path string) { - result, err := ioutil.ReadFile(path) - if err == nil { - jsre.Vm.Run(result) - } else { - jsrelogger.Infoln("Could not load file:", path) - } -} - -func (jsre *JSRE) LoadIntFile(file string) { - assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") - jsre.LoadExtFile(path.Join(assetPath, file)) -} - -func NewJSRE(xeth *xeth.XEth) *JSRE { - re := &JSRE{ - otto.New(), - xeth, - make(map[string][]otto.Value), - } - - // Init the JS lib - re.Vm.Run(jsLib) - - // Load extra javascript files - re.LoadIntFile("bignumber.min.js") - - re.Bind("eth", &JSEthereum{re.xeth, re.Vm}) - - re.initStdFuncs() - - jsrelogger.Infoln("started") - - return re -} - -func (self *JSRE) Bind(name string, v interface{}) { - self.Vm.Set(name, v) -} - -func (self *JSRE) Run(code string) (otto.Value, error) { - return self.Vm.Run(code) -} - -func (self *JSRE) initStdFuncs() { - t, _ := self.Vm.Get("eth") - eth := t.Object() - eth.Set("require", self.require) -} - -func (self *JSRE) Require(file string) error { - if len(filepath.Ext(file)) == 0 { - file += ".js" - } - - fh, err := os.Open(file) - if err != nil { - return err - } - - content, _ := ioutil.ReadAll(fh) - self.Run("exports = {};(function() {" + string(content) + "})();") - - return nil -} - -func (self *JSRE) require(call otto.FunctionCall) otto.Value { - file, err := call.Argument(0).ToString() - if err != nil { - return otto.UndefinedValue() - } - if err := self.Require(file); err != nil { - fmt.Println("err:", err) - return otto.UndefinedValue() - } - - t, _ := self.Vm.Get("exports") - - return t -} |