mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
Fixed stacktrace positions.
This commit is contained in:
parent
d1b4d8ef0e
commit
1e5ee63535
|
@ -188,5 +188,49 @@ func TestErrorContext(t *testing.T) {
|
|||
is(len(err.trace), 1)
|
||||
is(err.trace[0].location(), "<anonymous>:2:23")
|
||||
}
|
||||
|
||||
script1, err := vm.Compile("file1.js",
|
||||
`function A() {
|
||||
throw new Error("test");
|
||||
}
|
||||
`)
|
||||
is(err, nil)
|
||||
|
||||
_, err = vm.Run(script1)
|
||||
is(err, nil)
|
||||
|
||||
script2, err := vm.Compile("file2.js",
|
||||
`function B() {
|
||||
A()
|
||||
}
|
||||
`)
|
||||
is(err, nil)
|
||||
|
||||
_, err = vm.Run(script2)
|
||||
is(err, nil)
|
||||
|
||||
script3, err := vm.Compile("file3.js", "B()")
|
||||
is(err, nil)
|
||||
|
||||
_, err = vm.Run(script3)
|
||||
{
|
||||
err := err.(*Error)
|
||||
is(err.message, "test")
|
||||
is(len(err.trace), 3)
|
||||
is(err.trace[0].location(), "A (file1.js:2:15)")
|
||||
is(err.trace[1].location(), "B (file2.js:2:5)")
|
||||
is(err.trace[2].location(), "file3.js:1:1")
|
||||
}
|
||||
|
||||
{
|
||||
f, _ := vm.Get("B")
|
||||
_, err := f.Call(UndefinedValue())
|
||||
err1 := err.(*Error)
|
||||
is(err1.message, "test")
|
||||
is(len(err1.trace), 2)
|
||||
is(err1.trace[0].location(), "A (file1.js:2:15)")
|
||||
is(err1.trace[1].location(), "B (file2.js:2:5)")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@ const (
|
|||
)
|
||||
|
||||
type _parser struct {
|
||||
filename string
|
||||
str string
|
||||
length int
|
||||
base int
|
||||
|
@ -260,7 +259,7 @@ func (self *_parser) position(idx file.Idx) file.Position {
|
|||
position := file.Position{}
|
||||
offset := int(idx) - self.base
|
||||
str := self.str[:offset]
|
||||
position.Filename = self.filename
|
||||
position.Filename = self.file.Name()
|
||||
line, last := lineCount(str)
|
||||
position.Line = 1 + line
|
||||
if last >= 0 {
|
||||
|
|
|
@ -147,10 +147,13 @@ func (self *_object) call(this Value, argumentList []Value, eval bool, frame _fr
|
|||
case _nodeFunctionObject:
|
||||
rt := self.runtime
|
||||
stash := rt.enterFunctionScope(fn.stash, this)
|
||||
rt.scope.frame = _frame{
|
||||
callee: fn.node.name,
|
||||
file: fn.node.file,
|
||||
}
|
||||
defer func() {
|
||||
rt.leaveScope()
|
||||
}()
|
||||
rt.scope.frame = frame
|
||||
callValue := rt.cmpl_call_nodeFunction(self, stash, fn.node, this, argumentList)
|
||||
if value, valid := callValue.value.(_result); valid {
|
||||
return value.value
|
||||
|
|
Loading…
Reference in New Issue
Block a user