3 Star 1 Fork 0

Gitee 极速下载/otto

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/robertkrimen/otto
克隆/下载
error_native_test.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
package otto
import (
"testing"
"github.com/stretchr/testify/require"
)
// this is its own file because the tests in it rely on the line numbers of
// some of the functions defined here. putting it in with the rest of the
// tests would probably be annoying.
func TestErrorContextNative(t *testing.T) {
tt(t, func() {
vm := New()
err := vm.Set("N", func(c FunctionCall) Value {
v, err := c.Argument(0).Call(NullValue())
if err != nil {
panic(err)
}
return v
})
require.NoError(t, err)
s, err := vm.Compile("test.js", `
function F() { throw new Error('wow'); }
function G() { return N(F); }
`)
require.NoError(t, err)
_, err = vm.Run(s)
require.NoError(t, err)
f1, err := vm.Get("G")
require.NoError(t, err)
_, err = f1.Call(NullValue())
require.Error(t, err)
err1 := asError(t, err)
is(err1.message, "wow")
is(len(err1.trace), 3)
is(err1.trace[0].location(), "F (test.js:2:29)")
is(err1.trace[1].location(), "github.com/robertkrimen/otto.TestErrorContextNative.func1.1 (error_native_test.go:17)")
is(err1.trace[2].location(), "G (test.js:3:26)")
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/otto.git
git@gitee.com:mirrors/otto.git
mirrors
otto
otto
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385