Files
react-native/ReactCommon/react/debug/ios/react_native_assert.mm
T
Nick Gerleman c5bc3f1373 Use NSCAssert() in react_native_assert instead of C assert() (#36177)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36177

react_native_assert calls C `assert()`, where XCode does not have a built-in breakpoint navigator to hook to assertion failures (though you can add a symbolic breakpoint to "abort()" to get the effect). This changes the Apple implemented of `react_native_assert()` to use `NSCAssert` under the hood. This is safe to use in C functions, but will be trapped by the default XCode exceptions breakpoint navigator.

Changelog:
[iOS][Fixed] - Use NSCAssert() in react_native_assert instead of C assert()

Reviewed By: cipolleschi

Differential Revision: D43275024

fbshipit-source-id: 43c4e4f1ae6b99f32634d4b1880bce712c3ae8f6
2023-02-22 14:59:40 -08:00

28 lines
1.0 KiB
Plaintext

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/NSException.h>
#import <glog/logging.h>
#import <react/debug/react_native_assert.h>
#ifdef REACT_NATIVE_DEBUG
extern "C" void react_native_assert_fail(const char *func, const char *file, int line, const char *expr)
{
// flush logs because some might be lost on iOS if an assert is hit right after
// this. If you are trying to debug something actively and have added lots of
// LOG statements to track down an issue, there is race between flushing the
// final logs and stopping execution when the assert hits. Thus, if we know an
// assert will fail, we force flushing to happen right before the assert.
LOG(ERROR) << "react_native_assert failure: " << expr;
google::FlushLogFiles(google::GLOG_INFO /*min_severity*/);
NSCAssert(false, @"%s:%d: function %s: assertion failed (%s)", file, line, func, expr);
}
#endif