1package otto 2 3import ( 4 "fmt" 5) 6 7func builtinError(call FunctionCall) Value { 8 return toValue_object(call.runtime.newError("Error", call.Argument(0), 1)) 9} 10 11func builtinNewError(self *_object, argumentList []Value) Value { 12 return toValue_object(self.runtime.newError("Error", valueOfArrayIndex(argumentList, 0), 0)) 13} 14 15func builtinError_toString(call FunctionCall) Value { 16 thisObject := call.thisObject() 17 if thisObject == nil { 18 panic(call.runtime.panicTypeError()) 19 } 20 21 name := "Error" 22 nameValue := thisObject.get("name") 23 if nameValue.IsDefined() { 24 name = nameValue.string() 25 } 26 27 message := "" 28 messageValue := thisObject.get("message") 29 if messageValue.IsDefined() { 30 message = messageValue.string() 31 } 32 33 if len(name) == 0 { 34 return toValue_string(message) 35 } 36 37 if len(message) == 0 { 38 return toValue_string(name) 39 } 40 41 return toValue_string(fmt.Sprintf("%s: %s", name, message)) 42} 43 44func (runtime *_runtime) newEvalError(message Value) *_object { 45 self := runtime.newErrorObject("EvalError", message, 0) 46 self.prototype = runtime.global.EvalErrorPrototype 47 return self 48} 49 50func builtinEvalError(call FunctionCall) Value { 51 return toValue_object(call.runtime.newEvalError(call.Argument(0))) 52} 53 54func builtinNewEvalError(self *_object, argumentList []Value) Value { 55 return toValue_object(self.runtime.newEvalError(valueOfArrayIndex(argumentList, 0))) 56} 57 58func (runtime *_runtime) newTypeError(message Value) *_object { 59 self := runtime.newErrorObject("TypeError", message, 0) 60 self.prototype = runtime.global.TypeErrorPrototype 61 return self 62} 63 64func builtinTypeError(call FunctionCall) Value { 65 return toValue_object(call.runtime.newTypeError(call.Argument(0))) 66} 67 68func builtinNewTypeError(self *_object, argumentList []Value) Value { 69 return toValue_object(self.runtime.newTypeError(valueOfArrayIndex(argumentList, 0))) 70} 71 72func (runtime *_runtime) newRangeError(message Value) *_object { 73 self := runtime.newErrorObject("RangeError", message, 0) 74 self.prototype = runtime.global.RangeErrorPrototype 75 return self 76} 77 78func builtinRangeError(call FunctionCall) Value { 79 return toValue_object(call.runtime.newRangeError(call.Argument(0))) 80} 81 82func builtinNewRangeError(self *_object, argumentList []Value) Value { 83 return toValue_object(self.runtime.newRangeError(valueOfArrayIndex(argumentList, 0))) 84} 85 86func (runtime *_runtime) newURIError(message Value) *_object { 87 self := runtime.newErrorObject("URIError", message, 0) 88 self.prototype = runtime.global.URIErrorPrototype 89 return self 90} 91 92func (runtime *_runtime) newReferenceError(message Value) *_object { 93 self := runtime.newErrorObject("ReferenceError", message, 0) 94 self.prototype = runtime.global.ReferenceErrorPrototype 95 return self 96} 97 98func builtinReferenceError(call FunctionCall) Value { 99 return toValue_object(call.runtime.newReferenceError(call.Argument(0))) 100} 101 102func builtinNewReferenceError(self *_object, argumentList []Value) Value { 103 return toValue_object(self.runtime.newReferenceError(valueOfArrayIndex(argumentList, 0))) 104} 105 106func (runtime *_runtime) newSyntaxError(message Value) *_object { 107 self := runtime.newErrorObject("SyntaxError", message, 0) 108 self.prototype = runtime.global.SyntaxErrorPrototype 109 return self 110} 111 112func builtinSyntaxError(call FunctionCall) Value { 113 return toValue_object(call.runtime.newSyntaxError(call.Argument(0))) 114} 115 116func builtinNewSyntaxError(self *_object, argumentList []Value) Value { 117 return toValue_object(self.runtime.newSyntaxError(valueOfArrayIndex(argumentList, 0))) 118} 119 120func builtinURIError(call FunctionCall) Value { 121 return toValue_object(call.runtime.newURIError(call.Argument(0))) 122} 123 124func builtinNewURIError(self *_object, argumentList []Value) Value { 125 return toValue_object(self.runtime.newURIError(valueOfArrayIndex(argumentList, 0))) 126} 127