Skip to content

Commit

Permalink
Improved debug and fixed macros
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Apr 30, 2015
1 parent d82aaa7 commit eb04760
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 74 deletions.
1 change: 1 addition & 0 deletions Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0610"
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
Expand Down Expand Up @@ -182,6 +179,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -199,6 +197,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
Expand Down
10 changes: 0 additions & 10 deletions Libraries/RCTTest/RCTTestRunner.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#import "RCTTestRunner.h"

#import "FBSnapshotTestController.h"
#import "RCTDefines.h"
#import "RCTRedBox.h"
#import "RCTRootView.h"
#import "RCTTestModule.h"
Expand Down Expand Up @@ -76,8 +75,6 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictiona
vc.view = [[UIView alloc] init];
[vc.view addSubview:rootView]; // Add as subview so it doesn't get resized

#if RCT_DEBUG // Prevents build errors, as RCTRedBox is underfined if RCT_DEBUG=0

NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
NSString *error = [[RCTRedBox sharedInstance] currentErrorMessage];
while ([date timeIntervalSinceNow] > 0 && ![testModule isDone] && error == nil) {
Expand All @@ -98,13 +95,6 @@ - (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictiona
} else {
RCTAssert([testModule isDone], @"Test didn't finish within %d seconds", TIMEOUT_SECONDS);
}

#else

expectErrorBlock(@"RCTRedBox unavailable. Set RCT_DEBUG=1 for testing.");

#endif

}

@end
33 changes: 1 addition & 32 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,6 @@ - (void)setUp
_loading = NO;
if (error != nil) {

#if RCT_DEBUG // Red box is only available in debug mode

NSArray *stack = [[error userInfo] objectForKey:@"stack"];
if (stack) {
[[RCTRedBox sharedInstance] showErrorMessage:[error localizedDescription]
Expand All @@ -945,8 +943,6 @@ - (void)setUp
withDetails:[error localizedFailureReason]];
}

#endif

} else {

[[NSNotificationCenter defaultCenter] postNotificationName:RCTJavaScriptDidLoadNotification
Expand Down Expand Up @@ -980,33 +976,6 @@ - (void)bindKeys
action:^(UIKeyCommand *command) {
[weakSelf reload];
}];
// reset to normal mode
[commands registerKeyCommandWithInput:@"n"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTBridge *strongSelf = weakSelf;
strongSelf.executorClass = Nil;
[strongSelf reload];
}];

#if RCT_DEV // Debug executors are only available in dev mode

// reload in debug mode
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTBridge *strongSelf = weakSelf;
strongSelf.executorClass = NSClassFromString(@"RCTWebSocketExecutor");
if (!strongSelf.executorClass) {
strongSelf.executorClass = NSClassFromString(@"RCTWebViewExecutor");
}
if (!strongSelf.executorClass) {
RCTLogError(@"WebSocket debugger is not available. "
"Did you forget to include RCTWebSocketExecutor?");
}
[strongSelf reload];
}];
#endif
#endif

}
Expand Down Expand Up @@ -1091,7 +1060,7 @@ - (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args

[self _invokeAndProcessModule:@"BatchedBridge"
method:@"callFunctionReturnFlushedQueue"
arguments:@[moduleID, methodID, args ?: @[]]
arguments:@[moduleID ?: @0, methodID ?: @0, args ?: @[]]
context:RCTGetExecutorID(_javaScriptExecutor)];
}

Expand Down
6 changes: 3 additions & 3 deletions React/Base/RCTDevMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
/**
* Developer menu, useful for exposing extra functionality when debugging.
*/
@interface RCTDevMenu : NSObject <RCTBridgeModule, RCTInvalidating>
@interface RCTDevMenu : NSObject

/**
* Is the menu enabled. The menu is enabled by default in debug mode, but
* Is the menu enabled. The menu is enabled by default if RCT_DEV=1, but
* you may wish to disable it so that you can provide your own shake handler.
*/
@property (nonatomic, assign) BOOL shakeToShow;
Expand All @@ -41,7 +41,7 @@
@property (nonatomic, assign) NSTimeInterval liveReloadPeriod;

/**
* Manually show the menu. This will.
* Manually show the dev menu.
*/
- (void)show;

Expand Down
39 changes: 38 additions & 1 deletion React/Base/RCTDevMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
#import "RCTDevMenu.h"

#import "RCTBridge.h"
#import "RCTDefines.h"
#import "RCTKeyCommands.h"
#import "RCTLog.h"
#import "RCTProfile.h"
#import "RCTRootView.h"
#import "RCTSourceCode.h"
#import "RCTUtils.h"

#if RCT_DEV

