Replace MethodCallResult with folly::Optional

Reviewed By: AaaChiuuu

Differential Revision: D4481987

fbshipit-source-id: 945dd671eb2482f3c6b626192aa2181c5bfd906f
This commit is contained in:
Pieter De Baets 2017-02-02 05:07:28 -08:00 committed by Facebook Github Bot
parent 7812b82b18
commit 4d2512aef9
5 changed files with 11 additions and 14 deletions

View File

@ -119,7 +119,7 @@ void RCTNativeModule::invoke(ExecutorToken token, unsigned int methodId, folly::
MethodCallResult RCTNativeModule::callSerializableNativeHook(
ExecutorToken token, unsigned int reactMethodId, folly::dynamic &&params) {
RCTFatal(RCTErrorWithMessage(@"callSerializableNativeHook is not yet supported on iOS"));
return {nullptr, true};
return folly::none;
}

View File

@ -192,7 +192,7 @@ MethodCallResult MethodInvoker::invoke(std::weak_ptr<Instance>& 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>& instance, jni::a
auto jobject = env->CallObjectMethodA(module.get(), method_, args); \
jni::throwPendingJniExceptionAsCppException(); \
auto result = adopt_local(static_cast<JNI_CLASS::javaobject>(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>& 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>& instance, jni::a
default:
LOG(FATAL) << "Unknown return type: " << returnType;
return MethodCallResult {nullptr, true};
return folly::none;
}
}

View File

@ -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));
}
}

View File

@ -6,11 +6,11 @@
#include <functional>
#include <memory>
#include <string>
#include <sys/mman.h>
#include <vector>
#include <sys/mman.h>
#include <folly/Exception.h>
#include <folly/Optional.h>
#include <folly/dynamic.h>
#include "JSModulesUnbundle.h"
@ -34,10 +34,7 @@ class JSModulesUnbundle;
class MessageQueueThread;
class ModuleRegistry;
struct MethodCallResult {
folly::dynamic result;
bool isUndefined;
};
using MethodCallResult = folly::Optional<folly::dynamic>;
// This interface describes the delegate interface required by
// Executor implementations to call from JS into native code.

View File

@ -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());
}
} }