<small id='HZQmeGtfa'></small> <noframes id='pB1lL9F3g'>

  • <tfoot id='a7FTHqjpPf'></tfoot>

      <legend id='MHEc5PRSGp'><style id='8qzEj'><dir id='l6jrce'><q id='H4lnj3EhM'></q></dir></style></legend>
      <i id='KgrDt6T'><tr id='XdJR9'><dt id='I7xjEhz'><q id='KZMnjg8RaW'><span id='50OmR'><b id='pOkX4Ual'><form id='K65Ds'><ins id='FDGeY6'></ins><ul id='IErbmwg'></ul><sub id='zIYXCSVjk'></sub></form><legend id='ehoIYvM'></legend><bdo id='XdkBe'><pre id='Hqab'><center id='53e8'></center></pre></bdo></b><th id='XCNtV8Wc'></th></span></q></dt></tr></i><div id='RcfhCjt6'><tfoot id='mbAp'></tfoot><dl id='YHCkPB7j'><fieldset id='bkBTA'></fieldset></dl></div>

          <bdo id='bGOHCj'></bdo><ul id='Y2JayOEHg9'></ul>

          1. <li id='Lvz47OXV'></li>
            登陆

            v8go - 从Go履行JavaScript

            admin 2019-12-22 258人围观 ,发现0个评论

            v8go

            从Go履行JavaScript

            V8依靠

            V8版别:7.6.303.31

            为了使其v8go可用作规范Go包,可认为Linux和OSX包括预构建的V8静态库。

            V8需求64位,因而无法在32位体系上运转。

            用法

            import "rogchap.com/v8go"

            运转脚本

            ctx, _ := v8go.NewContext(nil) // creates a new V8 context with a new Isolate aka VM
            ctx.RunScript("const add = (a, b) => a + b", "math.js") // executes a script on the global context
            ctx.RunScript("const result = add(3, 4)", "main.js") // any functions previously added to the context can be called
            val, _ ctx.RunScript("result", "value.js") // return a value in JavaScript back to Go
            fmt.Printf("addition result: %s", val)

            一个VM,许多状况

            vm, _ := v8go.NewIsolate() // creates a new JavaScript VM
            ctx1, _ := v8go.NewContext(vm) // new context within the VM
            ctx1.RunScript("const multiply = (a, b) => a * b", "math.js")

            ctx2, _ := v8go.NewContext(vm) // another context on the same VM
            if _, err := ctx2.RunScript("multiply(3, 4)", "main.js"); err != nil {
            // this will err陶慧or as multiply is not defined in this context
            }

            Javascript过错

            val, err := ctx.RunScript(src, filename)
            if err != nil {
            err = ev8go - 从Go履行JavaScriptrr.(v8go.JSError) // JavaScript errors will be returned as the JSError struct
            fmt.Println(err.Message) // the message of the exception thrown
            fmt.Println(err.Location) // the filename, line number and the column where the error occured
            fmt.Println(err.StackTrace) // the full stack trace of the error, if available

            fmt.Printf("javascript error: %v", err) // will format the standard error message
            fmt.Printf("javascript stack trace: %+v", err) // will format the full error stack trace
            }

            更多运用文档能够看官方材料

            开源地址:

            因为头条审阅网址比较严,避免他们误会是推行,所以我们能够自行查找下载

            也能够重视我的头条号后给我发送 `v8go`,会主动把下载地址发送给你(做了关键字主动回复)

            您知道哪些好用的小工具,欢迎谈论共享,一起v8go - 从Go履行JavaScript讨论学习

            更多更优质的资讯,请重视我,你v8go - 从Go履行JavaScript的支撑会鼓舞我不断共享更多更好的优质文章。

            请关注微信公众号
            微信二维码
            不容错过
            Powered By Z-BlogPHP