Skip to content

Commit

Permalink
Replace MethodCallResult with folly::Optional
Browse files Browse the repository at this point in the history
Reviewed By: AaaChiuuu

Differential Revision: D4481987

fbshipit-source-id: 945dd671eb2482f3c6b626192aa2181c5bfd906f
  • Loading branch information
javache authored and facebook-github-bot committed Feb 2, 2017
1 parent 7812b82 commit 4d2512a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion React/CxxBridge/RCTNativeModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
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;
}


Expand Down
8 changes: 4 additions & 4 deletions ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,23 @@ 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) \
case KEY: { \
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);
switch (returnType) {
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())
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/cxxreact/CxxNativeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
Expand Down
9 changes: 3 additions & 6 deletions ReactCommon/cxxreact/Executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <sys/mman.h>
#include <vector>

#include <folly/Exception.h>
#include <folly/Optional.h>
#include <folly/dynamic.h>

#include "JSModulesUnbundle.h"
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions ReactCommon/cxxreact/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

} }

0 comments on commit 4d2512a

Please sign in to comment.