From 5250743fd43079dfcef57e5a3d434d21abc25ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 17 May 2022 12:19:46 +0200 Subject: [PATCH] Add calls to flush_ui_queue for Hermes (#4579) Rearranged jsi_init Refactored flush of UI queue for JSI --- src/jsi/jsi_function.hpp | 17 ++++++++++++----- src/jsi/jsi_init.cpp | 6 ------ src/jsi/jsi_init.hpp | 8 ++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/jsi/jsi_function.hpp b/src/jsi/jsi_function.hpp index cccbc4ad55..e58f91f280 100644 --- a/src/jsi/jsi_function.hpp +++ b/src/jsi/jsi_function.hpp @@ -23,36 +23,43 @@ namespace realm { namespace js { +template +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 diff --git a/src/jsi/jsi_init.cpp b/src/jsi/jsi_init.cpp index 14fcf96dc8..b6e32b7cee 100644 --- a/src/jsi/jsi_init.cpp +++ b/src/jsi/jsi_init.cpp @@ -19,12 +19,6 @@ #include "jsi_init.hpp" -namespace realm { -namespace js { -std::function flush_ui_queue; -} // namespace js -} // namespace realm - #if !REALM_ENABLE_SYNC #pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "crypt32") diff --git a/src/jsi/jsi_init.hpp b/src/jsi/jsi_init.hpp index 28e787359d..5ef4dc7efd 100644 --- a/src/jsi/jsi_init.hpp +++ b/src/jsi/jsi_init.hpp @@ -18,6 +18,14 @@ #pragma once +#include + +namespace realm { +namespace js { +std::function flush_ui_queue; +} // namespace js +} // namespace realm + #include "jsi_string.hpp" #include "jsi_protected.hpp" #include "jsi_function.hpp"