Throw error when target executable cannot be found (#764)

This commit is contained in:
Saúl Ibarra Corretgé 2024-12-23 21:31:15 +01:00 committed by GitHub
parent 7f156b6ef9
commit e5915821be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

Binary file not shown.

View file

@ -48,7 +48,13 @@ export function compileStandalone(inFile, outFile, targetExe) {
const bytecode = new Uint8Array(bjson.write(code, JS_WRITE_OBJ_BYTECODE | JS_WRITE_OBJ_REFERENCE | JS_WRITE_OBJ_STRIP_SOURCE)); const bytecode = new Uint8Array(bjson.write(code, JS_WRITE_OBJ_BYTECODE | JS_WRITE_OBJ_REFERENCE | JS_WRITE_OBJ_STRIP_SOURCE));
// Step 2: copy the bytecode to the end of the executable and add a marker. // Step 2: copy the bytecode to the end of the executable and add a marker.
const exe = std.loadFile(targetExe ?? globalThis.argv0, { binary: true }); const exeFileName = targetExe ?? globalThis.argv0;
const exe = std.loadFile(exeFileName, { binary: true });
if (!exe) {
throw new Error(`failed to open executable: ${exeFileName}`);
}
const exeSize = exe.length; const exeSize = exe.length;
const newBuffer = exe.buffer.transfer(exeSize + bytecode.length + Trailer.Size); const newBuffer = exe.buffer.transfer(exeSize + bytecode.length + Trailer.Size);
const newExe = new Uint8Array(newBuffer); const newExe = new Uint8Array(newBuffer);