diff --git a/ReactAndroid/src/main/java/com/facebook/react/v8executor/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/react/v8executor/OnLoad.cpp index a431ed4415be5f..ad1467995d1ec0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/v8executor/OnLoad.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/v8executor/OnLoad.cpp @@ -12,12 +12,6 @@ #include #include -namespace facebook { -namespace v8runtime { - std::unique_ptr makeV8Runtime(); -} // namespace v8runtime -} // namespace facebook - namespace facebook { namespace react { @@ -31,13 +25,16 @@ class V8ExecutorFactory : public JSExecutorFactory { std::unique_ptr createJSExecutor( std::shared_ptr delegate, - std::shared_ptr jsQueue) override { + std::shared_ptr jsQueue) override { + + auto logger = std::make_shared([](const std::string& message, unsigned int logLevel) { + reactAndroidLoggingHook(message, logLevel); + }); + return folly::make_unique( - facebook::v8runtime::makeV8Runtime(m_v8Config), + facebook::v8runtime::makeV8Runtime(m_v8Config, logger), delegate, - [](const std::string& message, unsigned int logLevel) { - reactAndroidLoggingHook(message, logLevel); - }, + *logger, JSIExecutor::defaultTimeoutInvoker, nullptr); } diff --git a/ReactCommon/jsi/V8Runtime.h b/ReactCommon/jsi/V8Runtime.h index 6c00571bdf59c0..582595e3b08787 100644 --- a/ReactCommon/jsi/V8Runtime.h +++ b/ReactCommon/jsi/V8Runtime.h @@ -60,7 +60,7 @@ namespace v8runtime { std::unique_ptr custom_snapshot = nullptr); /*Optional*/ std::unique_ptr makeV8Runtime(); - std::unique_ptr makeV8Runtime(const folly::dynamic& v8Config); + std::unique_ptr makeV8Runtime(const folly::dynamic& v8Config, const std::shared_ptr& logger); } // namespace v8runtime } // namespace facebook diff --git a/ReactCommon/jsi/V8Runtime_droid.cpp b/ReactCommon/jsi/V8Runtime_droid.cpp index e1b799dba3816a..04ba8866c5be6f 100644 --- a/ReactCommon/jsi/V8Runtime_droid.cpp +++ b/ReactCommon/jsi/V8Runtime_droid.cpp @@ -50,7 +50,8 @@ namespace facebook { namespace v8runtime { } } - V8Runtime::V8Runtime(const folly::dynamic& v8Config) : V8Runtime() { + V8Runtime::V8Runtime(const folly::dynamic& v8Config, const std::shared_ptr& logger) : V8Runtime() { + logger_ = logger; isCacheEnabled_ = IsCacheEnabled(v8Config); shouldProduceFullCache_ = ShouldProduceFullCache(v8Config); shouldSetNoLazyFlag_ = ShouldSetNoLazyFlag(v8Config); diff --git a/ReactCommon/jsi/V8Runtime_impl.h b/ReactCommon/jsi/V8Runtime_impl.h index 56f40082b535fa..5be28e1737b571 100644 --- a/ReactCommon/jsi/V8Runtime_impl.h +++ b/ReactCommon/jsi/V8Runtime_impl.h @@ -43,7 +43,7 @@ namespace facebook { namespace v8runtime { class V8Runtime : public jsi::Runtime { public: V8Runtime(); - V8Runtime(const folly::dynamic& v8Config); + V8Runtime(const folly::dynamic& v8Config, const std::shared_ptr& logger); V8Runtime(const v8::Platform* platform, std::shared_ptr&& logger, std::shared_ptr&& jsQueue, std::shared_ptr&& cacheProvider, @@ -374,6 +374,12 @@ namespace facebook { namespace v8runtime { bool ExecuteString(v8::Local source, const jsi::Buffer* cache, v8::Local name, bool report_exceptions); bool ExecuteString(const v8::Local& source, const std::string& sourceURL); + void Log(const std::string& message, const unsigned int logLevel) { + if (logger_) { + (*logger_)("V8Runtime:: " + message, logLevel); + } + } + void ReportException(v8::TryCatch* try_catch); v8::Isolate* GetIsolate() const { return isolate_; } diff --git a/ReactCommon/jsi/V8Runtime_shared.cpp b/ReactCommon/jsi/V8Runtime_shared.cpp index 13fccbc2508333..8a53423f622fd3 100644 --- a/ReactCommon/jsi/V8Runtime_shared.cpp +++ b/ReactCommon/jsi/V8Runtime_shared.cpp @@ -247,7 +247,9 @@ namespace facebook { namespace v8runtime { if (message.IsEmpty()) { // V8 didn't provide any extra information about this error; just // throw the exception. - throw jsi::JSError(*this, ""); + std::string errorMessage{ "" }; + Log(errorMessage, 3 /*LogLevel error*/); + throw jsi::JSError(*this, errorMessage); } else { // Print (filename):(line number): (message). @@ -283,7 +285,9 @@ namespace facebook { namespace v8runtime { sstr << stack_trace_string2 << std::endl; } - throw jsi::JSError(*this, sstr.str()); + std::string errorMessage{ sstr.str() }; + Log(errorMessage, 3 /*LogLevel error*/); + throw jsi::JSError(*this, errorMessage); } } @@ -740,7 +744,7 @@ namespace facebook { namespace v8runtime { return std::make_unique(); } - std::unique_ptr makeV8Runtime(const folly::dynamic& v8Config) { - return std::make_unique(v8Config); + std::unique_ptr makeV8Runtime(const folly::dynamic& v8Config, const std::shared_ptr& logger) { + return std::make_unique(v8Config, logger); } -}} // namespace facebook::v8runtime \ No newline at end of file +}} // namespace facebook::v8runtime