@interface RCTBridge (Profiling)

- (void)startProfiling;
Expand All @@ -36,7 +40,7 @@ - (void)RCT_motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event

@end

@interface RCTDevMenu () <UIActionSheetDelegate>
@interface RCTDevMenu () <RCTBridgeModule, RCTInvalidating, UIActionSheetDelegate>

@end

Expand Down Expand Up @@ -68,6 +72,28 @@ - (instancetype)init
selector:@selector(showOnShake)
name:RCTShowDevMenuNotification
object:nil];

#if TARGET_IPHONE_SIMULATOR

__weak RCTDevMenu *weakSelf = self;
RCTKeyCommands *commands = [RCTKeyCommands sharedInstance];

// Workaround around the first cmd+D not working: http://openradar.appspot.com/19613391
// You can register just the cmd key and do nothing. This will trigger the bug and cmd+R
// will work like a charm!
[commands registerKeyCommandWithInput:@""
modifierFlags:UIKeyModifierCommand
action:NULL];

// reload in debug mode
[commands registerKeyCommandWithInput:@"d"
modifierFlags:UIKeyModifierCommand
action:^(UIKeyCommand *command) {
__strong RCTDevMenu *strongSelf = weakSelf;
[strongSelf show];
}];
#endif

}
return self;
}
Expand Down Expand Up @@ -104,6 +130,7 @@ - (void)show

actionSheet.actionSheetStyle = UIBarStyleBlack;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
_actionSheet = actionSheet;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Expand Down Expand Up @@ -218,6 +245,16 @@ - (void)invalidate

@end

#else // Unvailable

@implementation RCTDevMenu

- (void)show {}

@end

#endif

@implementation RCTBridge (RCTDevMenu)

- (RCTDevMenu *)devMenu
Expand Down
6 changes: 0 additions & 6 deletions React/Base/RCTRedBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTDefines.h"

#if RCT_DEBUG // Red box is only available in debug mode

#import <UIKit/UIKit.h>

@interface RCTRedBox : NSObject
Expand All @@ -27,5 +23,3 @@
- (void)dismiss;

@end

#endif
22 changes: 18 additions & 4 deletions React/Base/RCTRedBox.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTDefines.h"

#if RCT_DEBUG // Red box is only available in debug mode

#import "RCTRedBox.h"

#import "RCTBridge.h"
#import "RCTDefines.h"
#import "RCTUtils.h"

#if RCT_DEBUG

@interface RCTRedBoxWindow : UIWindow <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, copy) NSString *lastErrorMessage;
Expand Down Expand Up @@ -310,4 +309,19 @@ - (void)dismiss

@end

#else // Disabled

@implementation RCTRedBox

+ (instancetype)sharedInstance { return nil; }
- (void)showErrorMessage:(NSString *)message {}
- (void)showErrorMessage:(NSString *)message withDetails:(NSString *)details {}
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
- (void)updateErrorMessage:(NSString *)message withStack:(NSArray *)stack {}
- (void)showErrorMessage:(NSString *)message withStack:(NSArray *)stack showIfHidden:(BOOL)shouldShow {}
- (NSString *)currentErrorMessage { return nil; }
- (void)dismiss {}

@end

#endif
10 changes: 3 additions & 7 deletions React/Modules/RCTExceptionsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ - (instancetype)init

} else {

// Filter out numbers so the same base errors are mapped to the same categories independent of incorrect values.
NSString *pattern = @"[+-]?\\d+[,.]?\\d*";
NSString *sanitizedMessage = [message stringByReplacingOccurrencesOfString:pattern withString:@"<num>" options:NSRegularExpressionSearch range:(NSRange){0, message.length}];

if (sanitizedMessage.length > maxMessageLength) {
sanitizedMessage = [[sanitizedMessage substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
if (message.length > maxMessageLength) {
message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."];
}

NSMutableString *prettyStack = [NSMutableString stringWithString:@"\n"];
for (NSDictionary *frame in stack) {
[prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]];
}

NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:sanitizedMessage];
NSString *name = [@"Unhandled JS Exception: " stringByAppendingString:message];
[NSException raise:name format:@"Message: %@, stack: %@", message, prettyStack];
}

Expand Down
12 changes: 6 additions & 6 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
"RCT_DEBUG=1",
"RCT_DEV=1",
"RCT_NSASSERT=1",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down Expand Up @@ -621,6 +622,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -638,10 +640,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -658,6 +657,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_STATIC_ANALYZER_MODE = deep;
GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)";
GCC_WARN_ABOUT_MISSING_NEWLINE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
Expand Down

0 comments on commit eb04760

Please sign in to comment.