forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native_stack_test.go
111 lines (90 loc) · 2.67 KB
/
native_stack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package otto
import (
"testing"
)
func TestNativeStackFrames(t *testing.T) {
tt(t, func() {
vm := New()
s, err := vm.Compile("input.js", `
function A() { ext1(); }
function B() { ext2(); }
A();
`)
if err != nil {
panic(err)
}
vm.Set("ext1", func(c FunctionCall) Value {
if _, err := c.Otto.Eval("B()"); err != nil {
panic(err)
}
return UndefinedValue()
})
vm.Set("ext2", func(c FunctionCall) Value {
{
// no limit, include innermost native frames
ctx := c.Otto.ContextSkip(-1, false)
is(ctx.Stacktrace, []string{
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.2 (native_stack_test.go:28)",
"B (input.js:3:22)",
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.1 (native_stack_test.go:20)",
"A (input.js:2:22)", "input.js:4:7",
})
is(ctx.Callee, "github.com/robertkrimen/otto.TestNativeStackFrames.func1.2")
is(ctx.Filename, "native_stack_test.go")
is(ctx.Line, 28)
is(ctx.Column, 0)
}
{
// no limit, skip innermost native frames
ctx := c.Otto.ContextSkip(-1, true)
is(ctx.Stacktrace, []string{
"B (input.js:3:22)",
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.1 (native_stack_test.go:20)",
"A (input.js:2:22)", "input.js:4:7",
})
is(ctx.Callee, "B")
is(ctx.Filename, "input.js")
is(ctx.Line, 3)
is(ctx.Column, 22)
}
if _, err := c.Otto.Eval("ext3()"); err != nil {
panic(err)
}
return UndefinedValue()
})
vm.Set("ext3", func(c FunctionCall) Value {
{
// no limit, include innermost native frames
ctx := c.Otto.ContextSkip(-1, false)
is(ctx.Stacktrace, []string{
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.3 (native_stack_test.go:69)",
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.2 (native_stack_test.go:28)",
"B (input.js:3:22)",
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.1 (native_stack_test.go:20)",
"A (input.js:2:22)", "input.js:4:7",
})
is(ctx.Callee, "github.com/robertkrimen/otto.TestNativeStackFrames.func1.3")
is(ctx.Filename, "native_stack_test.go")
is(ctx.Line, 69)
is(ctx.Column, 0)
}
{
// no limit, skip innermost native frames
ctx := c.Otto.ContextSkip(-1, true)
is(ctx.Stacktrace, []string{
"B (input.js:3:22)",
"github.com/robertkrimen/otto.TestNativeStackFrames.func1.1 (native_stack_test.go:20)",
"A (input.js:2:22)", "input.js:4:7",
})
is(ctx.Callee, "B")
is(ctx.Filename, "input.js")
is(ctx.Line, 3)
is(ctx.Column, 22)
}
return UndefinedValue()
})
if _, err := vm.Run(s); err != nil {
panic(err)
}
})
}