Convert indentation to tabs
This commit is contained in:
parent
8ed940ac09
commit
984420d181
@ -3,59 +3,59 @@ import { NewEvalMessage, TypedValue, EvalFailedMessage, EvalDoneMessage, ServerM
|
|||||||
import { SendableConnection } from "../common/connection";
|
import { SendableConnection } from "../common/connection";
|
||||||
|
|
||||||
export const evaluate = async (connection: SendableConnection, message: NewEvalMessage): Promise<void> => {
|
export const evaluate = async (connection: SendableConnection, message: NewEvalMessage): Promise<void> => {
|
||||||
const argStr: string[] = [];
|
const argStr: string[] = [];
|
||||||
message.getArgsList().forEach((value) => {
|
message.getArgsList().forEach((value) => {
|
||||||
argStr.push(value);
|
argStr.push(value);
|
||||||
});
|
});
|
||||||
const sendResp = (resp: any): void => {
|
const sendResp = (resp: any): void => {
|
||||||
const evalDone = new EvalDoneMessage();
|
const evalDone = new EvalDoneMessage();
|
||||||
evalDone.setId(message.getId());
|
evalDone.setId(message.getId());
|
||||||
const tof = typeof resp;
|
const tof = typeof resp;
|
||||||
if (tof !== "undefined") {
|
if (tof !== "undefined") {
|
||||||
const tv = new TypedValue();
|
const tv = new TypedValue();
|
||||||
let t: TypedValue.Type;
|
let t: TypedValue.Type;
|
||||||
switch (tof) {
|
switch (tof) {
|
||||||
case "string":
|
case "string":
|
||||||
t = TypedValue.Type.STRING;
|
t = TypedValue.Type.STRING;
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
t = TypedValue.Type.BOOLEAN;
|
t = TypedValue.Type.BOOLEAN;
|
||||||
break;
|
break;
|
||||||
case "object":
|
case "object":
|
||||||
t = TypedValue.Type.OBJECT;
|
t = TypedValue.Type.OBJECT;
|
||||||
break;
|
break;
|
||||||
case "number":
|
case "number":
|
||||||
t = TypedValue.Type.NUMBER;
|
t = TypedValue.Type.NUMBER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sendErr(EvalFailedMessage.Reason.EXCEPTION, `unsupported response type ${tof}`);
|
sendErr(EvalFailedMessage.Reason.EXCEPTION, `unsupported response type ${tof}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tv.setValue(tof === "string" ? resp : JSON.stringify(resp));
|
tv.setValue(tof === "string" ? resp : JSON.stringify(resp));
|
||||||
tv.setType(t);
|
tv.setType(t);
|
||||||
evalDone.setResponse(tv);
|
evalDone.setResponse(tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverMsg = new ServerMessage();
|
const serverMsg = new ServerMessage();
|
||||||
serverMsg.setEvalDone(evalDone);
|
serverMsg.setEvalDone(evalDone);
|
||||||
connection.send(serverMsg.serializeBinary());
|
connection.send(serverMsg.serializeBinary());
|
||||||
};
|
};
|
||||||
const sendErr = (reason: EvalFailedMessage.Reason, msg: string): void => {
|
const sendErr = (reason: EvalFailedMessage.Reason, msg: string): void => {
|
||||||
const evalFailed = new EvalFailedMessage();
|
const evalFailed = new EvalFailedMessage();
|
||||||
evalFailed.setId(message.getId());
|
evalFailed.setId(message.getId());
|
||||||
evalFailed.setReason(reason);
|
evalFailed.setReason(reason);
|
||||||
evalFailed.setMessage(msg);
|
evalFailed.setMessage(msg);
|
||||||
|
|
||||||
const serverMsg = new ServerMessage();
|
const serverMsg = new ServerMessage();
|
||||||
serverMsg.setEvalFailed(evalFailed);
|
serverMsg.setEvalFailed(evalFailed);
|
||||||
connection.send(serverMsg.serializeBinary());
|
connection.send(serverMsg.serializeBinary());
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require, setTimeout }, {
|
const value = vm.runInNewContext(`(${message.getFunction()})(${argStr.join(",")})`, { require, setTimeout }, {
|
||||||
timeout: message.getTimeout() || 30000,
|
timeout: message.getTimeout() || 30000,
|
||||||
});
|
});
|
||||||
sendResp(await value);
|
sendResp(await value);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
sendErr(EvalFailedMessage.Reason.EXCEPTION, ex.toString());
|
sendErr(EvalFailedMessage.Reason.EXCEPTION, ex.toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -3,26 +3,26 @@ import { Client } from "../src/browser/client";
|
|||||||
import { Server } from "../src/node/server";
|
import { Server } from "../src/node/server";
|
||||||
|
|
||||||
export const createClient = (): Client => {
|
export const createClient = (): Client => {
|
||||||
const s2c = new Emitter<Uint8Array | Buffer>();
|
const s2c = new Emitter<Uint8Array | Buffer>();
|
||||||
const c2s = new Emitter<Uint8Array | Buffer>();
|
const c2s = new Emitter<Uint8Array | Buffer>();
|
||||||
|
|
||||||
new Server({
|
new Server({
|
||||||
close: () => undefined,
|
close: () => undefined,
|
||||||
onClose: () => undefined,
|
onClose: () => undefined,
|
||||||
onMessage: (cb) => {
|
onMessage: (cb) => {
|
||||||
c2s.event((d) => cb(d));
|
c2s.event((d) => cb(d));
|
||||||
},
|
},
|
||||||
send: (data) => setTimeout(() => s2c.emit(data), 0),
|
send: (data) => setTimeout(() => s2c.emit(data), 0),
|
||||||
});
|
});
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
close: () => undefined,
|
close: () => undefined,
|
||||||
onClose: () => undefined,
|
onClose: () => undefined,
|
||||||
onMessage: (cb) => {
|
onMessage: (cb) => {
|
||||||
s2c.event((d) => cb(d));
|
s2c.event((d) => cb(d));
|
||||||
},
|
},
|
||||||
send: (data) => setTimeout(() => c2s.emit(data), 0),
|
send: (data) => setTimeout(() => c2s.emit(data), 0),
|
||||||
});
|
});
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user