single typedArray ref
parent
7086fbdd29
commit
801fd37d20
41
bridge.go
41
bridge.go
|
@ -109,14 +109,14 @@ func (b *Bridge) addValues() {
|
||||||
props: map[string]interface{}{
|
props: map[string]interface{}{
|
||||||
"Object": propObject("Object", nil),
|
"Object": propObject("Object", nil),
|
||||||
"Array": propObject("Array", nil),
|
"Array": propObject("Array", nil),
|
||||||
"Int8Array": typedArray("Int8Array"),
|
"Int8Array": typedArray,
|
||||||
"Int16Array": typedArray("Int16Array"),
|
"Int16Array": typedArray,
|
||||||
"Int32Array": typedArray("Int32Array"),
|
"Int32Array": typedArray,
|
||||||
"Uint8Array": typedArray("Uint8Array"),
|
"Uint8Array": typedArray,
|
||||||
"Uint16Array": typedArray("Uint16Array"),
|
"Uint16Array": typedArray,
|
||||||
"Uint32Array": typedArray("Uint32Array"),
|
"Uint32Array": typedArray,
|
||||||
"Float32Array": typedArray("Float32Array"),
|
"Float32Array": typedArray,
|
||||||
"Float64Array": typedArray("Float64Array"),
|
"Float64Array": typedArray,
|
||||||
"process": propObject("process", nil),
|
"process": propObject("process", nil),
|
||||||
"Date": &object{name: "Date", new: func(args []interface{}) interface{} {
|
"Date": &object{name: "Date", new: func(args []interface{}) interface{} {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
|
@ -366,6 +366,10 @@ func (b *Bridge) storeValue(addr int32, v interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rv := reflect.TypeOf(v)
|
rv := reflect.TypeOf(v)
|
||||||
|
if !rv.Comparable() {
|
||||||
|
panic(fmt.Sprintf("%T is not comparable", v))
|
||||||
|
}
|
||||||
|
|
||||||
if rv.Kind() == reflect.Ptr {
|
if rv.Kind() == reflect.Ptr {
|
||||||
rv = rv.Elem()
|
rv = rv.Elem()
|
||||||
}
|
}
|
||||||
|
@ -413,17 +417,16 @@ type array struct {
|
||||||
func (a *array) data() []byte {
|
func (a *array) data() []byte {
|
||||||
return a.buf.data[a.offset : a.offset+a.length]
|
return a.buf.data[a.offset : a.offset+a.length]
|
||||||
}
|
}
|
||||||
func typedArray(name string) *object {
|
|
||||||
return &object{
|
var typedArray = &object{
|
||||||
name: name,
|
name: "TypedArray",
|
||||||
new: func(args []interface{}) interface{} {
|
new: func(args []interface{}) interface{} {
|
||||||
return &array{
|
return &array{
|
||||||
buf: args[0].(*buffer),
|
buf: args[0].(*buffer),
|
||||||
offset: int(args[1].(float64)),
|
offset: int(args[1].(float64)),
|
||||||
length: int(args[2].(float64)),
|
length: int(args[2].(float64)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type buffer struct {
|
type buffer struct {
|
||||||
|
|
Loading…
Reference in New Issue