energy/cef/cef-v8-js-boolean.go

46 lines
850 B
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
2023-02-20 14:42:17 +08:00
// V8 JSValue JSBoolean 类型实现
2022-10-04 13:21:05 +08:00
package cef
2022-10-04 22:34:57 +08:00
import "github.com/energye/energy/consts"
2022-10-04 13:21:05 +08:00
type JSBoolean struct {
2023-02-21 23:16:35 +08:00
V8Value
2022-10-04 13:21:05 +08:00
}
2023-02-21 23:16:35 +08:00
func (m *JSBoolean) AsBoolean() *JSBoolean {
return m
2022-10-04 13:21:05 +08:00
}
func (m *JSBoolean) Value() bool {
if val, err := m.BooleanValue(); err == nil {
return val
}
return false
}
func (m *JSBoolean) SetValue(value bool) {
2023-02-22 12:31:35 +08:00
m.valueType.Jsv = consts.V8_VALUE_BOOLEAN
m.valueType.Gov = consts.GO_VALUE_BOOL
2022-10-04 13:21:05 +08:00
m.value = value
}
func (m *JSBoolean) ToString() string {
if val, err := m.BooleanValue(); err == nil {
if val {
return "true"
}
return "false"
}
return ""
}