react-native-windows 0.66.23 → 0.66.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +22 -1
- package/CHANGELOG.md +13 -4
- package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.cpp +17 -5
- package/Microsoft.ReactNative.Cxx/JSI/JsiApiContext.h +36 -7
- package/Microsoft.ReactNative.Cxx/ReactPromise.cpp +21 -1
- package/Microsoft.ReactNative.Cxx/ReactPromise.h +27 -0
- package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +1 -1
- package/ReactCommon/ReactCommon.vcxproj +0 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/CompactValue.h +204 -0
- package/package.json +1 -1
- package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGValue.h +0 -94
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,28 @@
|
|
|
2
2
|
"name": "react-native-windows",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Thu, 23 Jun 2022 18:48:52 GMT",
|
|
6
|
+
"tag": "react-native-windows_v0.66.24",
|
|
7
|
+
"version": "0.66.24",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Stop compiling yoga.cpp with /fp:strict. Doing so caused layout issues if Yoga code ran with the processor's rounding mode set to round down, due to NAN being defined in math.h as: ``` (float)(INFINITY * 0.0f) ``` Which macro-expands to: ``` (float)(((float)(1e+300 * 1e+300)) * 0.0f) ``` Which evaluates as follows: ``` (float)(((float)(inf.double)) * 0.0f) (float)(FLT_MAX * 0.0f) // Casting an infinite double to a float yields // FLT_MAX! (float)0.0f ```",
|
|
12
|
+
"author": "hpratt@microsoft.com",
|
|
13
|
+
"commit": "f13c49abc467b74828e3b93b3dd3d07c1c6658ed",
|
|
14
|
+
"package": "react-native-windows"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"comment": "Fix ExecuteJsi on instance shutdown",
|
|
18
|
+
"author": "vmorozov@microsoft.com",
|
|
19
|
+
"commit": "eb2764814113e3e64735e9d7503b8e4af98bb059",
|
|
20
|
+
"package": "react-native-windows"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Fri, 17 Jun 2022 17:40:57 GMT",
|
|
6
27
|
"tag": "react-native-windows_v0.66.23",
|
|
7
28
|
"version": "0.66.23",
|
|
8
29
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
# Change Log - react-native-windows
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 23 Jun 2022 18:48:52 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.66.
|
|
7
|
+
## 0.66.24
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Thu, 23 Jun 2022 18:48:52 GMT
|
|
10
10
|
|
|
11
11
|
### Patches
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- Stop compiling yoga.cpp with /fp:strict. Doing so caused layout issues if Yoga code ran with the processor's rounding mode set to round down, due to NAN being defined in math.h as: ``` (float)(INFINITY * 0.0f) ``` Which macro-expands to: ``` (float)(((float)(1e+300 * 1e+300)) * 0.0f) ``` Which evaluates as follows: ``` (float)(((float)(inf.double)) * 0.0f) (float)(FLT_MAX * 0.0f) // Casting an infinite double to a float yields // FLT_MAX! (float)0.0f ``` (hpratt@microsoft.com)
|
|
14
|
+
- Fix ExecuteJsi on instance shutdown (vmorozov@microsoft.com)
|
|
14
15
|
|
|
16
|
+
## 0.66.23
|
|
17
|
+
|
|
18
|
+
Fri, 17 Jun 2022 17:40:57 GMT
|
|
19
|
+
|
|
20
|
+
### Patches
|
|
21
|
+
|
|
22
|
+
- Fix use of [[maybe_unused]] attribute (vmorozov@microsoft.com)
|
|
23
|
+
|
|
15
24
|
## 0.66.22
|
|
16
25
|
|
|
17
26
|
Thu, 09 Jun 2022 04:18:35 GMT
|
|
@@ -10,16 +10,19 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
|
|
|
10
10
|
|
|
11
11
|
namespace winrt::Microsoft::ReactNative {
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
// If it is not found, then create it and store it in the context.Properties().
|
|
15
|
-
//
|
|
16
|
-
|
|
13
|
+
// Try to get JSI Runtime for the current JS dispatcher thread.
|
|
14
|
+
// If it is not found, then create it based on context JSI runtime and store it in the context.Properties().
|
|
15
|
+
// The function returns nullptr if the current context does not have JSI runtime.
|
|
16
|
+
// It makes sure that the JSI runtime holder is removed when the instance is unloaded.
|
|
17
|
+
facebook::jsi::Runtime *TryGetOrCreateContextRuntime(ReactContext const &context) noexcept {
|
|
17
18
|
ReactDispatcher jsDispatcher = context.JSDispatcher();
|
|
18
19
|
VerifyElseCrashSz(jsDispatcher.HasThreadAccess(), "Must be in JS thread");
|
|
19
20
|
|
|
20
21
|
// The JSI runtime is not available if we do Web debugging when JS is running in web browser.
|
|
21
22
|
JsiRuntime abiJsiRuntime = context.Handle().JSRuntime().as<JsiRuntime>();
|
|
22
|
-
|
|
23
|
+
if (!abiJsiRuntime) {
|
|
24
|
+
return nullptr;
|
|
25
|
+
}
|
|
23
26
|
|
|
24
27
|
// See if the JSI runtime was previously created.
|
|
25
28
|
JsiAbiRuntime *runtime = JsiAbiRuntime::GetFromJsiRuntime(abiJsiRuntime);
|
|
@@ -51,6 +54,15 @@ facebook::jsi::Runtime &GetOrCreateContextRuntime(ReactContext const &context) n
|
|
|
51
54
|
});
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
return runtime;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Calls TryGetOrCreateContextRuntime to get JSI runtime.
|
|
61
|
+
// It crashes when TryGetOrCreateContextRuntime returns null.
|
|
62
|
+
// Note: deprecated in favor of TryGetOrCreateContextRuntime.
|
|
63
|
+
[[deprecated]] facebook::jsi::Runtime &GetOrCreateContextRuntime(ReactContext const &context) noexcept {
|
|
64
|
+
facebook::jsi::Runtime *runtime = TryGetOrCreateContextRuntime(context);
|
|
65
|
+
VerifyElseCrashSz(runtime, "JSI runtime is not available");
|
|
54
66
|
return *runtime;
|
|
55
67
|
}
|
|
56
68
|
|
|
@@ -7,26 +7,55 @@
|
|
|
7
7
|
|
|
8
8
|
#include "../ReactContext.h"
|
|
9
9
|
#include "JsiAbiApi.h"
|
|
10
|
+
#include "ReactPromise.h"
|
|
10
11
|
|
|
11
12
|
namespace winrt::Microsoft::ReactNative {
|
|
12
13
|
|
|
13
|
-
//
|
|
14
|
-
// If it is not found, then create it and store it in the context.Properties().
|
|
15
|
-
//
|
|
16
|
-
|
|
14
|
+
// Try to get JSI Runtime for the current JS dispatcher thread.
|
|
15
|
+
// If it is not found, then create it based on context JSI runtime and store it in the context.Properties().
|
|
16
|
+
// The function returns nullptr if the current context does not have JSI runtime.
|
|
17
|
+
// It makes sure that the JSI runtime holder is removed when the instance is unloaded.
|
|
18
|
+
facebook::jsi::Runtime *TryGetOrCreateContextRuntime(ReactContext const &context) noexcept;
|
|
19
|
+
|
|
20
|
+
// Calls TryGetOrCreateContextRuntime to get JSI runtime.
|
|
21
|
+
// It crashes when TryGetOrCreateContextRuntime returns null.
|
|
22
|
+
// Note: deprecated in favor of TryGetOrCreateContextRuntime.
|
|
23
|
+
[[deprecated]] facebook::jsi::Runtime &GetOrCreateContextRuntime(ReactContext const &context) noexcept;
|
|
17
24
|
|
|
18
25
|
// Call provided lambda with the facebook::jsi::Runtime& parameter.
|
|
19
26
|
// For example: ExecuteJsi(context, [](facebook::jsi::Runtime& runtime){...})
|
|
20
27
|
// The code is executed synchronously if it is already in JSDispatcher, or asynchronously otherwise.
|
|
21
28
|
template <class TCodeWithRuntime>
|
|
22
|
-
void ExecuteJsi(ReactContext const &context, TCodeWithRuntime const &code) {
|
|
29
|
+
void ExecuteJsi(ReactContext const &context, TCodeWithRuntime const &code, ReactPromise<void> *callStatus = nullptr) {
|
|
23
30
|
ReactDispatcher jsDispatcher = context.JSDispatcher();
|
|
31
|
+
auto callCode = [](ReactContext const &context, TCodeWithRuntime const &code, ReactPromise<void> *callStatus) {
|
|
32
|
+
facebook::jsi::Runtime *runtime = TryGetOrCreateContextRuntime(context);
|
|
33
|
+
if (runtime) {
|
|
34
|
+
code(*runtime);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Report status of the call
|
|
38
|
+
if (callStatus) {
|
|
39
|
+
if (runtime) {
|
|
40
|
+
callStatus->Resolve();
|
|
41
|
+
} else {
|
|
42
|
+
callStatus->Reject("No JSI runtime");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
24
47
|
if (jsDispatcher.HasThreadAccess()) {
|
|
25
48
|
// Execute immediately if we are in JS thread.
|
|
26
|
-
|
|
49
|
+
callCode(context, code, callStatus);
|
|
27
50
|
} else {
|
|
28
51
|
// Otherwise, schedule work in JS thread.
|
|
29
|
-
jsDispatcher.Post([
|
|
52
|
+
jsDispatcher.Post([callCode,
|
|
53
|
+
context,
|
|
54
|
+
code,
|
|
55
|
+
callStatus = callStatus ? std::make_unique<ReactPromise<void>>(*callStatus)
|
|
56
|
+
: std::unique_ptr<ReactPromise<void>>(nullptr)]() noexcept {
|
|
57
|
+
callCode(context, code, callStatus.get());
|
|
58
|
+
});
|
|
30
59
|
}
|
|
31
60
|
}
|
|
32
61
|
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
#include "pch.h"
|
|
8
8
|
#include "ReactPromise.h"
|
|
9
|
-
#include "JSValueWriter.h"
|
|
10
9
|
|
|
11
10
|
namespace winrt::Microsoft::ReactNative {
|
|
12
11
|
|
|
@@ -105,6 +104,27 @@ bool ReactPromiseBase::TrySetState(State newState) const noexcept {
|
|
|
105
104
|
return false;
|
|
106
105
|
}
|
|
107
106
|
|
|
107
|
+
/*static*/ MethodResultCallback ReactPromiseBase::GetRejectResultCallback(
|
|
108
|
+
std::function<void(ReactError const &)> const &reject) noexcept {
|
|
109
|
+
return [reject](IJSValueWriter const &outputWriter) noexcept {
|
|
110
|
+
winrt::com_ptr<JSValueTreeWriter> writer = outputWriter.as<JSValueTreeWriter>();
|
|
111
|
+
JSValue jsValue = writer->TakeValue();
|
|
112
|
+
ReactError err{};
|
|
113
|
+
err.Code = jsValue.AsArray()[0].AsObject()[ErrorMapKeyCode].AsString();
|
|
114
|
+
err.Message = jsValue.AsArray()[0].AsObject()[ErrorMapKeyMessage].AsString();
|
|
115
|
+
err.UserInfo = jsValue.AsArray()[0].AsObject()[ErrorMapKeyUserInfo].AsObject().Copy();
|
|
116
|
+
reject(err);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ReactPromise<void>::ReactPromise(
|
|
121
|
+
std::function<void()> const &resolve,
|
|
122
|
+
std::function<void(ReactError const &)> const &reject) noexcept
|
|
123
|
+
: ReactPromiseBase(
|
|
124
|
+
winrt::make<JSValueTreeWriter>(),
|
|
125
|
+
[resolve](IJSValueWriter const & /*outputWriter*/) noexcept { resolve(); },
|
|
126
|
+
GetRejectResultCallback(reject)) {}
|
|
127
|
+
|
|
108
128
|
// Successfully resolve the ReactPromise<void>.
|
|
109
129
|
void ReactPromise<void>::Resolve() const noexcept {
|
|
110
130
|
if (TrySetState(State::Resolved) && m_resolve) {
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
// vnext/Microsoft.ReactNative.Cxx/README.md
|
|
6
6
|
|
|
7
7
|
#pragma once
|
|
8
|
+
#include <functional>
|
|
9
|
+
#include "JSValueReader.h"
|
|
10
|
+
#include "JSValueTreeReader.h"
|
|
11
|
+
#include "JSValueTreeWriter.h"
|
|
12
|
+
#include "JSValueWriter.h"
|
|
8
13
|
#include "ReactError.h"
|
|
9
14
|
#include "winrt/Microsoft.ReactNative.h"
|
|
10
15
|
|
|
@@ -35,6 +40,7 @@ struct ReactPromiseBase {
|
|
|
35
40
|
|
|
36
41
|
protected:
|
|
37
42
|
bool TrySetState(State newState) const noexcept;
|
|
43
|
+
static MethodResultCallback GetRejectResultCallback(std::function<void(ReactError const &)> const &reject) noexcept;
|
|
38
44
|
|
|
39
45
|
protected:
|
|
40
46
|
const std::shared_ptr<std::atomic<State>> m_state;
|
|
@@ -47,6 +53,10 @@ template <class T>
|
|
|
47
53
|
struct ReactPromise : ReactPromiseBase {
|
|
48
54
|
using ReactPromiseBase::ReactPromiseBase;
|
|
49
55
|
|
|
56
|
+
ReactPromise(
|
|
57
|
+
std::function<void(T const &)> const &resolve,
|
|
58
|
+
std::function<void(ReactError const &)> const &reject) noexcept;
|
|
59
|
+
|
|
50
60
|
// Successfully resolve the IReactPromise with an optional value.
|
|
51
61
|
void Resolve(T const &value) const noexcept;
|
|
52
62
|
};
|
|
@@ -55,10 +65,27 @@ template <>
|
|
|
55
65
|
struct ReactPromise<void> : ReactPromiseBase {
|
|
56
66
|
using ReactPromiseBase::ReactPromiseBase;
|
|
57
67
|
|
|
68
|
+
ReactPromise(std::function<void()> const &resolve, std::function<void(ReactError const &)> const &reject) noexcept;
|
|
69
|
+
|
|
58
70
|
// Successfully resolve the IReactPromise with an optional value.
|
|
59
71
|
void Resolve() const noexcept;
|
|
60
72
|
};
|
|
61
73
|
|
|
74
|
+
template <class T>
|
|
75
|
+
ReactPromise<T>::ReactPromise(
|
|
76
|
+
std::function<void(T const &)> const &resolve,
|
|
77
|
+
std::function<void(ReactError const &)> const &reject) noexcept
|
|
78
|
+
: ReactPromiseBase(
|
|
79
|
+
winrt::make<JSValueTreeWriter>(),
|
|
80
|
+
[resolve](IJSValueWriter const &outputWriter) noexcept {
|
|
81
|
+
winrt::com_ptr<JSValueTreeWriter> writer = outputWriter.as<JSValueTreeWriter>();
|
|
82
|
+
auto reader = winrt::make<JSValueTreeReader>(writer->TakeValue());
|
|
83
|
+
T result{};
|
|
84
|
+
ReadArgs(reader, result);
|
|
85
|
+
resolve(result);
|
|
86
|
+
},
|
|
87
|
+
GetRejectResultCallback(reject)) {}
|
|
88
|
+
|
|
62
89
|
// Successfully resolve the ReactPromise with an optional value.
|
|
63
90
|
template <class T>
|
|
64
91
|
void ReactPromise<T>::Resolve(T const &value) const noexcept {
|
|
@@ -23,7 +23,7 @@ void AddTurboModuleProvider(IReactPackageBuilder const &packageBuilder, std::wst
|
|
|
23
23
|
IJsiHostObject abiTurboModule{nullptr};
|
|
24
24
|
// We expect the initializer to be called immediately for TurboModules
|
|
25
25
|
moduleBuilder.AddInitializer([&abiTurboModule](IReactContext const &context) mutable {
|
|
26
|
-
|
|
26
|
+
TryGetOrCreateContextRuntime(ReactContext{context}); // Ensure the JSI runtime is created.
|
|
27
27
|
auto callInvoker = MakeAbiCallInvoker(context.JSDispatcher());
|
|
28
28
|
auto turboModule = std::make_shared<TTurboModule>(callInvoker);
|
|
29
29
|
abiTurboModule = winrt::make<JsiHostObjectWrapper>(std::move(turboModule));
|
|
@@ -72,10 +72,6 @@
|
|
|
72
72
|
<DisableSpecificWarnings>4715;4251;4800;4804;4305;4722;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
|
73
73
|
<PreprocessToFile>false</PreprocessToFile>
|
|
74
74
|
<ForcedIncludeFiles>pch.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
|
|
75
|
-
<!--
|
|
76
|
-
Using Strict FloatingPointModel on x64 to workaround a compiler issue, See https://github.com/microsoft/react-native-windows/issues/4122
|
|
77
|
-
-->
|
|
78
|
-
<FloatingPointModel Condition="'$(Platform)' == 'x64'">Strict</FloatingPointModel>
|
|
79
75
|
</ClCompile>
|
|
80
76
|
<Link>
|
|
81
77
|
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
|
|
12
|
+
#ifdef __cpp_lib_bit_cast
|
|
13
|
+
#include <bit>
|
|
14
|
+
#endif
|
|
15
|
+
#include "YGValue.h"
|
|
16
|
+
#include "YGMacros.h"
|
|
17
|
+
#include <cmath>
|
|
18
|
+
#include <cstdint>
|
|
19
|
+
#include <limits>
|
|
20
|
+
|
|
21
|
+
static_assert(
|
|
22
|
+
std::numeric_limits<float>::is_iec559,
|
|
23
|
+
"facebook::yoga::detail::CompactValue only works with IEEE754 floats");
|
|
24
|
+
|
|
25
|
+
#ifdef YOGA_COMPACT_VALUE_TEST
|
|
26
|
+
#define VISIBLE_FOR_TESTING public:
|
|
27
|
+
#else
|
|
28
|
+
#define VISIBLE_FOR_TESTING private:
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
namespace facebook {
|
|
32
|
+
namespace yoga {
|
|
33
|
+
namespace detail {
|
|
34
|
+
|
|
35
|
+
// This class stores YGValue in 32 bits.
|
|
36
|
+
// - The value does not matter for Undefined and Auto. NaNs are used for their
|
|
37
|
+
// representation.
|
|
38
|
+
// - To differentiate between Point and Percent, one exponent bit is used.
|
|
39
|
+
// Supported the range [0x40, 0xbf] (0xbf is inclusive for point, but
|
|
40
|
+
// exclusive for percent).
|
|
41
|
+
// - Value ranges:
|
|
42
|
+
// points: 1.08420217e-19f to 36893485948395847680
|
|
43
|
+
// 0x00000000 0x3fffffff
|
|
44
|
+
// percent: 1.08420217e-19f to 18446742974197923840
|
|
45
|
+
// 0x40000000 0x7f7fffff
|
|
46
|
+
// - Zero is supported, negative zero is not
|
|
47
|
+
// - values outside of the representable range are clamped
|
|
48
|
+
class YOGA_EXPORT CompactValue {
|
|
49
|
+
friend constexpr bool operator==(CompactValue, CompactValue) noexcept;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
static constexpr auto LOWER_BOUND = 1.08420217e-19f;
|
|
53
|
+
static constexpr auto UPPER_BOUND_POINT = 36893485948395847680.0f;
|
|
54
|
+
static constexpr auto UPPER_BOUND_PERCENT = 18446742974197923840.0f;
|
|
55
|
+
|
|
56
|
+
template <YGUnit Unit>
|
|
57
|
+
static CompactValue of(float value) noexcept {
|
|
58
|
+
if (value == 0.0f || (value < LOWER_BOUND && value > -LOWER_BOUND)) {
|
|
59
|
+
constexpr auto zero =
|
|
60
|
+
Unit == YGUnitPercent ? ZERO_BITS_PERCENT : ZERO_BITS_POINT;
|
|
61
|
+
return {zero};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
constexpr auto upperBound = Unit == YGUnitPercent ? UPPER_BOUND_PERCENT : UPPER_BOUND_POINT;
|
|
65
|
+
if (value > upperBound || value < -upperBound) {
|
|
66
|
+
value = copysignf(upperBound, value);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0;
|
|
70
|
+
auto data = asU32(value);
|
|
71
|
+
data -= BIAS;
|
|
72
|
+
data |= unitBit;
|
|
73
|
+
return {data};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template <YGUnit Unit>
|
|
77
|
+
static CompactValue ofMaybe(float value) noexcept {
|
|
78
|
+
return std::isnan(value) || std::isinf(value) ? ofUndefined() : of<Unit>(value);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static constexpr CompactValue ofZero() noexcept {
|
|
82
|
+
return CompactValue{ZERO_BITS_POINT};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static constexpr CompactValue ofUndefined() noexcept {
|
|
86
|
+
return CompactValue{};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static constexpr CompactValue ofAuto() noexcept {
|
|
90
|
+
return CompactValue{AUTO_BITS};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
constexpr CompactValue() noexcept : repr_(0x7FC00000) {}
|
|
94
|
+
|
|
95
|
+
CompactValue(const YGValue &x) noexcept : repr_(uint32_t{0}) {
|
|
96
|
+
switch (x.unit) {
|
|
97
|
+
case YGUnitUndefined:
|
|
98
|
+
*this = ofUndefined();
|
|
99
|
+
break;
|
|
100
|
+
case YGUnitAuto:
|
|
101
|
+
*this = ofAuto();
|
|
102
|
+
break;
|
|
103
|
+
case YGUnitPoint:
|
|
104
|
+
*this = of<YGUnitPoint>(x.value);
|
|
105
|
+
break;
|
|
106
|
+
case YGUnitPercent:
|
|
107
|
+
*this = of<YGUnitPercent>(x.value);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
operator YGValue() const noexcept {
|
|
113
|
+
switch (repr_) {
|
|
114
|
+
case AUTO_BITS:
|
|
115
|
+
return YGValueAuto;
|
|
116
|
+
case ZERO_BITS_POINT:
|
|
117
|
+
return YGValue{0.0f, YGUnitPoint};
|
|
118
|
+
case ZERO_BITS_PERCENT:
|
|
119
|
+
return YGValue{0.0f, YGUnitPercent};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (std::isnan(asFloat(repr_))) {
|
|
123
|
+
return YGValueUndefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
auto data = repr_;
|
|
127
|
+
data &= ~PERCENT_BIT;
|
|
128
|
+
data += BIAS;
|
|
129
|
+
|
|
130
|
+
return YGValue{asFloat(data), repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
bool isUndefined() const noexcept {
|
|
134
|
+
return (repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT && repr_ != ZERO_BITS_PERCENT && std::isnan(asFloat(repr_)));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
bool isAuto() const noexcept {
|
|
138
|
+
return repr_ == AUTO_BITS;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private:
|
|
142
|
+
uint32_t repr_;
|
|
143
|
+
|
|
144
|
+
static constexpr uint32_t BIAS = 0x20000000;
|
|
145
|
+
static constexpr uint32_t PERCENT_BIT = 0x40000000;
|
|
146
|
+
|
|
147
|
+
// these are signaling NaNs with specific bit pattern as payload they will be
|
|
148
|
+
// silenced whenever going through an FPU operation on ARM + x86
|
|
149
|
+
static constexpr uint32_t AUTO_BITS = 0x7faaaaaa;
|
|
150
|
+
static constexpr uint32_t ZERO_BITS_POINT = 0x7f8f0f0f;
|
|
151
|
+
static constexpr uint32_t ZERO_BITS_PERCENT = 0x7f80f0f0;
|
|
152
|
+
|
|
153
|
+
constexpr CompactValue(uint32_t data) noexcept : repr_(data) {}
|
|
154
|
+
|
|
155
|
+
VISIBLE_FOR_TESTING uint32_t repr() {
|
|
156
|
+
return repr_;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static uint32_t asU32(float f) {
|
|
160
|
+
#ifdef __cpp_lib_bit_cast
|
|
161
|
+
return std::bit_cast<uint32_t>(f);
|
|
162
|
+
#else
|
|
163
|
+
uint32_t u;
|
|
164
|
+
static_assert(sizeof(u) == sizeof(f));
|
|
165
|
+
std::memcpy(&u, &f, sizeof(f));
|
|
166
|
+
return u;
|
|
167
|
+
#endif
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static float asFloat(uint32_t u) {
|
|
171
|
+
#ifdef __cpp_lib_bit_cast
|
|
172
|
+
return std::bit_cast<float>(data);
|
|
173
|
+
#else
|
|
174
|
+
float f;
|
|
175
|
+
static_assert(sizeof(f) == sizeof(u));
|
|
176
|
+
std::memcpy(&f, &u, sizeof(u));
|
|
177
|
+
return f;
|
|
178
|
+
#endif
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
template <>
|
|
184
|
+
CompactValue CompactValue::of<YGUnitUndefined>(float) noexcept = delete;
|
|
185
|
+
template <>
|
|
186
|
+
CompactValue CompactValue::of<YGUnitAuto>(float) noexcept = delete;
|
|
187
|
+
template <>
|
|
188
|
+
CompactValue CompactValue::ofMaybe<YGUnitUndefined>(float) noexcept = delete;
|
|
189
|
+
template <>
|
|
190
|
+
CompactValue CompactValue::ofMaybe<YGUnitAuto>(float) noexcept = delete;
|
|
191
|
+
|
|
192
|
+
constexpr bool operator==(CompactValue a, CompactValue b) noexcept {
|
|
193
|
+
return a.repr_ == b.repr_;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
constexpr bool operator!=(CompactValue a, CompactValue b) noexcept {
|
|
197
|
+
return !(a == b);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
} // namespace detail
|
|
201
|
+
} // namespace yoga
|
|
202
|
+
} // namespace facebook
|
|
203
|
+
|
|
204
|
+
#endif
|
package/package.json
CHANGED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
#pragma once
|
|
9
|
-
|
|
10
|
-
#include <math.h>
|
|
11
|
-
#include "YGEnums.h"
|
|
12
|
-
#include "YGMacros.h"
|
|
13
|
-
|
|
14
|
-
#if defined(_MSC_VER) && defined(__clang__)
|
|
15
|
-
#define COMPILING_WITH_CLANG_ON_WINDOWS
|
|
16
|
-
#endif
|
|
17
|
-
#if defined(COMPILING_WITH_CLANG_ON_WINDOWS)
|
|
18
|
-
#include <limits>
|
|
19
|
-
constexpr float YGUndefined = std::numeric_limits<float>::quiet_NaN();
|
|
20
|
-
#else
|
|
21
|
-
YG_EXTERN_C_BEGIN
|
|
22
|
-
|
|
23
|
-
#if defined(_MSC_VER)
|
|
24
|
-
#define YGUndefined __builtin_nanf("0")
|
|
25
|
-
#else
|
|
26
|
-
#define YGUndefined NAN
|
|
27
|
-
#endif
|
|
28
|
-
|
|
29
|
-
#endif
|
|
30
|
-
|
|
31
|
-
typedef struct YGValue {
|
|
32
|
-
float value;
|
|
33
|
-
YGUnit unit;
|
|
34
|
-
} YGValue;
|
|
35
|
-
|
|
36
|
-
YOGA_EXPORT extern const YGValue YGValueAuto;
|
|
37
|
-
YOGA_EXPORT extern const YGValue YGValueUndefined;
|
|
38
|
-
YOGA_EXPORT extern const YGValue YGValueZero;
|
|
39
|
-
|
|
40
|
-
#if !defined(COMPILING_WITH_CLANG_ON_WINDOWS)
|
|
41
|
-
YG_EXTERN_C_END
|
|
42
|
-
#endif
|
|
43
|
-
#undef COMPILING_WITH_CLANG_ON_WINDOWS
|
|
44
|
-
|
|
45
|
-
#ifdef __cplusplus
|
|
46
|
-
|
|
47
|
-
inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
|
|
48
|
-
if (lhs.unit != rhs.unit) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
switch (lhs.unit) {
|
|
53
|
-
case YGUnitUndefined:
|
|
54
|
-
case YGUnitAuto:
|
|
55
|
-
return true;
|
|
56
|
-
case YGUnitPoint:
|
|
57
|
-
case YGUnitPercent:
|
|
58
|
-
return lhs.value == rhs.value;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
inline bool operator!=(const YGValue& lhs, const YGValue& rhs) {
|
|
65
|
-
return !(lhs == rhs);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
inline YGValue operator-(const YGValue& value) {
|
|
69
|
-
return {-value.value, value.unit};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
namespace facebook {
|
|
73
|
-
namespace yoga {
|
|
74
|
-
namespace literals {
|
|
75
|
-
|
|
76
|
-
inline YGValue operator"" _pt(long double value) {
|
|
77
|
-
return YGValue{static_cast<float>(value), YGUnitPoint};
|
|
78
|
-
}
|
|
79
|
-
inline YGValue operator"" _pt(unsigned long long value) {
|
|
80
|
-
return operator"" _pt(static_cast<long double>(value));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
inline YGValue operator"" _percent(long double value) {
|
|
84
|
-
return YGValue{static_cast<float>(value), YGUnitPercent};
|
|
85
|
-
}
|
|
86
|
-
inline YGValue operator"" _percent(unsigned long long value) {
|
|
87
|
-
return operator"" _percent(static_cast<long double>(value));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
} // namespace literals
|
|
91
|
-
} // namespace yoga
|
|
92
|
-
} // namespace facebook
|
|
93
|
-
|
|
94
|
-
#endif
|