Skip to content
Open
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
9 changes: 6 additions & 3 deletions barretenberg/cpp/src/barretenberg/bbapi/c_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ BBApiRequest global_request;
/**
* @brief Main API function that processes commands and returns responses
*
* In native builds, exceptions are caught and converted to ErrorResponse.
* In WASM builds (BB_NO_EXCEPTIONS), throw_or_abort_impl is provided by JS
* and throws a catchable JS Error, so no C++ recovery boundary is needed.
*
* @param command The command to execute
* @return CommandResponse The response from executing the command
*/
CommandResponse bbapi(Command&& command)
{
#ifndef BB_NO_EXCEPTIONS
try {
#endif
// Execute the command using the global request and return the response
return execute(global_request, std::move(command));
#ifndef BB_NO_EXCEPTIONS
} catch (const std::exception& e) {
return ErrorResponse{ .message = e.what() };
}
#else
return execute(global_request, std::move(command));
#endif
}

Expand Down
9 changes: 9 additions & 0 deletions barretenberg/cpp/src/barretenberg/env/throw_or_abort_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// In WASM builds, throw_or_abort_impl is provided by the JavaScript environment
// (declared as WASM_IMPORT in throw_or_abort_impl.hpp). The JS implementation throws
// a catchable JS Error, giving the caller a clean exception instead of aborting.
// We must not define a competing C++ implementation here for WASM, otherwise the
// linker uses the local definition (which calls std::abort) instead of the JS import.
#ifndef __wasm__

#include "barretenberg/common/log.hpp"
#include "barretenberg/common/wasm_export.hpp"
#include <stdexcept>
Expand Down Expand Up @@ -27,3 +34,5 @@ WASM_EXPORT void throw_or_abort_impl [[noreturn]] (const char* err)
abort_with_message(err);
#endif
}

#endif // !__wasm__
Loading