Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// #include "hermes/VM/RuntimeModule.h"
#include "js_native_api.h"

NAPI_EXTERN napi_status NAPI_CDECL napi_run_bytecode(napi_env env, void* data, size_t size, const char* source_url, napi_value *result);

namespace hermes::node_api {

class NodeApiEnvironment;
Expand Down
9 changes: 8 additions & 1 deletion test-app/runtime/src/main/cpp/napi/hermes/jsr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "jsr.h"
#include "js_runtime.h"
#include "File.h"

using namespace facebook::jsi;
std::unordered_map<napi_env, JSR *> JSR::env_to_jsr_cache;
Expand Down Expand Up @@ -131,7 +132,13 @@ napi_status js_cache_script(napi_env env, const char *source, const char *file)

napi_status js_run_cached_script(napi_env env, const char *file, napi_value script, void *cache,
napi_value *result) {
return napi_ok;
int length = 0;
auto data = tns::File::ReadBinary(file, length);
if (!data) {
return napi_cannot_run_js;
}

return napi_run_bytecode(env, data, length, file, result);
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leak: The data allocated by tns::File::ReadBinary is not freed after calling napi_run_bytecode. According to the File::ReadBinary implementation, it allocates memory with new uint8_t[length] which needs to be deleted by the caller. Either delete the data after the bytecode execution, or ensure napi_run_bytecode takes ownership of the buffer.

Suggested change
return napi_run_bytecode(env, data, length, file, result);
napi_status status = napi_run_bytecode(env, data, length, file, result);
delete[] data;
return status;

Copilot uses AI. Check for mistakes.
}

napi_status js_get_runtime_version(napi_env env, napi_value *version) {
Expand Down
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/arm64-v8a/libhermesvm.so
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/arm64-v8a/libjsi.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/armeabi-v7a/libjsi.so
Binary file not shown.
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/x86/libhermesvm.so
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/x86/libjsi.so
Binary file not shown.
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/x86_64/libhermesvm.so
Binary file not shown.
Binary file modified test-app/runtime/src/main/libs/shermes/x86_64/libjsi.so
Binary file not shown.