From 4d2512aef9e214dc3a66239dafb0c22624741dc9 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 2 Feb 2017 05:07:28 -0800 Subject: [PATCH] Replace MethodCallResult with folly::Optional Reviewed By: AaaChiuuu Differential Revision: D4481987 fbshipit-source-id: 945dd671eb2482f3c6b626192aa2181c5bfd906f --- React/CxxBridge/RCTNativeModule.mm | 2 +- ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp | 8 ++++---- ReactCommon/cxxreact/CxxNativeModule.cpp | 2 +- ReactCommon/cxxreact/Executor.h | 9 +++------ ReactCommon/cxxreact/JSCExecutor.cpp | 4 ++-- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/React/CxxBridge/RCTNativeModule.mm b/React/CxxBridge/RCTNativeModule.mm index cd67d6b37..475fde4b8 100644 --- a/React/CxxBridge/RCTNativeModule.mm +++ b/React/CxxBridge/RCTNativeModule.mm @@ -119,7 +119,7 @@ void RCTNativeModule::invoke(ExecutorToken token, unsigned int methodId, folly:: MethodCallResult RCTNativeModule::callSerializableNativeHook( ExecutorToken token, unsigned int reactMethodId, folly::dynamic &¶ms) { RCTFatal(RCTErrorWithMessage(@"callSerializableNativeHook is not yet supported on iOS")); - return {nullptr, true}; + return folly::none; } diff --git a/ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp b/ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp index 4a087337a..e93567899 100644 --- a/ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp +++ b/ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp @@ -192,7 +192,7 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, jni::a case KEY: { \ auto result = env->Call ## METHOD ## MethodA(module.get(), method_, args); \ jni::throwPendingJniExceptionAsCppException(); \ - return MethodCallResult {result, false}; \ + return folly::dynamic(result); \ } #define CASE_OBJECT(KEY, JNI_CLASS, ACTIONS) \ @@ -200,7 +200,7 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, jni::a auto jobject = env->CallObjectMethodA(module.get(), method_, args); \ jni::throwPendingJniExceptionAsCppException(); \ auto result = adopt_local(static_cast(jobject)); \ - return MethodCallResult {result->ACTIONS, false}; \ + return folly::dynamic(result->ACTIONS); \ } char returnType = signature_.at(0); @@ -208,7 +208,7 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, jni::a case 'v': env->CallVoidMethodA(module.get(), method_, args); jni::throwPendingJniExceptionAsCppException(); - return MethodCallResult {nullptr, true}; + return folly::none; CASE_PRIMITIVE('z', jboolean, Boolean) CASE_OBJECT('Z', JBoolean, value()) @@ -225,7 +225,7 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr& instance, jni::a default: LOG(FATAL) << "Unknown return type: " << returnType; - return MethodCallResult {nullptr, true}; + return folly::none; } } diff --git a/ReactCommon/cxxreact/CxxNativeModule.cpp b/ReactCommon/cxxreact/CxxNativeModule.cpp index cb711c6f5..b8a2b7719 100644 --- a/ReactCommon/cxxreact/CxxNativeModule.cpp +++ b/ReactCommon/cxxreact/CxxNativeModule.cpp @@ -163,7 +163,7 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook( " is asynchronous but invoked synchronously")); } - return { method.syncFunc(std::move(args)), false }; + return method.syncFunc(std::move(args)); } } diff --git a/ReactCommon/cxxreact/Executor.h b/ReactCommon/cxxreact/Executor.h index 3db53ffe6..c7b60a9d3 100644 --- a/ReactCommon/cxxreact/Executor.h +++ b/ReactCommon/cxxreact/Executor.h @@ -6,11 +6,11 @@ #include #include #include +#include #include -#include - #include +#include #include #include "JSModulesUnbundle.h" @@ -34,10 +34,7 @@ class JSModulesUnbundle; class MessageQueueThread; class ModuleRegistry; -struct MethodCallResult { - folly::dynamic result; - bool isUndefined; -}; +using MethodCallResult = folly::Optional; // This interface describes the delegate interface required by // Executor implementations to call from JS into native code. diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index 3658a24c2..61f2d83f6 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -877,10 +877,10 @@ JSValueRef JSCExecutor::nativeCallSyncHook( moduleId, methodId, std::move(args)); - if (result.isUndefined) { + if (!result.hasValue()) { return Value::makeUndefined(m_context); } - return Value::fromDynamic(m_context, result.result); + return Value::fromDynamic(m_context, result.value()); } } }