2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// 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 JSInteger 类型实现
|
2022-10-04 13:21:05 +08:00
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-04 22:34:57 +08:00
|
|
|
"github.com/energye/energy/consts"
|
2022-10-04 13:21:05 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type JSInteger 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 *JSInteger) AsInteger() *JSInteger {
|
|
|
|
return m
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *JSInteger) Float() float64 {
|
|
|
|
if val, err := m.IntegerValue(); err == nil {
|
|
|
|
return float64(val)
|
|
|
|
} else {
|
|
|
|
return 0.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *JSInteger) Value() int32 {
|
|
|
|
if val, err := m.IntegerValue(); err == nil {
|
|
|
|
return val
|
|
|
|
} else {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (m *JSInteger) SetValue(value int32) {
|
2023-02-22 12:31:35 +08:00
|
|
|
m.valueType.Jsv = consts.V8_VALUE_INT
|
|
|
|
m.valueType.Gov = consts.GO_VALUE_INT32
|
2022-10-04 13:21:05 +08:00
|
|
|
m.value = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *JSInteger) ToString() string {
|
|
|
|
if val, err := m.IntegerValue(); err == nil {
|
|
|
|
return fmt.Sprintf("%v", val)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|