Skip to content

Instantly share code, notes, and snippets.

package main
import (
"os"
"io"
"fmt"
"rpc"
"rpc/jsonrpc"
)
panic:
runtime.panic+0xa4 ~/go/src/pkg/runtime/proc.c:1060
runtime.panic(0x80b2fb8, 0x967ac4a0)
gojs.value_to_javascript+0x4e ~/Src/gojs/_obj/base.cgo1.go:89
gojs.value_to_javascript(0x967ac490, 0x80b32a8, 0x85a02a00, 0x0, 0x0, ...)
gojs.*Context·NewValue+0x67 ~/Src/gojs/_obj/base.cgo1.go:882
gojs.*Context·NewValue(0x967ac490, 0x80b32a8, 0x85a02a00, 0x85a02a00, 0x1, ...)
gojs.*Context·EvaluateScript+0x155 ~/Src/gojs/_obj/base.cgo1.go:-24
gojs.*Context·EvaluateScript(0x967ac490, 0x80d8be8, 0x3, 0x967ac498, 0x80dea4c, ...)
// Given a slice of go-style Values, this function allocates a new array of c-style values and returns a pointer to the first element in the array, along with the length of the array.
func (ctx *Context) newCValueArray(val []*Value) (*C.JSValueRef, C.size_t) {
if len(val) == 0 {
return nil, 0
}
arr := make([]C.JSValueRef, len(val))
for i := 0; i < len(val); i++ {
arr[i] = val[i].ref
}
return &arr[0], C.size_t(len(arr))
@crazy2be
crazy2be / gist:1057936
Created July 1, 2011 05:45
My daily WTF.
func nativecallback_CallAsFunction_go(data_ptr unsafe.Pointer, ctx unsafe.Pointer, obj unsafe.Pointer, thisObject unsafe.Pointer, argumentCount uint, arguments unsafe.Pointer, exception *unsafe.Pointer) unsafe.Pointer {
defer func() {
if r := recover(); r != nil {
*exception = unsafe.Pointer(recover_to_javascript((*Context)(ctx), r))
}
}()
data := (*object_data)(data_ptr)
ret := data.val.Interface().(GoFunctionCallback)(
(*Context)(ctx), (*Object)(obj), (*Object)(thisObject), (*[1 << 14]*Value)(arguments)[0:argumentCount])
func (ctx *Context) newGoValueArray(ptr unsafe.Pointer, size uint) ([]*Value) {
goarr := make([]*Value, size)
for i := uint(0); i < size; i++ {
goarr[i] = ctx.newValue(C.JSValueRef(ptr))
ptr = unsafe.Pointer(4+uintptr(ptr))
}
return goarr
}
func (ctx *Context) newCValueArray(val []*Value) (*C.JSValueRef, C.size_t) {
if len(val) == 0 {
return nil, 0
}
arr := make([]C.JSValueRef, len(val))
for i := 0; i < len(val); i++ {
arr[i] = val[i].ref
}
return &arr[0], C.size_t(len(arr))
}
// 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 (e *Exception) debugString() (str string) {
defer func() {
if r := recover(); r != nil {
stringer, ok := r.(Stringer)
if !ok {
str = "Panic of non-string type when attempting to create string representation."
return
}
str = stringer.String()
return
@crazy2be
crazy2be / WriteInt
Created January 20, 2012 01:30
Shifty bits.go
func WriteInt(wr io.Writer, num uint64) error {
var shifty uint = 64 - 8 // 64 bit integer mines 8 bit integer (byte)
// Our algorithm simply doesn't write anything for a value of zero, but we still need to write something as per the protocol. Handle it as a special case.
if num == 0 {
return writeByte(wr, 0x00)
}
sentFirst := false
void test(HashTable* table) {
int size = 5;
printf("%s", ((*table)[5]).c_str());
bool errorThrown = false;
map<int, string> expected;
int exp;
int res;