// Object[] -> []interface{} func convertArgs(this, argArr *rtc.Obj, method *rtc.Method) []interface{} { if method.ArgSlotCount() == 0 { return nil } if method.ArgSlotCount() == 1 && !method.IsStatic() { return []interface{}{this} } argObjs := argArr.Refs() argTypes := method.ParsedDescriptor().ParameterTypes() args := make([]interface{}, method.ArgSlotCount()) j := 0 if !method.IsStatic() { args[0] = this j = 1 } for i, argType := range argTypes { argObj := argObjs[i] if argType.IsBaseType() { // todo unboxed := box.Unbox(argObj, argType.Descriptor()) args[i+j] = unboxed if argType.IsLongOrDouble() { j++ } } else { args[i+j] = argObj } } return args }
// public static native void set(Object array, int index, Object value) // throws IllegalArgumentException, ArrayIndexOutOfBoundsException; // (Ljava/lang/Object;ILjava/lang/Object;)V func set(frame *rtda.Frame) { vars := frame.LocalVars() arr := vars.GetRef(0) index := vars.GetInt(1) value := vars.GetRef(2) if arr == nil { frame.Thread().ThrowNPE() return } if !arr.IsArray() { frame.Thread().ThrowIllegalArgumentException("Argument is not an array") return } if index < 0 || index >= heap.ArrayLength(arr) { frame.Thread().ThrowArrayIndexOutOfBoundsExceptionNoMsg() return } if !arr.IsPrimitiveArray() { arr.Refs()[index] = value return } //TODO Consistent with the current need to determine whether the type and source type // Such as: // [I // java/lang/Integer // frame.Thread().ThrowIllegalArgumentException("argument type mismatch") // primitive array primitiveDescriptorStr := arr.Class().Name()[1:] if primitiveDescriptorStr != value.GetPrimitiveDescriptor() { frame.Thread().ThrowIllegalArgumentException("argument type mismatch") return } unboxed := box.Unbox(value, primitiveDescriptorStr) primitiveDescriptor := arr.Class().Name()[1] switch primitiveDescriptor { case 'Z': arr.Booleans()[index] = int8(unboxed.(int32)) case 'B': arr.Bytes()[index] = int8(unboxed.(int32)) case 'C': arr.Chars()[index] = uint16(unboxed.(int32)) case 'S': arr.Shorts()[index] = int16(unboxed.(int32)) case 'I': arr.Ints()[index] = unboxed.(int32) case 'J': arr.Longs()[index] = unboxed.(int64) case 'F': arr.Floats()[index] = unboxed.(float32) case 'D': arr.Doubles()[index] = unboxed.(float64) } }
// java/net/PlainSocketImpl~socketSetOption~ // (IZLjava/lang/Object;)V // abstract void socketSetOption(int cmd, boolean on, Object value) // throws SocketException; func psi_socketSetOption(frame *rtda.Frame) { vars := frame.LocalVars() this := vars.GetThis() cmd := vars.GetInt(1) //on := vars.GetBoolean(2) value := vars.GetRef(3) switch cmd { case 0x1006: //timeout _timeout := box.Unbox(value, "I").(int32) fdObj := this.GetFieldValue("fd", "Ljava/io/FileDescriptor;").(*rtc.Obj) if fdObj.Extra() != nil { conn := fdObj.Extra().(net.Conn) conn.SetReadDeadline(time.Now().Add(time.Duration(_timeout) * time.Millisecond)) } break default: break } }