single typedArray ref

pull/2/head
vedhavyas 2019-08-22 17:24:00 -07:00
parent 7086fbdd29
commit 801fd37d20
No known key found for this signature in database
GPG Key ID: 317BF0923E3EB7E5
1 changed files with 22 additions and 19 deletions

View File

@ -109,14 +109,14 @@ func (b *Bridge) addValues() {
props: map[string]interface{}{
"Object": propObject("Object", nil),
"Array": propObject("Array", nil),
"Int8Array": typedArray("Int8Array"),
"Int16Array": typedArray("Int16Array"),
"Int32Array": typedArray("Int32Array"),
"Uint8Array": typedArray("Uint8Array"),
"Uint16Array": typedArray("Uint16Array"),
"Uint32Array": typedArray("Uint32Array"),
"Float32Array": typedArray("Float32Array"),
"Float64Array": typedArray("Float64Array"),
"Int8Array": typedArray,
"Int16Array": typedArray,
"Int32Array": typedArray,
"Uint8Array": typedArray,
"Uint16Array": typedArray,
"Uint32Array": typedArray,
"Float32Array": typedArray,
"Float64Array": typedArray,
"process": propObject("process", nil),
"Date": &object{name: "Date", new: func(args []interface{}) interface{} {
t := time.Now()
@ -366,6 +366,10 @@ func (b *Bridge) storeValue(addr int32, v interface{}) {
}
rv := reflect.TypeOf(v)
if !rv.Comparable() {
panic(fmt.Sprintf("%T is not comparable", v))
}
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
}
@ -413,9 +417,9 @@ type array struct {
func (a *array) data() []byte {
return a.buf.data[a.offset : a.offset+a.length]
}
func typedArray(name string) *object {
return &object{
name: name,
var typedArray = &object{
name: "TypedArray",
new: func(args []interface{}) interface{} {
return &array{
buf: args[0].(*buffer),
@ -424,7 +428,6 @@ func typedArray(name string) *object {
}
},
}
}
type buffer struct {
data []byte