Skip to content

Commit 8e15a0d

Browse files
committed
Added RCT_DEBUG
1 parent b0348ed commit 8e15a0d

File tree

14 files changed

+185
-190
lines changed

14 files changed

+185
-190
lines changed

React/Base/RCTAssert.h

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,7 @@
99

1010
#import <Foundation/Foundation.h>
1111

12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif
15-
16-
/**
17-
* By default, only raise an NSAssertion in debug mode
18-
* (custom assert functions will still be called).
19-
*/
20-
#ifndef RCT_ASSERT
21-
#if DEBUG
22-
#define RCT_ASSERT 1
23-
#else
24-
#define RCT_ASSERT 0
25-
#endif
26-
#endif
12+
#import "RCTDefines.h"
2713

2814
/**
2915
* The default error domain to be used for React errors.
@@ -44,13 +30,14 @@ typedef void (^RCTAssertFunction)(
4430
/**
4531
* Private logging function - ignore this.
4632
*/
47-
void _RCTAssertFormat(BOOL, const char *, int, const char *, NSString *, ...) NS_FORMAT_FUNCTION(5,6);
33+
RCT_EXTERN void _RCTAssertFormat(
34+
BOOL, const char *, int, const char *, NSString *, ...) NS_FORMAT_FUNCTION(5,6);
4835

4936
/**
5037
* This is the main assert macro that you should use.
5138
*/
5239
#define RCTAssert(condition, ...) do { BOOL pass = ((condition) != 0); \
53-
if (RCT_ASSERT && !pass) { [[NSAssertionHandler currentHandler] handleFailureInFunction:@(__func__) \
40+
if (RCT_NSASSERT && !pass) { [[NSAssertionHandler currentHandler] handleFailureInFunction:@(__func__) \
5441
file:@(__FILE__) lineNumber:__LINE__ description:__VA_ARGS__]; } \
5542
_RCTAssertFormat(pass, __FILE__, __LINE__, __func__, __VA_ARGS__); \
5643
} while (false)
@@ -66,16 +53,12 @@ _RCTAssertFormat(pass, __FILE__, __LINE__, __func__, __VA_ARGS__); \
6653
* macros. You can use these to replace the standard behavior with custom log
6754
* functionality.
6855
*/
69-
void RCTSetAssertFunction(RCTAssertFunction assertFunction);
70-
RCTAssertFunction RCTGetAssertFunction(void);
56+
RCT_EXTERN void RCTSetAssertFunction(RCTAssertFunction assertFunction);
57+
RCT_EXTERN RCTAssertFunction RCTGetAssertFunction(void);
7158

7259
/**
7360
* This appends additional code to the existing assert function, without
7461
* replacing the existing functionality. Useful if you just want to forward
7562
* assert info to an extra service without changing the default behavior.
7663
*/
77-
void RCTAddAssertFunction(RCTAssertFunction assertFunction);
78-
79-
#ifdef __cplusplus
80-
}
81-
#endif
64+
RCT_EXTERN void RCTAddAssertFunction(RCTAssertFunction assertFunction);

React/Base/RCTBridge.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <UIKit/UIKit.h>
1111

1212
#import "RCTBridgeModule.h"
13+
#import "RCTDefines.h"
1314
#import "RCTFrameUpdate.h"
1415
#import "RCTInvalidating.h"
1516
#import "RCTJavaScriptExecutor.h"
@@ -40,7 +41,7 @@ typedef NSArray *(^RCTBridgeModuleProviderBlock)(void);
4041
/**
4142
* This function returns the module name for a given class.
4243
*/
43-
extern NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
44+
RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
4445

