2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTAssert.h"
|
|
|
|
|
2015-04-11 22:08:00 +00:00
|
|
|
NSString *const RCTErrorDomain = @"RCTErrorDomain";
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-11 22:08:00 +00:00
|
|
|
RCTAssertFunction RCTCurrentAssertFunction = nil;
|
|
|
|
|
2015-06-15 14:53:45 +00:00
|
|
|
NSException *_RCTNotImplementedException(SEL, Class);
|
|
|
|
NSException *_RCTNotImplementedException(SEL cmd, Class cls)
|
|
|
|
{
|
|
|
|
NSString *msg = [NSString stringWithFormat:@"%s is not implemented "
|
|
|
|
"for the class %@", sel_getName(cmd), cls];
|
|
|
|
return [NSException exceptionWithName:@"RCTNotDesignatedInitializerException"
|
|
|
|
reason:msg userInfo:nil];
|
|
|
|
}
|
|
|
|
|
2015-04-11 22:08:00 +00:00
|
|
|
void _RCTAssertFormat(
|
|
|
|
BOOL condition,
|
|
|
|
const char *fileName,
|
|
|
|
int lineNumber,
|
|
|
|
const char *function,
|
|
|
|
NSString *format, ...)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-04-11 22:08:00 +00:00
|
|
|
if (RCTCurrentAssertFunction) {
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
NSString *message = [[NSString alloc] initWithFormat:format arguments:args];
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
RCTCurrentAssertFunction(
|
|
|
|
condition, @(fileName), @(lineNumber), @(function), message
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCTSetAssertFunction(RCTAssertFunction assertFunction)
|
|
|
|
{
|
|
|
|
RCTCurrentAssertFunction = assertFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTAssertFunction RCTGetAssertFunction(void)
|
|
|
|
{
|
|
|
|
return RCTCurrentAssertFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RCTAddAssertFunction(RCTAssertFunction assertFunction)
|
|
|
|
{
|
|
|
|
RCTAssertFunction existing = RCTCurrentAssertFunction;
|
|
|
|
if (existing) {
|
|
|
|
RCTCurrentAssertFunction = ^(BOOL condition,
|
|
|
|
NSString *fileName,
|
|
|
|
NSNumber *lineNumber,
|
|
|
|
NSString *function,
|
|
|
|
NSString *message) {
|
|
|
|
|
|
|
|
existing(condition, fileName, lineNumber, function, message);
|
|
|
|
assertFunction(condition, fileName, lineNumber, function, message);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
RCTCurrentAssertFunction = assertFunction;
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2015-05-25 12:19:53 +00:00
|
|
|
|
|
|
|
NSString *RCTCurrentThreadName(void)
|
|
|
|
{
|
|
|
|
NSThread *thread = [NSThread currentThread];
|
|
|
|
NSString *threadName = [thread isMainThread] ? @"main" : thread.name;
|
|
|
|
if (threadName.length == 0) {
|
|
|
|
#if DEBUG // This is DEBUG not RCT_DEBUG because it *really* must not ship in RC
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
threadName = @(dispatch_queue_get_label(dispatch_get_current_queue()));
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#else
|
|
|
|
threadName = [NSString stringWithFormat:@"%p", thread];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return threadName;
|
|
|
|
}
|