From 18630616eb933213d51b00e3c1a76820a8d93823 Mon Sep 17 00:00:00 2001 From: Robert Krimen Date: Sun, 19 May 2013 21:08:32 -0700 Subject: [PATCH] Remove throw behavior from Otto.Call --- otto.go | 27 +-------------------------- otto_test.go | 34 ++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/otto.go b/otto.go index 47a495b..9d18923 100644 --- a/otto.go +++ b/otto.go @@ -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 } diff --git a/otto_test.go b/otto_test.go index 079204f..dc0ce8f 100644 --- a/otto_test.go +++ b/otto_test.go @@ -451,9 +451,27 @@ func TestOttoCall(t *testing.T) { Is(value, "1,2,3,,4,5,6,7,abc") } +func TestOttoCall_new(t *testing.T) { + Terst(t) + + _, test := runTestWithOtto() + + failSet("abc", func(call FunctionCall) Value { + value, err := call.Otto.Call(`new Object`, nil, "Nothing happens.") + Is(err, nil) + return value + }) + test(` + def = abc(); + [ def, def instanceof String ]; + `, "Nothing happens.,true") +} + func TestOttoCall_throw(t *testing.T) { Terst(t) + return + _, test := runTestWithOtto() failSet("abc", func(call FunctionCall) Value { @@ -492,19 +510,3 @@ func TestOttoCall_throw(t *testing.T) { [ error instanceof Error, error.message, error.def, typeof error, error, error instanceof Number ]; `, "false,,,object,3.14159,true") } - -func TestOttoCall_new(t *testing.T) { - Terst(t) - - _, test := runTestWithOtto() - - failSet("abc", func(call FunctionCall) Value { - value, err := call.Otto.Call(`new Object`, nil, "Nothing happens.") - Is(err, nil) - return value - }) - test(` - def = abc(); - [ def, def instanceof String ]; - `, "Nothing happens.,true") -}