4546
/**
4647
* Async batched bridge used to communicate with the JavaScript application.

React/Base/RCTBridge.m

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
143143

144144
// Get data entry
145145
NSString *entry = @(*(const char **)(mach_header + addr));
146-
NSArray *parts = [[entry substringWithRange:(NSRange){2, entry.length - 3}] componentsSeparatedByString:@" "];
146+
NSArray *parts = [[entry substringWithRange:(NSRange){2, entry.length - 3}]
147+
componentsSeparatedByString:@" "];
147148

148149
// Parse class name
149150
NSString *moduleClassName = parts[0];
@@ -164,33 +165,32 @@ typedef NS_ENUM(NSUInteger, RCTBridgeFields) {
164165
}
165166
}
166167

167-
#if DEBUG
168+
if (RCT_DEBUG) {
168169

169-
// We may be able to get rid of this check in future, once people
170-
// get used to the new registration system. That would potentially
171-
// allow you to create modules that are not automatically registered
170+
// We may be able to get rid of this check in future, once people
171+
// get used to the new registration system. That would potentially
172+
// allow you to create modules that are not automatically registered
172173

173-
static unsigned int classCount;
174-
Class *classes = objc_copyClassList(&classCount);
175-
for (unsigned int i = 0; i < classCount; i++)
176-
{
177-
Class cls = classes[i];
178-
Class superclass = cls;
179-
while (superclass)
174+
static unsigned int classCount;
175+
Class *classes = objc_copyClassList(&classCount);
176+
for (unsigned int i = 0; i < classCount; i++)
180177
{
181-
if (class_conformsToProtocol(superclass, @protocol(RCTBridgeModule)))
178+
Class cls = classes[i];
179+
Class superclass = cls;
180+
while (superclass)
182181
{
183-
if (![RCTModuleClassesByID containsObject:cls]) {
184-
RCTLogError(@"Class %@ was not exported. Did you forget to use RCT_EXPORT_MODULE()?", NSStringFromClass(cls));
182+
if (class_conformsToProtocol(superclass, @protocol(RCTBridgeModule)))
183+
{
184+
if (![RCTModuleClassesByID containsObject:cls]) {
185+
RCTLogError(@"Class %@ was not exported. Did you forget to use RCT_EXPORT_MODULE()?", NSStringFromClass(cls));
186+
}
187+
break;
185188
}
186-
break;
189+
superclass = class_getSuperclass(superclass);
187190
}
188-
superclass = class_getSuperclass(superclass);
189191
}
190192
}
191193

192-
#endif
193-
194194
});
195195

196196
return RCTModuleClassesByID;
@@ -289,13 +289,13 @@ - (instancetype)initWithReactMethodName:(NSString *)reactMethodName
289289
_isClassMethod = [reactMethodName characterAtIndex:0] == '+';
290290
_moduleClass = NSClassFromString(_moduleClassName);
291291

292-
#if DEBUG
292+
if (RCT_DEBUG) {
293293

294-
// Sanity check
295-
RCTAssert([_moduleClass conformsToProtocol:@protocol(RCTBridgeModule)],
296-
@"You are attempting to export the method %@, but %@ does not \
297-
conform to the RCTBridgeModule Protocol", objCMethodName, _moduleClassName);
298-
#endif
294+
// Sanity check
295+
RCTAssert([_moduleClass conformsToProtocol:@protocol(RCTBridgeModule)],
296+
@"You are attempting to export the method %@, but %@ does not \
297+
conform to the RCTBridgeModule Protocol", objCMethodName, _moduleClassName);
298+
}
299299

300300
// Get method signature
301301
_methodSignature = _isClassMethod ?
@@ -449,20 +449,19 @@ - (void)invokeWithBridge:(RCTBridge *)bridge
449449
arguments:(NSArray *)arguments
450450
context:(NSNumber *)context
451451
{
452+
if (RCT_DEBUG) {
452453

453-
#if DEBUG
454-
455-
// Sanity check
456-
RCTAssert([module class] == _moduleClass, @"Attempted to invoke method \
457-
%@ on a module of class %@", _methodName, [module class]);
458-
#endif
459-
460-
// Safety check
461-
if (arguments.count != _argumentBlocks.count) {
462-
RCTLogError(@"%@.%@ was called with %zd arguments, but expects %zd",
463-
RCTBridgeModuleNameForClass(_moduleClass), _JSMethodName,
464-
arguments.count, _argumentBlocks.count);
465-
return;
454+
// Sanity check
455+
RCTAssert([module class] == _moduleClass, @"Attempted to invoke method \
456+
%@ on a module of class %@", _methodName, [module class]);
457+
458+
// Safety check
459+
if (arguments.count != _argumentBlocks.count) {
460+
RCTLogError(@"%@.%@ was called with %zd arguments, but expects %zd",
461+
RCTBridgeModuleNameForClass(_moduleClass), _JSMethodName,
462+
arguments.count, _argumentBlocks.count);
463+
return;
464+
}
466465
}
467466

468467
// Create invocation (we can't re-use this as it wouldn't be thread-safe)

React/Base/RCTConvert.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#import "../Views/RCTAnimationType.h"
1717
#import "../Views/RCTPointerEvents.h"
1818

19+
#import "RCTDefines.h"
1920
#import "RCTLog.h"
2021

2122
/**
@@ -116,33 +117,25 @@ typedef BOOL css_overflow;
116117

117118
@end
118119

119-
#ifdef __cplusplus
120-
extern "C" {
121-
#endif
122-
123120
/**
124121
* This function will attempt to set a property using a json value by first
125122
* inferring the correct type from all available information, and then
126123
* applying an appropriate conversion method. If the property does not
127124
* exist, or the type cannot be inferred, the function will return NO.
128125
*/
129-
BOOL RCTSetProperty(id target, NSString *keyPath, SEL type, id json);
126+
RCT_EXTERN BOOL RCTSetProperty(id target, NSString *keyPath, SEL type, id json);
130127

131128
/**
132129
* This function attempts to copy a property from the source object to the
133130
* destination object using KVC. If the property does not exist, or cannot
134131
* be set, it will do nothing and return NO.
135132
*/
136-
BOOL RCTCopyProperty(id target, id source, NSString *keyPath);
133+
RCT_EXTERN BOOL RCTCopyProperty(id target, id source, NSString *keyPath);
137134

138135
/**
139136
* Underlying implementation of RCT_ENUM_CONVERTER macro. Ignore this.
140137
*/
141-
NSNumber *RCTConvertEnumValue(const char *, NSDictionary *, NSNumber *, id);
142-
143-
#ifdef __cplusplus
144-
}
145-
#endif
138+
RCT_EXTERN NSNumber *RCTConvertEnumValue(const char *, NSDictionary *, NSNumber *, id);
146139

