diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-03-23 04:45:56 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-03-23 04:45:56 +0800 |
commit | 3133372a6a81c91528afbde58e22b3f9df257d03 (patch) | |
tree | 16778611a22c9fd249a94c88660cb0c6d297ce9b /Godeps/_workspace/src/github.com/obscuren/otto/error.go | |
parent | 59eab49cb849ca93b9608763f4842654e8044d0f (diff) | |
parent | 85acdadcfa99ea5c74907029cb63919cc0302c1a (diff) | |
download | go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.gz go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.bz2 go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.lz go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.xz go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.tar.zst go-tangerine-3133372a6a81c91528afbde58e22b3f9df257d03.zip |
Merge pull request #536 from zsfelfoldi/develop
using robertkrimen/otto, godeps updated
Diffstat (limited to 'Godeps/_workspace/src/github.com/obscuren/otto/error.go')
-rw-r--r-- | Godeps/_workspace/src/github.com/obscuren/otto/error.go | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/Godeps/_workspace/src/github.com/obscuren/otto/error.go b/Godeps/_workspace/src/github.com/obscuren/otto/error.go deleted file mode 100644 index 887b954bd..000000000 --- a/Godeps/_workspace/src/github.com/obscuren/otto/error.go +++ /dev/null @@ -1,152 +0,0 @@ -package otto - -import ( - "errors" - "fmt" - - "github.com/robertkrimen/otto/ast" -) - -type _exception struct { - value interface{} -} - -func newException(value interface{}) *_exception { - return &_exception{ - value: value, - } -} - -func (self *_exception) eject() interface{} { - value := self.value - self.value = nil // Prevent Go from holding on to the value, whatever it is - return value -} - -type _error struct { - Name string - Message string - - Line int // Hackish -- line where the error/exception occurred -} - -var messageDetail map[string]string = map[string]string{ - "notDefined": "%v is not defined", -} - -func messageFromDescription(description string, argumentList ...interface{}) string { - message := messageDetail[description] - if message == "" { - message = description - } - message = fmt.Sprintf(message, argumentList...) - return message -} - -func (self _error) MessageValue() Value { - if self.Message == "" { - return UndefinedValue() - } - return toValue_string(self.Message) -} - -func (self _error) String() string { - if len(self.Name) == 0 { - return self.Message - } - if len(self.Message) == 0 { - return self.Name - } - return fmt.Sprintf("%s: %s", self.Name, self.Message) -} - -func newError(name string, argumentList ...interface{}) _error { - description := "" - var node ast.Node = nil - length := len(argumentList) - if length > 0 { - if node, _ = argumentList[length-1].(ast.Node); node != nil || argumentList[length-1] == nil { - argumentList = argumentList[0 : length-1] - length -= 1 - } - if length > 0 { - description, argumentList = argumentList[0].(string), argumentList[1:] - } - } - return _error{ - Name: name, - Message: messageFromDescription(description, argumentList...), - Line: -1, - } - //error := _error{ - // Name: name, - // Message: messageFromDescription(description, argumentList...), - // Line: -1, - //} - //if node != nil { - // error.Line = ast.position() - //} - //return error -} - -func newReferenceError(argumentList ...interface{}) _error { - return newError("ReferenceError", argumentList...) -} - -func newTypeError(argumentList ...interface{}) _error { - return newError("TypeError", argumentList...) -} - -func newRangeError(argumentList ...interface{}) _error { - return newError("RangeError", argumentList...) -} - -func newSyntaxError(argumentList ...interface{}) _error { - return newError("SyntaxError", argumentList...) -} - -func newURIError(argumentList ...interface{}) _error { - return newError("URIError", argumentList...) -} - -func typeErrorResult(throw bool) bool { - if throw { - panic(newTypeError()) - } - return false -} - -func catchPanic(function func()) (err error) { - // FIXME - defer func() { - if caught := recover(); caught != nil { - if exception, ok := caught.(*_exception); ok { - caught = exception.eject() - } - switch caught := caught.(type) { - //case *_syntaxError: - // err = errors.New(fmt.Sprintf("%s (line %d)", caught.String(), caught.Line+0)) - // return - case _error: - if caught.Line == -1 { - err = errors.New(caught.String()) - } else { - // We're 0-based (for now), hence the + 1 - err = errors.New(fmt.Sprintf("%s (line %d)", caught.String(), caught.Line+1)) - } - return - case Value: - err = errors.New(toString(caught)) - return - //case string: - // if strings.HasPrefix(caught, "SyntaxError:") { - // err = errors.New(caught) - // return - // } - } - panic(caught) - } - }() - function() - return nil -} |