-
Notifications
You must be signed in to change notification settings - Fork 586
/
type_error.go
58 lines (52 loc) · 1.64 KB
/
type_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package otto
func (rt *runtime) newErrorObject(name string, message Value, stackFramesToPop int) *object {
obj := rt.newClassObject(classErrorName)
if message.IsDefined() {
err := newError(rt, name, stackFramesToPop, "%s", message.string())
obj.defineProperty("message", err.messageValue(), 0o111, false)
obj.value = err
} else {
obj.value = newError(rt, name, stackFramesToPop)
}
obj.defineOwnProperty("stack", property{
value: propertyGetSet{
rt.newNativeFunction("get", "internal", 0, func(FunctionCall) Value {
return stringValue(obj.value.(ottoError).formatWithStack())
}),
&nilGetSetObject,
},
mode: modeConfigureMask & modeOnMask,
}, false)
return obj
}
func (rt *runtime) newErrorObjectError(err ottoError) *object {
obj := rt.newClassObject(classErrorName)
obj.defineProperty("message", err.messageValue(), 0o111, false)
obj.value = err
switch err.name {
case "EvalError":
obj.prototype = rt.global.EvalErrorPrototype
case "TypeError":
obj.prototype = rt.global.TypeErrorPrototype
case "RangeError":
obj.prototype = rt.global.RangeErrorPrototype
case "ReferenceError":
obj.prototype = rt.global.ReferenceErrorPrototype
case "SyntaxError":
obj.prototype = rt.global.SyntaxErrorPrototype
case "URIError":
obj.prototype = rt.global.URIErrorPrototype
default:
obj.prototype = rt.global.ErrorPrototype
}
obj.defineOwnProperty("stack", property{
value: propertyGetSet{
rt.newNativeFunction("get", "internal", 0, func(FunctionCall) Value {
return stringValue(obj.value.(ottoError).formatWithStack())
}),
&nilGetSetObject,
},
mode: modeConfigureMask & modeOnMask,
}, false)
return obj
}