Files
react-native/ReactCommon/react/debug/react_native_assert.h
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

47 lines
1.3 KiB
C

/*
* 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.
*/
// No header guards since it is legitimately possible to include this file more
// than once with and without REACT_NATIVE_DEBUG.
// react_native_assert allows us to opt-in to specific asserts on Android and
// test before moving on. When all issues have been found, maybe we can use
// `UNDEBUG` flag to disable NDEBUG in debug builds on Android.
// Asserting is appropriate for conditions that:
// 1. May or may not be recoverable, and
// 2. imply there is a bug in React Native when violated.
// For recoverable conditions that can be violated by user mistake (e.g. JS
// code passes an unexpected prop value), consider react_native_expect instead.
#include "flags.h"
#undef react_native_assert
#ifndef REACT_NATIVE_DEBUG
#define react_native_assert(e) ((void)0)
#else // REACT_NATIVE_DEBUG
#define react_native_assert(e) \
((e) ? (void)0 : react_native_assert_fail(__func__, __FILE__, __LINE__, #e))
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void react_native_assert_fail(
const char *func,
const char *file,
int line,
const char *expr);
#ifdef __cplusplus
}
#endif // __cpusplus
#endif // REACT_NATIVE_DEBUG