Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Emscripten target (Passing header from fetch response. Using Config.path for inMemory Realm) #6716

Merged
merged 3 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/realm/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,11 +1489,12 @@ void DB::set_logger(const std::shared_ptr<util::Logger>& logger) noexcept
m_logger = std::make_shared<DBLogger>(logger, m_path_hash);
}

void DB::open(Replication& repl, const DBOptions options)
void DB::open(Replication& repl, const DBOptions options, const std::string& in_memory_path)
{
REALM_ASSERT(!is_attached());
repl.initialize(*this); // Throws
set_replication(&repl);
m_db_path = in_memory_path;

m_alloc.init_in_memory_buffer();

Expand Down Expand Up @@ -2767,12 +2768,12 @@ DBRef DB::create(std::unique_ptr<Replication> repl, const std::string& file,
return retval;
}

DBRef DB::create(std::unique_ptr<Replication> repl, const DBOptions& options) NO_THREAD_SAFETY_ANALYSIS
DBRef DB::create(std::unique_ptr<Replication> repl, const DBOptions& options, const std::string& in_memory_path) NO_THREAD_SAFETY_ANALYSIS
{
REALM_ASSERT(repl);
DBRef retval = std::make_shared<DBInit>(options);
retval->m_history = std::move(repl);
retval->open(*retval->m_history, options);
retval->open(*retval->m_history, options, in_memory_path);
return retval;
}

Expand Down
6 changes: 4 additions & 2 deletions src/realm/db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class DB : public std::enable_shared_from_this<DB> {
static DBRef create(std::unique_ptr<Replication> repl, const std::string& file,
const DBOptions& options = DBOptions());
static DBRef create(BinaryData, bool take_ownership = true);
static DBRef create(std::unique_ptr<Replication> repl, const DBOptions& options = DBOptions());
static DBRef create(std::unique_ptr<Replication> repl, const DBOptions& options = DBOptions(), const std::string& in_memory_path = "");

~DB() noexcept;

Expand Down Expand Up @@ -540,7 +540,9 @@ class DB : public std::enable_shared_from_this<DB> {
REQUIRES(!m_mutex);
void open(BinaryData, bool take_ownership = true) REQUIRES(!m_mutex);
void open(Replication&, const std::string& file, const DBOptions& options = DBOptions()) REQUIRES(!m_mutex);
void open(Replication& repl, const DBOptions options = DBOptions()) REQUIRES(!m_mutex);
// in_memory_path is used to set the `db_path` used to register and associate a users's SyncSession with the Realm path (see SyncUser::register_session)
// SyncSession::path() relies on the registered `m_db->get_path`
void open(Replication& repl, const DBOptions options = DBOptions(), const std::string& in_memory_path = "") REQUIRES(!m_mutex);

void do_open(const std::string& file, bool no_create, const DBOptions& options);

Expand Down
2 changes: 1 addition & 1 deletion src/realm/object-store/impl/realm_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void RealmCoordinator::open_db()
// Force the DB to be created in memory-only mode, ignoring the filesystem path supplied in the config.
// This is so we can run an SDK on top without having to solve the browser persistence problem yet,
// or teach RealmConfig and SDKs about pure in-memory realms.
m_db = DB::create(std::move(history), options);
m_db = DB::create(std::move(history), options, m_config.path);
#else
if (m_config.path.size()) {
m_db = DB::create(std::move(history), m_config.path, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ static void error(emscripten_fetch_t* fetch)
auto guard = util::make_scope_exit([&]() noexcept {
emscripten_fetch_close(fetch);
});
std::string packed_headers;
packed_headers.resize(emscripten_fetch_get_response_headers_length(fetch));
emscripten_fetch_get_response_headers(fetch, packed_headers.data(), packed_headers.size());

std::unique_ptr<FetchState> state(reinterpret_cast<FetchState*>(fetch->userData));
state->completion_block({fetch->status, 0, {}, std::string(fetch->data, size_t(fetch->numBytes)), ErrorCodes::HTTPError});
state->completion_block({fetch->status, 0, parse_headers(packed_headers), std::string(fetch->data, size_t(fetch->numBytes)), ErrorCodes::HTTPError});
}

void EmscriptenNetworkTransport::send_request_to_server(
Expand Down