Skip to content

Commit

Permalink
Add calls to flush_ui_queue for Hermes (#4579)
Browse files Browse the repository at this point in the history
Rearranged jsi_init

Refactored flush of UI queue for JSI
  • Loading branch information
kraenhansen committed Jun 9, 2022
1 parent ea5d5ce commit a781ddf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
17 changes: 12 additions & 5 deletions src/jsi/jsi_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,43 @@
namespace realm {
namespace js {

template <typename T>
inline T flush_and_return(T&& val)
{
flush_ui_queue();
return val;
}

template <>
inline JsiVal realmjsi::Function::call(JsiEnv env, const JsiFunc& function, size_t argc, const JsiVal arguments[])
{
return env(function->call(env, env.args(arguments, argc), argc));
return flush_and_return(env(function->call(env, env.args(arguments, argc), argc)));
}

template <>
inline JsiVal realmjsi::Function::call(JsiEnv env, const JsiFunc& function, const JsiObj& this_object, size_t argc,
const JsiVal arguments[])
{
return env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
return flush_and_return(env(function->callWithThis(env, this_object, env.args(arguments, argc), argc)));
}

template <>
inline JsiVal realmjsi::Function::callback(JsiEnv env, const JsiFunc& function, size_t argc, const JsiVal arguments[])
{
return env(function->call(env, env.args(arguments, argc), argc));
return flush_and_return(env(function->call(env, env.args(arguments, argc), argc)));
}
template <>
inline JsiVal realmjsi::Function::callback(JsiEnv env, const JsiFunc& function, const JsiObj& this_object,
size_t argc, const JsiVal arguments[])
{
return env(function->callWithThis(env, this_object, env.args(arguments, argc), argc));
return flush_and_return(env(function->callWithThis(env, this_object, env.args(arguments, argc), argc)));
}

template <>
inline JsiObj realmjsi::Function::construct(JsiEnv env, const JsiFunc& function, size_t argc,
const JsiVal arguments[])
{
return env(function->callAsConstructor(env, env.args(arguments, argc), argc).asObject(env));
return flush_and_return(env(function->callAsConstructor(env, env.args(arguments, argc), argc).asObject(env)));
}

} // namespace js
Expand Down
6 changes: 0 additions & 6 deletions src/jsi/jsi_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@

#include "jsi_init.hpp"

namespace realm {
namespace js {
std::function<void()> flush_ui_queue;
} // namespace js
} // namespace realm

#if !REALM_ENABLE_SYNC
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "crypt32")
Expand Down
8 changes: 8 additions & 0 deletions src/jsi/jsi_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

#pragma once

#include <functional>

namespace realm {
namespace js {
std::function<void()> flush_ui_queue;
} // namespace js
} // namespace realm

#include "jsi_string.hpp"
#include "jsi_protected.hpp"
#include "jsi_function.hpp"
Expand Down

0 comments on commit a781ddf

Please sign in to comment.