147140
/**
148141
* This macro is used for creating simple converter functions that just call

React/Base/RCTDefines.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Foundation/Foundation.h>
11+
12+
/**
13+
* Make global functions usable in C++
14+
*/
15+
#if defined(__cplusplus)
16+
#define RCT_EXTERN extern "C" __attribute__((visibility("default")))
17+
#else
18+
#define RCT_EXTERN extern __attribute__((visibility("default")))
19+
#endif
20+
21+
/**
22+
* The RCT_DEBUG macro can be used to exclude error checking and logging code
23+
* from release builds to improve performance and reduce binary size.
24+
*/
25+
#ifndef RCT_DEBUG
26+
#if DEBUG
27+
#define RCT_DEBUG 1
28+
#else
29+
#define RCT_DEBUG 0
30+
#endif
31+
#endif
32+
33+
/**
34+
* The RCT_DEV macro can be used to enable or disable development tools
35+
* such as the debug executors, dev menu, red box, etc.
36+
*/
37+
#ifndef RCT_DEV
38+
#if DEBUG
39+
#define RCT_DEV 1
40+
#else
41+
#define RCT_DEV 0
42+
#endif
43+
#endif
44+
45+
/**
46+
* By default, only raise an NSAssertion in debug mode
47+
* (custom assert functions will still be called).
48+
*/
49+
#ifndef RCT_NSASSERT
50+
#if RCT_DEBUG
51+
#define RCT_NSASSERT 1
52+
#else
53+
#define RCT_NSASSERT 0
54+
#endif
55+
#endif

React/Base/RCTLog.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
#import <Foundation/Foundation.h>
1111

1212
#import "RCTAssert.h"
13-
14-
#ifdef __cplusplus
15-
extern "C" {
16-
#endif
13+
#import "RCTDefines.h"
1714

1815
/**
1916
* Thresholds for logs to raise an assertion, or display redbox, respectively.
@@ -46,9 +43,9 @@ typedef void (^RCTLogFunction)(
4643
);
4744

4845
/**
49-
* Get a given thread's name (or the current queue, iff in debug mode)
46+
* Get a given thread's name (or the current queue, if in debug mode)
5047
*/
51-
NSString *RCTThreadName(NSThread *);
48+
RCT_EXTERN NSString *RCTThreadName(NSThread *);
5249

5350
/**
5451
* A method to generate a string from a collection of log data. To omit any
@@ -73,35 +70,35 @@ extern RCTLogFunction RCTDefaultLogFunction;
7370
* below which logs will be ignored. Default is RCTLogLevelInfo for debug and
7471
* RCTLogLevelError for production.
7572
*/
76-
void RCTSetLogThreshold(RCTLogLevel threshold);
77-
RCTLogLevel RCTGetLogThreshold(void);
73+
RCT_EXTERN void RCTSetLogThreshold(RCTLogLevel threshold);
74+
RCT_EXTERN RCTLogLevel RCTGetLogThreshold(void);
7875

7976
/**
8077
* These methods get and set the current logging function called by the RCTLogXX
8178
* macros. You can use these to replace the standard behavior with custom log
8279
* functionality.
8380
*/
84-
void RCTSetLogFunction(RCTLogFunction logFunction);
85-
RCTLogFunction RCTGetLogFunction(void);
81+
RCT_EXTERN void RCTSetLogFunction(RCTLogFunction logFunction);
82+
RCT_EXTERN RCTLogFunction RCTGetLogFunction(void);
8683

8784
/**
8885
* This appends additional code to the existing log function, without replacing
8986
* the existing functionality. Useful if you just want to forward logs to an
9087
* extra service without changing the default behavior.
9188
*/
92-
void RCTAddLogFunction(RCTLogFunction logFunction);
89+
RCT_EXTERN void RCTAddLogFunction(RCTLogFunction logFunction);
9390

9491
/**
9592
* This method adds a conditional prefix to any messages logged within the scope
9693
* of the passed block. This is useful for adding additional context to log
9794
* messages. The block will be performed synchronously on the current thread.
9895
*/
99-
void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix);
96+
RCT_EXTERN void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix);
10097

10198
/**
10299
* Private logging functions - ignore these.
103100
*/
104-
void _RCTLogFormat(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
101+
RCT_EXTERN void _RCTLogFormat(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FUNCTION(4,5);
105102
#define _RCTLog(lvl, ...) do { \
106103
if (lvl >= RCTLOG_FATAL_LEVEL) { RCTAssert(NO, __VA_ARGS__); } \
107104
_RCTLogFormat(lvl, __FILE__, __LINE__, __VA_ARGS__); \
@@ -116,7 +113,3 @@ void _RCTLogFormat(RCTLogLevel, const char *, int, NSString *, ...) NS_FORMAT_FU
116113
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
117114
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)
118115
#define RCTLogMustFix(...) _RCTLog(RCTLogLevelMustFix, __VA_ARGS__)
119-
120-
#ifdef __cplusplus
121-
}
122-
#endif

0 commit comments

Comments
 (0)