diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 19da6a51d..1729c603b 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1164,8 +1164,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR RCT_PROFILE_BEGIN_EVENT(0, @"callFunctionOnModule", (@{ @"module": module, @"method": method })); __block JSValue *ret = nil; NSError *errorObj = tryAndReturnError(^{ - Value result = self->_reactInstance->callFunctionSync( - [module UTF8String], [method UTF8String], arguments); + Value result = self->_reactInstance->callFunctionSync([module UTF8String], [method UTF8String], (id)arguments); JSContext *context = contextForGlobalContextRef(JSC_JSContextGetGlobalContext(result.context())); ret = [JSC_JSValue(result.context()) valueWithJSValueRef:result inContext:context]; }); diff --git a/React/CxxModule/RCTCxxUtils.h b/React/CxxModule/RCTCxxUtils.h index 0aac6ccbd..7c1a6b212 100644 --- a/React/CxxModule/RCTCxxUtils.h +++ b/React/CxxModule/RCTCxxUtils.h @@ -26,16 +26,10 @@ std::vector> createNativeModules(NSArray::toValue is used by JSCExecutor callFunctionSync. - * Note: Because the NSArray * is really a NSArray * __strong the toValue is - * accepting NSArray *const __strong instead of NSArray *&&. - */ -template <> -struct ValueEncoder { - static Value toValue(JSGlobalContextRef ctx, NSArray *const __strong array) - { - JSValue *value = [JSC_JSValue(ctx) valueWithObject:array inContext:contextForGlobalContextRef(ctx)]; +template<> +struct JSCValueEncoder { + static Value toJSCValue(JSGlobalContextRef ctx, id obj) { + JSValue *value = [JSC_JSValue(ctx) valueWithObject:obj inContext:contextForGlobalContextRef(ctx)]; return {ctx, [value JSValueRef]}; } }; diff --git a/ReactCommon/cxxreact/JSCExecutor.h b/ReactCommon/cxxreact/JSCExecutor.h index c381d0d30..0f823c3b6 100644 --- a/ReactCommon/cxxreact/JSCExecutor.h +++ b/ReactCommon/cxxreact/JSCExecutor.h @@ -36,8 +36,19 @@ private: folly::dynamic m_jscConfig; }; -template -struct ValueEncoder; +template +struct JSCValueEncoder { + // If you get a build error here, it means the compiler can't see the template instantation of toJSCValue + // applicable to your type. + static const Value toJSCValue(JSGlobalContextRef ctx, T&& value); +}; + +template<> +struct JSCValueEncoder { + static const Value toJSCValue(JSGlobalContextRef ctx, const folly::dynamic &&value) { + return Value::fromDynamic(ctx, value); + } +}; class RN_EXPORT JSCExecutor : public JSExecutor { public: @@ -69,7 +80,7 @@ public: Value callFunctionSync( const std::string& module, const std::string& method, T&& args) { return callFunctionSyncWithValue( - module, method, ValueEncoder::type>::toValue( + module, method, JSCValueEncoder::type>::toJSCValue( m_context, std::forward(args))); }