diff --git a/src/postject.cpp b/src/postject.cpp index cf4ea4a..730058c 100644 --- a/src/postject.cpp +++ b/src/postject.cpp @@ -14,10 +14,12 @@ enum class ExecutableFormat { kELF, kMachO, kPE, kUnknown }; enum class InjectResult { kAlreadyExists, kError, kSuccess }; std::vector vec_from_val(const emscripten::val& value) { - // TODO(dsanders11) - vecFromJSArray incurs a copy, so memory usage is higher - // than it needs to be. Explore ways to access the memory - // directly and avoid the copy. - return emscripten::vecFromJSArray(value); + // We are using `convertJSArrayToNumberVector()` instead of `vecFromJSArray()` + // because it is faster. It is okay if we use it without additional type + // checking because this function is only called on Node.js Buffer instances + // which is expected to contain elements that are safe to pass to the JS + // function, `Number()`. + return emscripten::convertJSArrayToNumberVector(value); } ExecutableFormat get_executable_format(const emscripten::val& executable) { diff --git a/test/cli.mjs b/test/cli.mjs index 2b06da9..8197dfc 100644 --- a/test/cli.mjs +++ b/test/cli.mjs @@ -115,7 +115,7 @@ describe("postject CLI", () => { expect(status).to.equal(0); expect(stdout).to.have.string(resourceContents); } - }).timeout(3_00_000); + }).timeout(15_000); it("should display an error message when filename doesn't exist", async () => { { @@ -137,7 +137,7 @@ describe("postject CLI", () => { expect(stdout).to.not.have.string("Injection done!"); expect(status).to.equal(1); } - }).timeout(3_00_000); + }).timeout(15_000); it("should display an error message when the file is not a supported executable type", async () => { const bogusFile = path.join(tempDir, "bogus.exe"); @@ -160,7 +160,7 @@ describe("postject CLI", () => { ); expect(stdout).to.not.have.string("Injection done!"); expect(status).to.equal(1); - }).timeout(3_00_000); + }).timeout(15_000); }); describe("postject API", () => { @@ -234,7 +234,7 @@ describe("postject API", () => { expect(status).to.equal(0); expect(stdout).to.have.string(resourceContents); } - }).timeout(3_00_000); + }).timeout(15_000); }); describe("api.js should not contain __filename and __dirname", () => {