Parse args sent through evaluation function
Previously they'd go in still stringified so we didn't get a chance to convert buffer objects back to buffers, for example, making things like `fs.write` write `[object Object]` to files.
This commit is contained in:
@ -4,7 +4,7 @@ import { logger, field } from "@coder/logger";
|
||||
import { ReadWriteConnection, InitData, OperatingSystem, SharedProcessData } from "../common/connection";
|
||||
import { Disposer, stringify, parse } from "../common/util";
|
||||
import { NewEvalMessage, ServerMessage, EvalDoneMessage, EvalFailedMessage, ClientMessage, WorkingInitMessage, EvalEventMessage } from "../proto";
|
||||
import { ActiveEval } from "./command";
|
||||
import { ActiveEval } from "./evaluate";
|
||||
|
||||
/**
|
||||
* Client accepts an arbitrary connection intended to communicate with the Server.
|
||||
|
@ -12,11 +12,6 @@ export interface ActiveEvaluation {
|
||||
|
||||
declare var __non_webpack_require__: typeof require;
|
||||
export const evaluate = (connection: SendableConnection, message: NewEvalMessage, onDispose: () => void): ActiveEvaluation | void => {
|
||||
const argStr: string[] = [];
|
||||
message.getArgsList().forEach((value) => {
|
||||
argStr.push(value);
|
||||
});
|
||||
|
||||
/**
|
||||
* Send the response and call onDispose.
|
||||
*/
|
||||
@ -94,11 +89,12 @@ export const evaluate = (connection: SendableConnection, message: NewEvalMessage
|
||||
process: {
|
||||
env: process.env,
|
||||
},
|
||||
args: message.getArgsList().map(parse),
|
||||
};
|
||||
|
||||
let value: any; // tslint:disable-line no-any
|
||||
try {
|
||||
const code = `(${message.getFunction()})(${eventEmitter ? "eventEmitter, " : ""}${argStr.join(",")});`;
|
||||
const code = `(${message.getFunction()})(${eventEmitter ? "eventEmitter, " : ""}...args);`;
|
||||
value = vm.runInNewContext(code, sandbox, {
|
||||
// If the code takes longer than this to return, it is killed and throws.
|
||||
timeout: message.getTimeout() || 15000,
|
||||
|
Reference in New Issue
Block a user