Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
c4b0ac3a
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c4b0ac3a
编写于
3月 28, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade-dev v2.3.44
上级
ace6f197
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
74 deletion
+62
-74
cef/bind/v8-bind.go
cef/bind/v8-bind.go
+10
-7
cef/bind/v8-dynamic-type.go
cef/bind/v8-dynamic-type.go
+46
-61
cef/bind/v8-static-type.go
cef/bind/v8-static-type.go
+3
-4
cef/cef-v8-bind-render.go
cef/cef-v8-bind-render.go
+3
-2
未找到文件。
cef/bind/v8-bind.go
浏览文件 @
c4b0ac3a
...
...
@@ -14,6 +14,7 @@ import (
"container/list"
"fmt"
"github.com/energye/energy/pkgs/json"
"strings"
"sync"
"unsafe"
)
...
...
@@ -32,10 +33,11 @@ type v8bind struct {
// 参数
// name: 唯一字段名, 重复将被覆盖
// value: 值
func
(
m
*
v8bind
)
Set
(
name
string
,
value
JSValue
)
{
func
(
m
*
v8bind
)
Set
(
name
[]
string
,
value
JSValue
)
{
m
.
setLock
.
Lock
()
defer
m
.
setLock
.
Unlock
()
if
id
,
ok
:=
m
.
hasFieldCollection
[
name
];
ok
{
n
:=
strings
.
Join
(
name
,
"."
)
if
id
,
ok
:=
m
.
hasFieldCollection
[
n
];
ok
{
if
value
.
Id
()
!=
id
{
// remove old id
old
:=
m
.
Remove
(
id
)
...
...
@@ -43,7 +45,7 @@ func (m *v8bind) Set(name string, value JSValue) {
id
=
m
.
Add
(
value
)
value
.
setId
(
id
)
//update name id
m
.
hasFieldCollection
[
n
ame
]
=
id
m
.
hasFieldCollection
[
n
]
=
id
switch
old
.
(
type
)
{
case
JSValue
:
//old value set new id
...
...
@@ -54,7 +56,7 @@ func (m *v8bind) Set(name string, value JSValue) {
// create set new value and return new id
id
=
m
.
Add
(
value
)
value
.
setId
(
id
)
m
.
hasFieldCollection
[
n
ame
]
=
id
m
.
hasFieldCollection
[
n
]
=
id
}
}
...
...
@@ -88,8 +90,9 @@ func (m *v8bind) Remove(id uintptr) any {
return
nil
}
func
GetBinds
(
fn
func
(
binds
map
[
string
]
JSValue
))
{
//fn(bind.fieldCollection)
// GetBinds 获取绑定的字段
func
GetBinds
(
fn
func
(
hasFieldCollection
map
[
string
]
uintptr
,
fieldCollection
*
list
.
List
))
{
fn
(
bind
.
hasFieldCollection
,
bind
.
fieldCollection
)
}
func
Test
()
{
...
...
@@ -217,7 +220,7 @@ func Test() {
fmt
.
Println
(
"fieldCollection.Len():"
,
bind
.
fieldCollection
.
Len
(),
len
(
bind
.
hasFieldCollection
))
for
k
,
v
:=
range
bind
.
hasFieldCollection
{
jsv
:=
bind
.
GetJSValue
(
v
)
fmt
.
Println
(
"k:"
,
k
,
"v:"
,
v
,
"jsv:"
,
jsv
.
Type
(),
v
==
jsv
.
Id
())
fmt
.
Println
(
"k:"
,
k
,
"v:"
,
v
,
"jsv:"
,
jsv
.
Type
(),
v
==
jsv
.
Id
()
,
"name:"
,
jsv
.
Name
()
)
}
}
...
...
cef/bind/v8-dynamic-type.go
浏览文件 @
c4b0ac3a
...
...
@@ -21,7 +21,6 @@ import (
"github.com/energye/energy/pkgs/json"
"reflect"
"strconv"
"strings"
)
const
(
...
...
@@ -37,7 +36,7 @@ var (
//
// GO和JS动态变量类型
type
JSValue
interface
{
Name
()
string
//当前变量绑定的名称
Name
()
[]
string
//当前变量绑定的名称
Bytes
()
[]
byte
//变量值转换为字节
JSONString
()
string
//变量值转换为JSON String
SetValue
(
value
any
)
//设置新值
...
...
@@ -70,21 +69,19 @@ type JSValue interface {
// V8Value 绑定到JS的字段
type
V8Value
struct
{
id
uintptr
pName
string
name
string
name
[]
string
rv
*
reflect
.
Value
value
json
.
JSON
}
func
init
()
{
isMainProcess
=
common
.
Args
.
IsMain
()
//TODO dev
isMainProcess
=
common
.
Args
.
IsMain
()
}
func
(
m
*
V8Value
)
free
()
{
bind
.
Remove
(
m
.
Id
())
m
.
id
=
0
m
.
pName
=
""
m
.
name
=
""
m
.
name
=
nil
m
.
rv
=
nil
m
.
value
.
Free
()
}
...
...
@@ -128,16 +125,12 @@ func (m *V8Value) fieldToBind() {
}
// nameKey
func
(
m
*
V8Value
)
nameKey
()
string
{
var
build
strings
.
Builder
build
.
WriteString
(
m
.
pName
)
build
.
WriteString
(
"."
)
build
.
WriteString
(
m
.
name
)
m
.
name
=
build
.
String
()
build
.
Reset
()
func
(
m
*
V8Value
)
nameKey
(
name
string
)
[]
string
{
m
.
name
=
append
(
m
.
name
,
name
)
return
m
.
name
}
// createJSValue 创建 JSValue
func
(
m
*
V8Value
)
createJSValue
(
name
string
,
rv
*
reflect
.
Value
)
JSValue
{
kind
:=
rv
.
Kind
()
if
kind
==
reflect
.
Ptr
{
...
...
@@ -146,83 +139,73 @@ func (m *V8Value) createJSValue(name string, rv *reflect.Value) JSValue {
switch
kind
{
case
reflect
.
String
:
v
:=
new
(
jsString
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_STRING
,
V
:
rv
.
Interface
(),
S
:
rv
.
Len
()}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
v
:=
new
(
jsInteger
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_INT
,
V
:
rv
.
Interface
(),
S
:
strconv
.
IntSize
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
v
:=
new
(
jsInteger
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_UINT
,
V
:
rv
.
Interface
(),
S
:
strconv
.
IntSize
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Float32
,
reflect
.
Float64
:
v
:=
new
(
jsDouble
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_FLOAT64
,
V
:
rv
.
Interface
(),
S
:
8
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Bool
:
v
:=
new
(
jsBoolean
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_BOOL
,
V
:
rv
.
Interface
(),
S
:
1
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Struct
:
v
:=
new
(
jsObject
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_MAP
,
V
:
rv
.
Interface
(),
S
:
0
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Map
:
v
:=
new
(
jsObject
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_MAP
,
V
:
rv
.
Interface
(),
S
:
rv
.
Len
()}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Slice
:
v
:=
new
(
jsArray
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_SLICE
,
V
:
rv
.
Interface
(),
S
:
rv
.
Len
()}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
case
reflect
.
Func
:
v
:=
new
(
jsFunction
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_FUNC
,
V
:
rv
.
Interface
(),
S
:
0
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
default
:
v
:=
new
(
jsNull
)
v
.
name
=
name
v
.
pName
=
m
.
name
v
.
name
=
m
.
name
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_NIL
,
V
:
null
,
S
:
0
}
v
.
rv
=
rv
bind
.
Set
(
v
.
nameKey
(),
v
)
bind
.
Set
(
v
.
nameKey
(
name
),
v
)
return
v
}
}
...
...
@@ -232,6 +215,7 @@ func (m *V8Value) Bytes() []byte {
return
m
.
value
.
Bytes
()
}
// JSONString 返回 JSONString
func
(
m
*
V8Value
)
JSONString
()
string
{
return
string
(
m
.
Bytes
())
}
...
...
@@ -273,11 +257,12 @@ func (m *V8Value) SetValue(value any) {
func
(
m
*
V8Value
)
setId
(
id
uintptr
)
{
m
.
id
=
id
}
func
(
m
*
V8Value
)
Id
()
uintptr
{
return
m
.
id
}
func
(
m
*
V8Value
)
Name
()
string
{
func
(
m
*
V8Value
)
Name
()
[]
string
{
return
m
.
name
}
...
...
@@ -436,9 +421,9 @@ func NewInteger(name string, value int) JSInteger {
value
=
0
}
v
:=
new
(
jsInteger
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_INT
,
V
:
value
,
S
:
4
}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -451,9 +436,9 @@ func NewString(name, value string) JSString {
value
=
""
}
v
:=
new
(
jsString
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_STRING
,
V
:
value
,
S
:
len
(
value
)}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -466,9 +451,9 @@ func NewDouble(name string, value float64) JSDouble {
value
=
0
}
v
:=
new
(
jsDouble
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_FLOAT64
,
V
:
value
,
S
:
8
}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -481,9 +466,9 @@ func NewBoolean(name string, value bool) JSBoolean {
value
=
false
}
v
:=
new
(
jsBoolean
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_BOOL
,
V
:
value
,
S
:
1
}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -493,9 +478,9 @@ func NewNull(name string) JSNull {
return
nil
}
v
:=
new
(
jsNull
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_NIL
,
V
:
null
,
S
:
0
}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -505,9 +490,9 @@ func NewUndefined(name string) JSUndefined {
return
nil
}
v
:=
new
(
jsUndefined
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_NIL
,
V
:
undefined
,
S
:
0
}
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -524,10 +509,10 @@ func NewFunction(name string, fn any) JSFunction {
return
nil
}
v
:=
new
(
jsFunction
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_FUNC
,
V
:
&
rv
,
S
:
0
}
v
.
rv
=
&
rv
bind
.
Set
(
name
,
v
)
bind
.
Set
(
v
.
name
,
v
)
return
v
}
...
...
@@ -551,7 +536,7 @@ func NewObject(object any) JSObject {
return
nil
}
v
:=
new
(
jsObject
)
v
.
name
=
rv
.
Type
()
.
Elem
()
.
Name
()
v
.
name
=
[]
string
{
rv
.
Type
()
.
Elem
()
.
Name
()}
v
.
value
=
&
json
.
JsonData
{
T
:
consts
.
GO_VALUE_MAP
,
V
:
object
,
S
:
0
}
v
.
rv
=
&
rv
bind
.
Set
(
v
.
name
,
v
)
...
...
@@ -568,7 +553,7 @@ func NewArray(name string, values ...any) JSArray {
values
=
nil
}
v
:=
new
(
jsArray
)
v
.
name
=
name
v
.
name
=
[]
string
{
name
}
for
_
,
value
:=
range
values
{
v
.
Add
(
value
)
}
...
...
cef/bind/v8-static-type.go
浏览文件 @
c4b0ac3a
...
...
@@ -16,10 +16,9 @@
package
bind
// Bind 绑定Go类型
//
// 变量和函数绑定, 在Go中定义的字段绑定到JS中, 在Go中定义的函数导出到JS
//
// 支持类型 String = string , Integer = (int8 ~ uint64) , Double = (float32, float64), Boolean = bool, Function = func, Object = struct | map, Array = Slice
// 变量和函数绑定, 在Go中定义的字段绑定到JS中, 在Go中定义的函数导出到JS
// 不可改变类型
// 支持类型 String = string , Integer = (int8 ~ uint64) , Double = (float32, float64), Boolean = bool, Function = func, Object = struct | map, Array = Slice
func
Bind
(
name
string
,
bind
any
)
error
{
return
nil
}
cef/cef-v8-bind-render.go
浏览文件 @
c4b0ac3a
...
...
@@ -13,6 +13,7 @@ package cef
import
(
"bytes"
"container/list"
"fmt"
"github.com/energye/energy/cef/bind"
"github.com/energye/energy/pkgs/json"
...
...
@@ -32,8 +33,8 @@ func (m *bindRenderProcess) initBindIPC() {
return
}
m
.
isInitBindIPC
=
true
bind
.
GetBinds
(
func
(
binds
map
[
string
]
bind
.
JSValue
)
{
fmt
.
Println
(
"binds"
,
len
(
binds
))
bind
.
GetBinds
(
func
(
hasFieldCollection
map
[
string
]
uintptr
,
fieldCollection
*
list
.
List
)
{
fmt
.
Println
(
"binds"
,
len
(
hasFieldCollection
))
})
renderIPC
.
addCallback
(
func
(
channelId
int64
,
data
json
.
JSON
)
bool
{
if
data
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录