Compare commits

..

No commits in common. "803ad0277235cd2b54bcc961d21b44147820d305" and "0f57e8ffcb5bda819ef6cf6c47a22079d0bf52d2" have entirely different histories.

2 changed files with 11 additions and 22 deletions

View File

@ -39,7 +39,7 @@ type Message struct {
Type MsgType `json:"type"`
Id int64 `json:"id"`
Method string `json:"method"`
Args Vals `json:"args"`
Params Vals `json:"params"`
Result Vals `json:"result"`
Error string `json:"error"`
}
@ -118,25 +118,14 @@ func (ipc *ipcCommon) handleCall(msg Message) {
}
argsCount := method.Type().NumIn()
if len(msg.Args) != argsCount {
ipc.sendResponse(msg.Id, nil, fmt.Errorf("args count mismatch: expected %d, got %d", argsCount, len(msg.Args)))
if len(msg.Params) != argsCount {
ipc.sendResponse(msg.Id, nil, fmt.Errorf("args count mismatch: expected %d, got %d", argsCount, len(msg.Params)))
return
}
var args []reflect.Value
for i, arg := range msg.Args {
paramType := method.Type().In(i)
argType := reflect.TypeOf(arg)
// JSON decodes any number to float64. If we need int, we should check and convert
if paramType.Kind() == reflect.Int && argType.Kind() == reflect.Float64 {
floatArg := arg.(float64)
if float64(int64(floatArg)) == floatArg && !paramType.OverflowInt(int64(floatArg)) {
arg = arg.(int)
}
}
args = append(args, reflect.ValueOf(paramType))
for _, param := range msg.Params {
args = append(args, reflect.ValueOf(param))
}
results := method.Call(args)
@ -232,7 +221,7 @@ func (ipc *ipcCommon) Call(method string, params ...any) (Vals, error) {
Type: MsgCall,
Id: id,
Method: method,
Args: params,
Params: params,
}
if err := ipc.sendMsg(msg); err != nil {

View File

@ -20,7 +20,7 @@ interface CallMessage {
type: MsgType.Call,
id: number,
method: string;
args: Vals;
params: Vals;
}
interface ResponseMessage {
@ -129,18 +129,18 @@ abstract class IPCCommon {
}
const argsCount = method.length;
if (msg.args.length !== argsCount) {
if (msg.params.length !== argsCount) {
this.sendMsg({
type: MsgType.Response,
id: msg.id,
error: `argument count mismatch: expected ${ argsCount }, got ${ msg.args.length }`
error: `argument count mismatch: expected ${ argsCount }, got ${ msg.params.length }`
});
return;
}
try {
this.processingCalls++;
let result = method.apply(endpoint, msg.args);
let result = method.apply(endpoint, msg.params);
if (result instanceof Promise) {
result = await result;
}
@ -192,7 +192,7 @@ abstract class IPCCommon {
}
};
try {
this.sendMsg({type: MsgType.Call, id, method, args: params});
this.sendMsg({type: MsgType.Call, id, method, params});
} catch (e) {
delete this.pendingCalls[id];
reject(new Error(`send call: ${ e }`));