File: error_native_test.go

package info (click to toggle)
golang-github-robertkrimen-otto 0.0~git20200922.ef014fd-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,796 kB
  • sloc: perl: 1,227; makefile: 79
file content (39 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (2)
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
package otto

import (
	"testing"
)

// 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()

		vm.Set("N", func(c FunctionCall) Value {
			v, err := c.Argument(0).Call(NullValue())
			if err != nil {
				panic(err)
			}
			return v
		})

		s, _ := vm.Compile("test.js", `
			function F() { throw new Error('wow'); }
			function G() { return N(F); }
		`)

		vm.Run(s)

		f1, _ := vm.Get("G")
		_, err := f1.Call(NullValue())
		err1 := err.(*Error)
		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:15)")
		is(err1.trace[2].location(), "G (test.js:3:26)")
	})
}