1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-19 19:55:30 +08:00
otto/builtin_error.go
Robert Krimen c55510cb36 Inline context initialization & improve _object.value
* Context setup is now done via _newContext.
* _newContext is a function that resides in inline.go. _newContext is very flat,
resulting in almost no function calls (a 180 from the earlier status quo).
* inline.go is a Go source file that is built by Perl (via inline).
* Lots of crufty functions removed (along with all of their TODO & FIXME).
* In addition, before, the underlying value of _object.value was a pointer to
something. This made for extra work, since the type of _object.value is interface{},
which is already something of a pointer. Now, the underlying value of _object.value
in Function, Date, RegExp, ..., is a struct value.
* type_function.go was streamlined, removing superfluous struct fields and methods.
* There is now less "digging" to get to the actual value of a function, which is important
when makings lots of calls.

Before (without inline):

    PASS
    BenchmarkNew        2000           1067871 ns/op
    ok      github.com/robertkrimen/otto    3.336s
    PASS
    BenchmarkNew        2000           1077644 ns/op
    ok      github.com/robertkrimen/otto    3.367s

After (with inline):

    PASS
    BenchmarkNew       10000            364418 ns/op
    ok      github.com/robertkrimen/otto    4.616s
    PASS
    BenchmarkNew       10000            307241 ns/op
    ok      github.com/robertkrimen/otto    4.051s

This (partially) fixes #22
2013-06-09 18:28:18 -07:00

86 lines
2.7 KiB
Go

package otto
func (runtime *_runtime) newEvalError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.EvalErrorPrototype
return self
}
func builtinEvalError(call FunctionCall) Value {
return toValue(call.runtime.newEvalError(call.Argument(0)))
}
func builtinNewEvalError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newEvalError(valueOfArrayIndex(argumentList, 0)))
}
func (runtime *_runtime) newTypeError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.TypeErrorPrototype
return self
}
func builtinTypeError(call FunctionCall) Value {
return toValue(call.runtime.newTypeError(call.Argument(0)))
}
func builtinNewTypeError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newTypeError(valueOfArrayIndex(argumentList, 0)))
}
func (runtime *_runtime) newRangeError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.RangeErrorPrototype
return self
}
func builtinRangeError(call FunctionCall) Value {
return toValue(call.runtime.newRangeError(call.Argument(0)))
}
func builtinNewRangeError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newRangeError(valueOfArrayIndex(argumentList, 0)))
}
func (runtime *_runtime) newURIError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.URIErrorPrototype
return self
}
func (runtime *_runtime) newReferenceError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.ReferenceErrorPrototype
return self
}
func builtinReferenceError(call FunctionCall) Value {
return toValue(call.runtime.newReferenceError(call.Argument(0)))
}
func builtinNewReferenceError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newReferenceError(valueOfArrayIndex(argumentList, 0)))
}
func (runtime *_runtime) newSyntaxError(message Value) *_object {
self := runtime.newErrorObject(message)
self.prototype = runtime.Global.SyntaxErrorPrototype
return self
}
func builtinSyntaxError(call FunctionCall) Value {
return toValue(call.runtime.newSyntaxError(call.Argument(0)))
}
func builtinNewSyntaxError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newSyntaxError(valueOfArrayIndex(argumentList, 0)))
}
func builtinURIError(call FunctionCall) Value {
return toValue(call.runtime.newURIError(call.Argument(0)))
}
func builtinNewURIError(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newURIError(valueOfArrayIndex(argumentList, 0)))
}