1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +08:00

Remove throw behavior from Otto.Call

This commit is contained in:
Robert Krimen
2013-05-19 21:08:32 -07:00
parent 83c56dd73d
commit 18630616eb
2 changed files with 19 additions and 42 deletions

27
otto.go
View File

@@ -216,18 +216,11 @@ func (self Otto) Call(source string, this interface{}, argumentList ...interface
thisValue := UndefinedValue()
new_, throw := false, false
new_ := false
switch {
case strings.HasPrefix(source, "throw new "):
source = source[10:]
throw = true
new_ = true
case strings.HasPrefix(source, "new "):
source = source[4:]
new_ = true
case strings.HasPrefix(source, "throw "):
source = source[6:]
throw = true
}
if !new_ && this == nil {
@@ -242,17 +235,11 @@ func (self Otto) Call(source string, this interface{}, argumentList ...interface
}
})
if !fallback && err == nil {
if throw {
panic(value)
}
return value, nil
}
} else {
value, err := self.ToValue(this)
if err != nil {
if throw {
panic(UndefinedValue())
}
return UndefinedValue(), err
}
thisValue = value
@@ -260,9 +247,6 @@ func (self Otto) Call(source string, this interface{}, argumentList ...interface
fnValue, err := self.Run(source)
if err != nil {
if throw {
panic(UndefinedValue())
}
return UndefinedValue(), err
}
@@ -270,24 +254,15 @@ func (self Otto) Call(source string, this interface{}, argumentList ...interface
if new_ {
value, err = fnValue.constructSafe(thisValue, argumentList...)
if err != nil {
if throw {
panic(UndefinedValue())
}
return UndefinedValue(), err
}
} else {
value, err = fnValue.Call(thisValue, argumentList...)
if err != nil {
if throw {
panic(UndefinedValue())
}
return UndefinedValue(), err
}
}
if throw {
panic(value)
}
return value, nil
}