-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_bool.go
72 lines (58 loc) · 1.13 KB
/
value_bool.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package runtime
import (
"reflect"
"strconv"
)
type ValueBool struct {
*ValueBase
v bool
}
func NewBool(v bool) ValueBool {
if v {
return boolTrue
}
return boolFalse
}
func (v ValueBool) IsTrue() bool {
return v.v
}
func (v ValueBool) ToGoValue(*Context) interface{} {
return v.Value()
}
func (v ValueBool) GoType() reflect.Type {
return reflect.TypeOf(v.v)
}
func (v ValueBool) Value() bool {
return v.v
}
func (v ValueBool) CompareTo(other Value, c *Context) CompareResult {
if v2, ok := other.(ValueBool); ok {
if v.Value() == v2.Value() {
return CompareResultEqual
}
}
return CompareResultNotEqual
}
func (v ValueBool) GetMember(name string, c *Context) Value {
return getMemberByType(c, v, name)
}
func (ValueBool) GetIndex(int, *Context) Value {
return constUndefined
}
func (ValueBool) Type() ValueType {
return TypeBool
}
func (v ValueBool) ToString(*Context) string {
return strconv.FormatBool(v.Value())
}
func (v ValueBool) Hash() int64 {
if v.v {
return 1
} else {
return 0
}
}
var (
boolTrue = ValueBool{ValueBase: &ValueBase{}, v: true}
boolFalse = ValueBool{ValueBase: &ValueBase{}, v: false}
)