Exemplo n.º 1
0
func makeValue(t Type, v *js.Object, fl flag) Value {
	rt := t.common()
	if t.Kind() == Array || t.Kind() == Struct || t.Kind() == Ptr {
		return Value{rt, unsafe.Pointer(v.Unsafe()), fl | flag(t.Kind())}
	}
	return Value{rt, unsafe.Pointer(js.Global.Call("$newDataPointer", v, jsType(rt.ptrTo())).Unsafe()), fl | flag(t.Kind()) | flagIndir}
}
Exemplo n.º 2
0
func cvtDirect(v Value, typ Type) Value {
	var srcVal = v.object()
	if srcVal == jsType(v.typ).Get("nil") {
		return makeValue(typ, jsType(typ).Get("nil"), v.flag)
	}

	var val *js.Object
	switch k := typ.Kind(); k {
	case Slice:
		slice := jsType(typ).New(srcVal.Get("$array"))
		slice.Set("$offset", srcVal.Get("$offset"))
		slice.Set("$length", srcVal.Get("$length"))
		slice.Set("$capacity", srcVal.Get("$capacity"))
		val = js.Global.Call("$newDataPointer", slice, jsType(PtrTo(typ)))
	case Ptr:
		if typ.Elem().Kind() == Struct {
			if typ.Elem() == v.typ.Elem() {
				val = srcVal
				break
			}
			val = jsType(typ).New()
			copyStruct(val, srcVal, typ.Elem())
			break
		}
		val = jsType(typ).New(srcVal.Get("$get"), srcVal.Get("$set"))
	case Struct:
		val = jsType(typ).Get("ptr").New()
		copyStruct(val, srcVal, typ)
	case Array, Bool, Chan, Func, Interface, Map, String:
		val = js.InternalObject(v.ptr)
	default:
		panic(&ValueError{"reflect.Convert", k})
	}
	return Value{typ.common(), unsafe.Pointer(val.Unsafe()), v.flag&(flagRO|flagIndir) | flag(typ.Kind())}
}
Exemplo n.º 3
0
func makeValue(t Type, v js.Object, fl flag) Value {
	rt := t.common()
	if t.Size() > ptrSize && t.Kind() != Array && t.Kind() != Struct {
		return Value{rt, unsafe.Pointer(js.Global.Call("go$newDataPointer", v, jsType(rt.ptrTo())).Unsafe()), fl | flag(t.Kind())<<flagKindShift | flagIndir}
	}
	return Value{rt, unsafe.Pointer(v.Unsafe()), fl | flag(t.Kind())<<flagKindShift}
}
Exemplo n.º 4
0
func makeValue(t Type, v js.Object, fl flag) Value {
	rt := t.common()
	if t.Kind() == Array || t.Kind() == Struct || rt.pointers() {
		return Value{rt, unsafe.Pointer(v.Unsafe()), 0, fl | flag(t.Kind())<<flagKindShift}
	}
	if t.Size() > ptrSize || t.Kind() == String {
		return Value{rt, unsafe.Pointer(js.Global.Call("$newDataPointer", v, jsType(rt.ptrTo())).Unsafe()), 0, fl | flag(t.Kind())<<flagKindShift | flagIndir}
	}
	return Value{rt, nil, uintptr(unsafe.Pointer(v.Unsafe())), fl | flag(t.Kind())<<flagKindShift}
}
Exemplo n.º 5
0
func makeIword(t Type, v js.Object) iword {
	if t.Size() > ptrSize && t.Kind() != Array && t.Kind() != Struct {
		return iword(js.Global.Call("go$newDataPointer", v, jsType(PtrTo(t))).Unsafe())
	}
	return iword(v.Unsafe())
}
Exemplo n.º 6
0
func makePointer(t Type, v js.Object) unsafe.Pointer {
	if t.Size() > ptrSize && t.Kind() != Array && t.Kind() != Struct {
		return unsafe.Pointer(js.Global.Call("$newDataPointer", v, jsType(PtrTo(t))).Unsafe())
	}
	return unsafe.Pointer(v.Unsafe())
}