1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/otto_error_test.go
Robert Krimen e6768252c2 Improve error reporting
* Delay entering global scope on code evaluation, not runtime creation

This fixes #66
2014-06-12 21:27:32 -07:00

49 lines
914 B
Go

package otto
import (
"testing"
)
func TestOttoError(t *testing.T) {
tt(t, func() {
vm := New()
_, err := vm.Run(`throw "Xyzzy"`)
is(err, "Xyzzy")
_, err = vm.Run(`throw new TypeError()`)
is(err, "TypeError")
_, err = vm.Run(`throw new TypeError("Nothing happens.")`)
is(err, "TypeError: Nothing happens.")
_, err = ToValue([]byte{})
is(err, "TypeError: invalid value (slice): missing runtime: [] ([]uint8)")
_, err = vm.Run(`
(function(){
return abcdef.length
})()
`)
is(err, "ReferenceError: 'abcdef' is not defined")
_, err = vm.Run(`
function start() {
}
start()
xyzzy()
`)
is(err, "ReferenceError: 'xyzzy' is not defined")
_, err = vm.Run(`
// Just a comment
xyzzy
`)
is(err, "ReferenceError: 'xyzzy' is not defined")
})
}