aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/robertkrimen/otto/type_error.go
blob: 84e5d79b19c7d8f0593ff823fcf25148b6bd9dae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package otto

func (rt *_runtime) newErrorObject(name string, message Value, stackFramesToPop int) *_object {
    self := rt.newClassObject("Error")
    if message.IsDefined() {
        msg := message.string()
        self.defineProperty("message", toValue_string(msg), 0111, false)
        self.value = newError(rt, name, stackFramesToPop, msg)
    } else {
        self.value = newError(rt, name, stackFramesToPop)
    }

    self.defineOwnProperty("stack", _property{
        value: _propertyGetSet{
            rt.newNativeFunction("get", "internal", 0, func(FunctionCall) Value {
                return toValue_string(self.value.(_error).formatWithStack())
            }),
            &_nilGetSetObject,
        },
        mode: modeConfigureMask & modeOnMask,
    }, false)

    return self
}