From f1cbb11620c1609189daf5370f0dba86ceb7d275 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 10 Jul 2017 05:21:03 -0700 Subject: [PATCH] Replace -[RCTConvert folly_dynamic:] with direct calls to convertIdToFollyDynamic Reviewed By: kathryngray Differential Revision: D5355734 fbshipit-source-id: 4ba1533b75c8e271a86a2d5cc3a3354e52f83db2 --- React/CxxBridge/RCTCxxBridge.mm | 5 +++-- React/CxxBridge/RCTObjcExecutor.mm | 2 +- React/CxxModule/RCTCxxMethod.mm | 2 +- React/CxxModule/RCTCxxUtils.h | 15 ++++----------- React/CxxModule/RCTCxxUtils.mm | 29 ++++++----------------------- React/CxxModule/RCTNativeModule.mm | 3 ++- 6 files changed, 17 insertions(+), 39 deletions(-) diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 9bc259d5c..7ff36e89c 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -29,6 +29,7 @@ #import #import #import +#import #import #import #import @@ -1005,7 +1006,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR if (self->_reactInstance) { self->_reactInstance->callJSFunction([module UTF8String], [method UTF8String], - [RCTConvert folly_dynamic:args ?: @[]]); + convertIdToFollyDynamic(args ?: @[])); // ensureOnJavaScriptThread may execute immediately, so use jsMessageThread, to make sure // the block is invoked after callJSFunction @@ -1041,7 +1042,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR RCTProfileEndFlowEvent(); if (self->_reactInstance) { - self->_reactInstance->callJSCallback([cbID unsignedLongLongValue], [RCTConvert folly_dynamic:args ?: @[]]); + self->_reactInstance->callJSCallback([cbID unsignedLongLongValue], convertIdToFollyDynamic(args ?: @[])); } }]; } diff --git a/React/CxxBridge/RCTObjcExecutor.mm b/React/CxxBridge/RCTObjcExecutor.mm index 0bf158751..ec474292b 100644 --- a/React/CxxBridge/RCTObjcExecutor.mm +++ b/React/CxxBridge/RCTObjcExecutor.mm @@ -50,7 +50,7 @@ public: } m_jsThread->runOnQueue([this, json]{ - m_delegate->callNativeModules(*this, [RCTConvert folly_dynamic:json], true); + m_delegate->callNativeModules(*this, convertIdToFollyDynamic(json), true); }); }; diff --git a/React/CxxModule/RCTCxxMethod.mm b/React/CxxModule/RCTCxxMethod.mm index de8375e6e..65a5433a4 100644 --- a/React/CxxModule/RCTCxxMethod.mm +++ b/React/CxxModule/RCTCxxMethod.mm @@ -90,7 +90,7 @@ using namespace facebook::react; }; } - folly::dynamic args = [RCTConvert folly_dynamic:arguments]; + folly::dynamic args = convertIdToFollyDynamic(arguments); args.resize(args.size() - _method->callbacks); try { diff --git a/React/CxxModule/RCTCxxUtils.h b/React/CxxModule/RCTCxxUtils.h index c07b6ff8a..0aac6ccbd 100644 --- a/React/CxxModule/RCTCxxUtils.h +++ b/React/CxxModule/RCTCxxUtils.h @@ -9,21 +9,14 @@ #include -#import -#include -#include -#include -#include +#import + +#import +#import @class RCTBridge; @class RCTModuleData; -@interface RCTConvert (folly) - -+ (folly::dynamic)folly_dynamic:(id)json; - -@end - namespace facebook { namespace react { diff --git a/React/CxxModule/RCTCxxUtils.mm b/React/CxxModule/RCTCxxUtils.mm index ec9f88afc..053f45c0d 100644 --- a/React/CxxModule/RCTCxxUtils.mm +++ b/React/CxxModule/RCTCxxUtils.mm @@ -12,32 +12,13 @@ #import #import #import -#include -#include +#import +#import #import "DispatchMessageQueueThread.h" #import "RCTCxxModule.h" #import "RCTNativeModule.h" -using namespace facebook::react; - -@implementation RCTConvert (folly) - -+ (folly::dynamic)folly_dynamic:(id)json; -{ - if (json == nil || json == (id)kCFNull) { - return nullptr; - } else { - folly::dynamic dyn = convertIdToFollyDynamic(json); - if (dyn == nil) { - RCTAssert(false, @"RCTConvert input json is of an impossible type"); - } - return dyn; - } -} - -@end - namespace facebook { namespace react { @@ -109,7 +90,8 @@ static NSError *errorWithException(const std::exception &e) return [NSError errorWithDomain:RCTErrorDomain code:1 userInfo:errorInfo]; } -NSError *tryAndReturnError(const std::function& func) { +NSError *tryAndReturnError(const std::function& func) +{ try { @try { func(); @@ -133,7 +115,8 @@ NSError *tryAndReturnError(const std::function& func) { } } -NSString *deriveSourceURL(NSURL *url) { +NSString *deriveSourceURL(NSURL *url) +{ NSString *sourceUrl; if (url.isFileURL) { // Url will contain only path to resource (i.g. file:// will be removed) diff --git a/React/CxxModule/RCTNativeModule.mm b/React/CxxModule/RCTNativeModule.mm index 7e51af062..6d47b1ea6 100644 --- a/React/CxxModule/RCTNativeModule.mm +++ b/React/CxxModule/RCTNativeModule.mm @@ -14,6 +14,7 @@ #import #import #import +#import #import #import @@ -49,7 +50,7 @@ folly::dynamic RCTNativeModule::getConstants() { RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"[RCTNativeModule getConstants] moduleData.exportedConstants", nil); NSDictionary *constants = m_moduleData.exportedConstants; - folly::dynamic ret = [RCTConvert folly_dynamic:constants]; + folly::dynamic ret = convertIdToFollyDynamic(constants); RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @""); return ret; }