Introduce CSSAssertSetFailFunc and CSSAsserFail to throw managed exception
Summary: - Define CSS_ASSERT_FAIL_ENABLED for P/Invoke (Visual Studio project already has it) - Pass managed delegate pointer to unmanaged side via P/Invoke. - CSSAssertFail will call the managed delegate when assert failed. - The delegate will throw managed exception. Reviewed By: emilsjolander Differential Revision: D3982084 fbshipit-source-id: 058a87c10ca89238362be4d8759cc00dd0c9b376
This commit is contained in:
committed by
Facebook Github Bot
parent
90844d62c5
commit
56f6efdecf
31
csharp/Facebook.CSSLayout/CSSAssert.cs
Normal file
31
csharp/Facebook.CSSLayout/CSSAssert.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2014-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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
internal static class CSSAssert
|
||||
{
|
||||
public delegate void FailFunc(string message);
|
||||
|
||||
private static bool _assertInitialized;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (!_assertInitialized)
|
||||
{
|
||||
Native.CSSAssertSetFailFunc((message) => {
|
||||
throw new InvalidOperationException(message);
|
||||
});
|
||||
_assertInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -93,6 +93,7 @@ namespace Facebook.CSSLayout
|
||||
throw new InvalidOperationException("Allready initialized node");
|
||||
}
|
||||
|
||||
CSSAssert.Initialize();
|
||||
_cssNode = Native.CSSNodeNew();
|
||||
_children = new List<CSSNode>(4);
|
||||
Native.CSSNodeSetPrintFunc(_cssNode, _printFunc);
|
||||
|
@@ -20,6 +20,9 @@ namespace Facebook.CSSLayout
|
||||
private const string DllName = "CSSLayout";
|
||||
#endif
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSAssertSetFailFunc(CSSAssert.FailFunc func);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeNew();
|
||||
|
||||
|
Reference in New Issue
Block a user