mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Introduce CSSAssertSetFailFunc and CSSAsserFail to throw managed exception
Reviewed By: emilsjolander Differential Revision: D3982084 fbshipit-source-id: 058a87c10ca89238362be4d8759cc00dd0c9b376
This commit is contained in:
committed by
Facebook Github Bot
parent
b99343bdad
commit
9673c885fd
@@ -219,6 +219,7 @@ void _CSSNodeMarkDirty(const CSSNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index) {
|
void CSSNodeInsertChild(const CSSNodeRef node, const CSSNodeRef child, const uint32_t index) {
|
||||||
|
CSS_ASSERT(child->parent == NULL, "Child already has a parent, it must be removed first.");
|
||||||
CSSNodeListInsert(node->children, child, index);
|
CSSNodeListInsert(node->children, child, index);
|
||||||
child->parent = node;
|
child->parent = node;
|
||||||
_CSSNodeMarkDirty(node);
|
_CSSNodeMarkDirty(node);
|
||||||
@@ -2295,3 +2296,17 @@ void CSSNodeCalculateLayout(const CSSNodeRef node,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CSS_ASSERT_FAIL_ENABLED
|
||||||
|
static CSSAssertFailFunc gAssertFailFunc;
|
||||||
|
|
||||||
|
void CSSAssertSetFailFunc(CSSAssertFailFunc func) {
|
||||||
|
gAssertFailFunc = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSSAssertFail(const char *message) {
|
||||||
|
if (gAssertFailFunc) {
|
||||||
|
(*gAssertFailFunc)(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -122,6 +122,10 @@ typedef CSSSize (*CSSMeasureFunc)(void *context,
|
|||||||
CSSMeasureMode heightMode);
|
CSSMeasureMode heightMode);
|
||||||
typedef void (*CSSPrintFunc)(void *context);
|
typedef void (*CSSPrintFunc)(void *context);
|
||||||
|
|
||||||
|
#ifdef CSS_ASSERT_FAIL_ENABLED
|
||||||
|
typedef void (*CSSAssertFailFunc)(const char *message);
|
||||||
|
#endif
|
||||||
|
|
||||||
// CSSNode
|
// CSSNode
|
||||||
WIN_EXPORT CSSNodeRef CSSNodeNew();
|
WIN_EXPORT CSSNodeRef CSSNodeNew();
|
||||||
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
|
||||||
@@ -206,4 +210,10 @@ CSS_NODE_LAYOUT_PROPERTY(float, Width);
|
|||||||
CSS_NODE_LAYOUT_PROPERTY(float, Height);
|
CSS_NODE_LAYOUT_PROPERTY(float, Height);
|
||||||
CSS_NODE_LAYOUT_PROPERTY(CSSDirection, Direction);
|
CSS_NODE_LAYOUT_PROPERTY(CSSDirection, Direction);
|
||||||
|
|
||||||
|
#ifdef CSS_ASSERT_FAIL_ENABLED
|
||||||
|
// Assert
|
||||||
|
WIN_EXPORT void CSSAssertSetFailFunc(CSSAssertFailFunc func);
|
||||||
|
WIN_EXPORT void CSSAssertFail(const char *message);
|
||||||
|
#endif
|
||||||
|
|
||||||
CSS_EXTERN_C_END
|
CSS_EXTERN_C_END
|
||||||
|
|||||||
@@ -33,8 +33,16 @@
|
|||||||
#define CSS_ABORT()
|
#define CSS_ABORT()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CSS_ASSERT(X, message) \
|
#if CSS_ASSERT_FAIL_ENABLED
|
||||||
if (!(X)) { \
|
#define CSS_ERROR_FUNC(message) CSSAssertFail(message)
|
||||||
fprintf(stderr, "%s\n", message); \
|
#else
|
||||||
CSS_ABORT(); \
|
#define CSS_ERROR_FUNC(message) fprintf(stderr, "%s", message)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CSS_ASSERT
|
||||||
|
#define CSS_ASSERT(X, message) \
|
||||||
|
if (!(X)) { \
|
||||||
|
CSS_ERROR_FUNC(message); \
|
||||||
|
CSS_ABORT(); \
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user