diff --git a/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm b/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm index 402e4d776c2..0372d419016 100644 --- a/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm +++ b/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm @@ -20,16 +20,7 @@ JSIExecutor::RuntimeInstaller RCTJSIExecutorRuntimeInstaller(JSIExecutor::Runtim _RCTLogJavaScriptInternal(static_cast(logLevel), [NSString stringWithUTF8String:message.c_str()]); }; bindNativeLogger(runtime, iosLoggingBinder); - - PerformanceNow iosPerformanceNowBinder = []() { - auto time = std::chrono::steady_clock::now(); - auto duration = std::chrono::duration_cast(time.time_since_epoch()).count(); - - constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0; - - return duration / NANOSECONDS_IN_MILLISECOND; - }; - bindNativePerformanceNow(runtime, iosPerformanceNowBinder); + bindNativePerformanceNow(runtime); // Wrap over the original runtimeInstaller if (runtimeInstaller) { diff --git a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp index 2a102d5d265..6326364220b 100644 --- a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include @@ -56,10 +55,7 @@ static void installBindings(jsi::Runtime &runtime) { static_cast( &reactAndroidLoggingHook); react::bindNativeLogger(runtime, androidLogger); - - react::PerformanceNow androidNativePerformanceNow = - static_cast(&reactAndroidNativePerformanceNowHook); - react::bindNativePerformanceNow(runtime, androidNativePerformanceNow); + react::bindNativePerformanceNow(runtime); } class HermesExecutorHolder diff --git a/ReactAndroid/src/main/jni/react/jni/NativeTime.cpp b/ReactAndroid/src/main/jni/react/jni/NativeTime.cpp deleted file mode 100644 index 042805ff66d..00000000000 --- a/ReactAndroid/src/main/jni/react/jni/NativeTime.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#include "NativeTime.h" -#include - -namespace facebook { -namespace react { - -double reactAndroidNativePerformanceNowHook() { - auto time = std::chrono::steady_clock::now(); - auto duration = std::chrono::duration_cast( - time.time_since_epoch()) - .count(); - - constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0; - - return duration / NANOSECONDS_IN_MILLISECOND; -} - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/jni/NativeTime.h b/ReactAndroid/src/main/jni/react/jni/NativeTime.h deleted file mode 100644 index bc943de23f7..00000000000 --- a/ReactAndroid/src/main/jni/react/jni/NativeTime.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#pragma once - -namespace facebook { -namespace react { - -double reactAndroidNativePerformanceNowHook(); - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp index 9d38412d1cb..d61e0706d7b 100644 --- a/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -31,10 +30,7 @@ class JSCExecutorFactory : public JSExecutorFactory { static_cast( &reactAndroidLoggingHook); react::bindNativeLogger(runtime, androidLogger); - - react::PerformanceNow androidNativePerformanceNow = - static_cast(&reactAndroidNativePerformanceNowHook); - react::bindNativePerformanceNow(runtime, androidNativePerformanceNow); + react::bindNativePerformanceNow(runtime); }; return std::make_unique( jsc::makeJSCRuntime(), diff --git a/ReactCommon/cxxreact/JSExecutor.cpp b/ReactCommon/cxxreact/JSExecutor.cpp index 471d54ca5ec..7f7bfd32e99 100644 --- a/ReactCommon/cxxreact/JSExecutor.cpp +++ b/ReactCommon/cxxreact/JSExecutor.cpp @@ -11,6 +11,8 @@ #include +#include + namespace facebook { namespace react { @@ -23,5 +25,15 @@ std::string JSExecutor::getSyntheticBundlePath( return folly::to("seg-", bundleId, ".js"); } +double JSExecutor::performanceNow() { + auto time = std::chrono::steady_clock::now(); + auto duration = std::chrono::duration_cast( + time.time_since_epoch()) + .count(); + + constexpr double NANOSECONDS_IN_MILLISECOND = 1000000.0; + return duration / NANOSECONDS_IN_MILLISECOND; +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/cxxreact/JSExecutor.h b/ReactCommon/cxxreact/JSExecutor.h index 4d6e45f9c37..112426a1da4 100644 --- a/ReactCommon/cxxreact/JSExecutor.h +++ b/ReactCommon/cxxreact/JSExecutor.h @@ -138,6 +138,8 @@ class RN_EXPORT JSExecutor { static std::string getSyntheticBundlePath( uint32_t bundleId, const std::string &bundlePath); + + static double performanceNow(); }; } // namespace react diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index c4a804d95b2..8e080802308 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -565,7 +565,7 @@ void bindNativeLogger(Runtime &runtime, Logger logger) { })); } -void bindNativePerformanceNow(Runtime &runtime, PerformanceNow performanceNow) { +void bindNativePerformanceNow(Runtime &runtime) { runtime.global().setProperty( runtime, "nativePerformanceNow", @@ -573,11 +573,10 @@ void bindNativePerformanceNow(Runtime &runtime, PerformanceNow performanceNow) { runtime, PropNameID::forAscii(runtime, "nativePerformanceNow"), 0, - [performanceNow = std::move(performanceNow)]( - jsi::Runtime &runtime, - const jsi::Value &, - const jsi::Value *args, - size_t count) { return Value(performanceNow()); })); + [](jsi::Runtime &runtime, + const jsi::Value &, + const jsi::Value *args, + size_t count) { return Value(JSExecutor::performanceNow()); })); } } // namespace react diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h index 90119ec4093..c17a052e866 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h @@ -137,9 +137,8 @@ using Logger = std::function; void bindNativeLogger(jsi::Runtime &runtime, Logger logger); -using PerformanceNow = std::function; -void bindNativePerformanceNow( - jsi::Runtime &runtime, - PerformanceNow performanceNow); +void bindNativePerformanceNow(jsi::Runtime &runtime); + +double performanceNow(); } // namespace react } // namespace facebook