Skip to content

Instantly share code, notes, and snippets.

@crazy2be
Created July 3, 2011 21:32
Show Gist options
  • Save crazy2be/1062628 to your computer and use it in GitHub Desktop.
Save crazy2be/1062628 to your computer and use it in GitHub Desktop.
// native.go
// Have to add this function for native_test.go
func ptrToJSValueRef(ptr unsafe.Pointer) C.JSValueRef {
return C.JSValueRef(ptr)
}
// native_test.go
func PrettyPrintValArr(t *testing.T, values []*Value) {
for _, val := range values {
tlog(t, val)
}
}
func ValArrToStrings(t *testing.T, values []*Value) {
for _, val := range values {
tlog(t, val.ctx.ToStringOrDie(val))
}
}
func TestNewCValueArray(t *testing.T) {
ctx := NewContext()
defer ctx.Release()
valarr := make([]*Value, 5)
valarr[0] = ctx.NewValue(0)
valarr[1] = ctx.NewNumberValue(1.3)
valarr[2] = ctx.NewValue(nil)
valarr[3] = ctx.NewValue(2309240)
valarr[4] = ctx.NewValue(0x934)
cptr, size := ctx.newCValueArray(valarr)
val1 := ctx.newValue(*cptr)
val2 := ctx.newValue(ptrToJSValueRef(unsafe.Pointer(uintptr(unsafe.Pointer(cptr))+4)))
tlog(t, ctx.ToStringOrDie(val1))
tlog(t, ctx.ToStringOrDie(val2))
origarray := ctx.newGoValueArray(unsafe.Pointer(cptr), uint(size))
assert.Equal(t, valarr, origarray)
PrettyPrintValArr(t, valarr)
PrettyPrintValArr(t, origarray)
ValArrToStrings(t, valarr)
ValArrToStrings(t, origarray)
// tlog(t, ctx.ToStringOrDie(origarray[0]))
// tlog(t, ctx.ToStringOrDie(origarray[1]))
// tlog(t, ctx.ToStringOrDie(origarray[2]))
// tlog(t, ctx.ToStringOrDie(origarray[3]))
// tlog(t, ctx.ToStringOrDie(origarray[4]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment