Implement multi-error.

This commit is contained in:
Qi Xiao 2016-02-07 00:47:25 +01:00
parent a41182a48a
commit d8702d78c5
2 changed files with 6 additions and 1 deletions

View File

@ -40,6 +40,7 @@ func init() {
&BuiltinFn{"typeof", typeof},
&BuiltinFn{"fail", wrapFn(fail)},
&BuiltinFn{"multi-error", wrapFn(multiErrorFn)},
&BuiltinFn{"return", wrapFn(returnFn)},
&BuiltinFn{"break", wrapFn(breakFn)},
&BuiltinFn{"continue", wrapFn(continueFn)},
@ -191,6 +192,10 @@ func fail(ec *evalCtx, arg Value) {
throw(errors.New(ToString(arg)))
}
func multiErrorFn(ec *evalCtx, args ...Error) {
throw(multiError{args})
}
func returnFn(ec *evalCtx) {
throw(Return)
}

View File

@ -179,7 +179,7 @@ type multiError struct {
func (me multiError) Repr() string {
b := new(bytes.Buffer)
b.WriteString("(multi-error")
b.WriteString("?(multi-error")
for _, e := range me.errors {
b.WriteString(" ")
b.WriteString(e.Repr())