Skip to content

Commit 56e79f5

Browse files
authored
Remove legacy cxxmodules (#15151)
* Remove legacy cxxmodules * Change files * remove UT of now deleted code * format
1 parent 8dd69ff commit 56e79f5

40 files changed

Lines changed: 44 additions & 2391 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Remove legacy cxxmodules",
4+
"packageName": "react-native-windows",
5+
"email": "30809111+acoates-ms@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

vnext/Desktop.DLL/react-native-win32.x64.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ EXPORTS
3434
?at@dynamic@folly@@QEGBAAEBU12@V?$Range@PEBD@2@@Z
3535
?getRuntimeExecutor@Instance@react@facebook@@QEAA?AV?$function@$$A6AX$$QEAV?$function@$$A6AXAEAVRuntime@jsi@facebook@@@Z@std@@@Z@std@@XZ
3636
?callJSFunction@Instance@react@facebook@@QEAAX$$QEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0$$QEAUdynamic@folly@@@Z
37-
?createI18nModule@windows@react@@YA?AV?$unique_ptr@VCxxModule@module@xplat@facebook@@U?$default_delete@VCxxModule@module@xplat@facebook@@@std@@@std@@V?$unique_ptr@UII18nModule@windows@react@@U?$default_delete@UII18nModule@windows@react@@@std@@@4@@Z
3837
??$to_ascii_with_route@$09U?$to_ascii_alphabet@$0A@@folly@@$0BE@@detail@folly@@YA_KAEAY0BE@D_K@Z
3938
??$to_ascii_with_route@$09U?$to_ascii_alphabet@$0A@@folly@@@detail@folly@@YA_KPEADPEBD_K@Z
4039
??$to_ascii_size_route@$09@detail@folly@@YA_K_K@Z
@@ -58,7 +57,6 @@ EXPORTS
5857
?GetRuntimeOptionString@React@Microsoft@@YA?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV34@@Z
5958
?makeChakraRuntime@JSI@Microsoft@@YA?AV?$unique_ptr@VRuntime@jsi@facebook@@U?$default_delete@VRuntime@jsi@facebook@@@std@@@std@@$$QEAUChakraRuntimeArgs@12@@Z
6059
?Make@IHttpResource@Networking@React@Microsoft@@SA?AV?$shared_ptr@UIHttpResource@Networking@React@Microsoft@@@std@@XZ
61-
?CreateTimingModule@react@facebook@@YA?AV?$unique_ptr@VCxxModule@module@xplat@facebook@@U?$default_delete@VCxxModule@module@xplat@facebook@@@std@@@std@@AEBV?$shared_ptr@VMessageQueueThread@react@facebook@@@4@@Z
6260
?MakeJSQueueThread@ReactNative@Microsoft@@YA?AV?$shared_ptr@VMessageQueueThread@react@facebook@@@std@@XZ
6361
?Hash128@SpookyHashV2@hash@folly@@SAXPEBX_KPEA_K2@Z
6462
??1Instance@react@facebook@@UEAA@XZ

vnext/Desktop.DLL/react-native-win32.x86.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ EXPORTS
3535
?at@dynamic@folly@@QGBEABU12@V?$Range@PBD@2@@Z
3636
?getRuntimeExecutor@Instance@react@facebook@@QAE?AV?$function@$$A6GX$$QAV?$function@$$A6GXAAVRuntime@jsi@facebook@@@Z@std@@@Z@std@@XZ
3737
?callJSFunction@Instance@react@facebook@@QAEX$$QAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0$$QAUdynamic@folly@@@Z
38-
?createI18nModule@windows@react@@YG?AV?$unique_ptr@VCxxModule@module@xplat@facebook@@U?$default_delete@VCxxModule@module@xplat@facebook@@@std@@@std@@V?$unique_ptr@UII18nModule@windows@react@@U?$default_delete@UII18nModule@windows@react@@@std@@@4@@Z
3938
??$to_ascii_size_route@$09@detail@folly@@YGI_K@Z
4039
??$to_ascii_with_route@$09U?$to_ascii_alphabet@$0A@@folly@@$0BE@@detail@folly@@YGIAAY0BE@D_K@Z
4140
?getModuleRegistry@Instance@react@facebook@@QAEAAVModuleRegistry@23@XZ
@@ -55,7 +54,6 @@ EXPORTS
5554
?GetRuntimeOptionInt@React@Microsoft@@YA?BHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z
5655
?GetRuntimeOptionString@React@Microsoft@@YA?BV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV34@@Z
5756
?makeChakraRuntime@JSI@Microsoft@@YG?AV?$unique_ptr@VRuntime@jsi@facebook@@U?$default_delete@VRuntime@jsi@facebook@@@std@@@std@@$$QAUChakraRuntimeArgs@12@@Z
58-
?CreateTimingModule@react@facebook@@YG?AV?$unique_ptr@VCxxModule@module@xplat@facebook@@U?$default_delete@VCxxModule@module@xplat@facebook@@@std@@@std@@ABV?$shared_ptr@VMessageQueueThread@react@facebook@@@4@@Z
5957
?Make@IHttpResource@Networking@React@Microsoft@@SG?AV?$shared_ptr@UIHttpResource@Networking@React@Microsoft@@@std@@XZ
6058
?MakeJSQueueThread@ReactNative@Microsoft@@YG?AV?$shared_ptr@VMessageQueueThread@react@facebook@@@std@@XZ
6159
?Hash128@SpookyHashV2@hash@folly@@SGXPBXIPA_K1@Z

vnext/Desktop.UnitTests/React.Windows.Desktop.UnitTests.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@
114114
<ClCompile Include="UtilsTest.cpp" />
115115
<ClCompile Include="WebSocketJSExecutorTest.cpp" />
116116
<ClCompile Include="WebSocketMocks.cpp" />
117-
<ClCompile Include="WebSocketModuleTest.cpp" />
118117
<ClCompile Include="WinRTNetworkingMocks.cpp" />
119118
<ClCompile Include="WinRTWebSocketResourceUnitTest.cpp" />
120119
</ItemGroup>

vnext/Desktop.UnitTests/React.Windows.Desktop.UnitTests.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
<ClCompile Include="WebSocketJSExecutorTest.cpp">
3535
<Filter>Unit Tests</Filter>
3636
</ClCompile>
37-
<ClCompile Include="WebSocketModuleTest.cpp">
38-
<Filter>Unit Tests</Filter>
39-
</ClCompile>
4037
<ClCompile Include="WinRTWebSocketResourceUnitTest.cpp">
4138
<Filter>Unit Tests</Filter>
4239
</ClCompile>

vnext/Desktop/Modules/DesktopTimingModule.cpp

Lines changed: 0 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -68,244 +68,6 @@ bool TimerQueue::IsEmpty() const {
6868
return m_timerVector.empty();
6969
}
7070

71-
//==============================================================================
72-
// TimingHelper
73-
//==============================================================================
74-
75-
/*static*/ void TimingHelper::ThreadpoolTimerCallback(PTP_CALLBACK_INSTANCE, PVOID Parameter, PTP_TIMER) noexcept {
76-
static_cast<TimingHelper *>(Parameter)->OnTimerRaised();
77-
}
78-
79-
void TimingHelper::OnTimerRaised() noexcept {
80-
if (auto inst = m_wkInstance.lock()) {
81-
if (auto nativeThread = m_nativeThread.lock()) {
82-
// Make sure we execute it on native thread for native modules
83-
// Capture weak_ptr "this" because callback will be executed on native
84-
// thread even if "this" is destroyed.
85-
nativeThread->runOnQueue([weakThis = std::weak_ptr<TimingHelper>(shared_from_this())]() {
86-
auto strongThis = weakThis.lock();
87-
if (!strongThis) {
88-
return;
89-
}
90-
91-
if ((!strongThis->m_threadpoolTimer) || strongThis->m_timerQueue.IsEmpty()) {
92-
return;
93-
}
94-
95-
folly::dynamic readyTimers = folly::dynamic::array();
96-
auto now = std::chrono::system_clock::now();
97-
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
98-
99-
// Fire timers which will be expired in 10ms
100-
while (!strongThis->m_timerQueue.IsEmpty() && now_ms > strongThis->m_timerQueue.Front().DueTime - 10ms) {
101-
// Pop first timer from the queue and add it to list of timers ready
102-
// to fire
103-
auto next = strongThis->m_timerQueue.Front();
104-
strongThis->m_timerQueue.Pop();
105-
106-
// VSO:1916882 potential overflow
107-
readyTimers.push_back(next.Id);
108-
109-
// If timer is repeating push it back onto the queue for the next
110-
// repetition 'next.Period' being greater than 10ms is intended to
111-
// prevent infinite loops
112-
if (next.Repeat)
113-
strongThis->m_timerQueue.Push(Timer{next.Id, now_ms + next.Period, next.Period, true});
114-
}
115-
116-
if (!readyTimers.empty()) {
117-
if (auto instance = strongThis->m_wkInstance.lock()) {
118-
instance->callJSFunction("JSTimers", "callTimers", folly::dynamic::array(std::move(readyTimers)));
119-
} else {
120-
assert(false && "m_wkInstance.lock failed");
121-
}
122-
}
123-
124-
if (!strongThis->m_timerQueue.IsEmpty()) {
125-
strongThis->SetKernelTimer(strongThis->m_timerQueue.Front().DueTime);
126-
} else {
127-
strongThis->m_dueTime = DateTime::max();
128-
}
129-
});
130-
} else {
131-
assert(false && "m_nativeThread.lock failed");
132-
}
133-
}
134-
}
135-
136-
void TimingHelper::createTimer(
137-
std::weak_ptr<facebook::react::Instance> instance,
138-
uint64_t id,
139-
double duration,
140-
double jsSchedulingTime,
141-
bool repeat) noexcept {
142-
SetInstance(instance);
143-
auto now = std::chrono::system_clock::now();
144-
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
145-
146-
// Convert double duration to std::chrono::duration
147-
auto period = TimeSpan{(int64_t)duration};
148-
// Convert int64_t scheduletime to std::chrono::time_point
149-
DateTime scheduledTime = DateTime(TimeSpan((int64_t)jsSchedulingTime));
150-
// Calculate the initial due time -- scheduleTime plus duration
151-
auto initialDueTime = scheduledTime + period;
152-
153-
if (scheduledTime + period <= now_ms && !repeat) {
154-
if (auto inst = m_wkInstance.lock()) {
155-
inst->callJSFunction("JSTimers", "callTimers", folly::dynamic::array(folly::dynamic::array(id)));
156-
} else {
157-
assert(false && "m_wkInstance.lock failed");
158-
}
159-
return;
160-
}
161-
162-
// Make sure duration is always larger than 16ms to avoid unnecessary wakeups.
163-
period = TimeSpan{duration < 16 ? 16 : (int64_t)duration};
164-
m_timerQueue.Push(Timer{id, initialDueTime, period, repeat});
165-
166-
TimersChanged();
167-
}
168-
169-
void TimingHelper::TimersChanged() noexcept {
170-
if (m_timerQueue.IsEmpty()) {
171-
// TimerQueue is empty.
172-
// Stop the kernel timer only when it is about to fire
173-
if (KernelTimerIsAboutToFire()) {
174-
StopKernelTimer();
175-
}
176-
return;
177-
}
178-
// If front timer has the same target time as ThreadpoolTimer,
179-
// we will keep ThreadpoolTimer unchanged.
180-
if (m_timerQueue.Front().DueTime == m_dueTime) {
181-
// do nothing
182-
}
183-
// If current front timer's due time is earlier than current
184-
// ThreadpoolTimer's, we need to reset the ThreadpoolTimer to current front
185-
// timer
186-
else if (m_timerQueue.Front().DueTime < m_dueTime) {
187-
SetKernelTimer(m_timerQueue.Front().DueTime);
188-
}
189-
// If current front timer's due time is later than current kernel timer's,
190-
// we will reset kernel timer only when it is about to fire
191-
else if (KernelTimerIsAboutToFire()) {
192-
SetKernelTimer(m_timerQueue.Front().DueTime);
193-
}
194-
}
195-
196-
bool TimingHelper::KernelTimerIsAboutToFire() noexcept {
197-
// Here we assume if kernel timer is going to fire within 2 frames (about
198-
// 33ms), we return true I am not sure the 2 frames assumption is good enough.
199-
// We may need adjustment after performance analysis.
200-
auto now = std::chrono::system_clock::now();
201-
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
202-
if (m_dueTime - now_ms <= 33ms)
203-
return true;
204-
return false;
205-
}
206-
207-
void TimingHelper::SetInstance(std::weak_ptr<facebook::react::Instance> instance) noexcept {
208-
if (m_wkInstance.expired())
209-
m_wkInstance = instance;
210-
}
211-
212-
void TimingHelper::SetKernelTimer(DateTime dueTime) noexcept {
213-
m_dueTime = dueTime;
214-
FILETIME FileDueTime;
215-
ULARGE_INTEGER ulDueTime;
216-
auto now = std::chrono::system_clock::now();
217-
auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(now);
218-
TimeSpan period = dueTime - now_ms;
219-
ulDueTime.QuadPart = (ULONGLONG) - (period.count() * 10000);
220-
FileDueTime.dwHighDateTime = ulDueTime.HighPart;
221-
FileDueTime.dwLowDateTime = ulDueTime.LowPart;
222-
223-
if (!m_threadpoolTimer) {
224-
InitializeKernelTimer();
225-
}
226-
227-
SetThreadpoolTimer(m_threadpoolTimer, &FileDueTime, 0, 0);
228-
}
229-
230-
void TimingHelper::InitializeKernelTimer() noexcept {
231-
// Create ThreadPoolTimer
232-
m_threadpoolTimer = CreateThreadpoolTimer(&TimingHelper::ThreadpoolTimerCallback, static_cast<PVOID>(this), NULL);
233-
assert(m_threadpoolTimer && "CreateThreadpoolTimer failed.");
234-
}
235-
236-
void TimingHelper::deleteTimer(uint64_t id) noexcept {
237-
if (m_timerQueue.IsEmpty())
238-
return;
239-
if (m_timerQueue.Remove(id)) {
240-
TimersChanged();
241-
}
242-
}
243-
244-
void TimingHelper::StopKernelTimer() noexcept {
245-
// Cancel pending callbacks
246-
SetThreadpoolTimer(m_threadpoolTimer, NULL, 0, 0);
247-
m_dueTime = DateTime::max();
248-
}
249-
250-
void TimingHelper::setSendIdleEvents(bool /*sendIdleEvents*/) noexcept {
251-
// It seems we don't need this API. Leave it empty for now.
252-
assert(false && "not implemented");
253-
}
254-
255-
TimingHelper::~TimingHelper() {
256-
if (m_threadpoolTimer) {
257-
StopKernelTimer();
258-
WaitForThreadpoolTimerCallbacks(m_threadpoolTimer, true);
259-
CloseThreadpoolTimer(m_threadpoolTimer);
260-
}
261-
}
262-
263-
//==============================================================================
264-
// TimingModule
265-
//==============================================================================
266-
267-
TimingModule::TimingModule(std::shared_ptr<TimingHelper> &&timing) : m_timing(std::move(timing)) {}
268-
269-
std::string TimingModule::getName() {
270-
return "Timing";
271-
}
272-
273-
std::map<std::string, dynamic> TimingModule::getConstants() noexcept {
274-
return {};
275-
}
276-
277-
std::vector<module::CxxModule::Method> TimingModule::getMethods() noexcept {
278-
return {
279-
Method(
280-
"createTimer",
281-
[this](dynamic args) // int64_t id, int64_t duration, double
282-
// jsSchedulingTime, bool repeat
283-
{
284-
m_timing->createTimer(
285-
getInstance(),
286-
jsArgAsInt(args, 0),
287-
jsArgAsDouble(args, 1),
288-
jsArgAsDouble(args, 2),
289-
jsArgAsBool(args, 3));
290-
}),
291-
Method(
292-
"deleteTimer",
293-
[this](dynamic args) // int64_t code, const std::string& reason,
294-
// int64_t id
295-
{ m_timing->deleteTimer(jsArgAsInt(args, 0)); }),
296-
Method(
297-
"setSendIdleEvents",
298-
[this](dynamic args) // const std::string& message, int64_t id
299-
{ m_timing->setSendIdleEvents(jsArgAsBool(args, 0)); }),
300-
};
301-
}
302-
303-
std::unique_ptr<facebook::xplat::module::CxxModule> CreateTimingModule(
304-
const std::shared_ptr<facebook::react::MessageQueueThread> &nativeThread) noexcept {
305-
auto module = std::make_unique<TimingModule>(std::make_shared<TimingHelper>(nativeThread));
306-
return std::move(module);
307-
}
308-
30971
//==============================================================================
31072
// Timing
31173
//==============================================================================

vnext/Desktop/Modules/DesktopTimingModule.h

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <InstanceManager.h>
99
#include <NativeModules.h>
10-
#include <cxxreact/CxxModule.h>
1110
#include <cxxreact/MessageQueueThread.h>
1211

1312
#include <chrono>
@@ -63,60 +62,6 @@ class TimerQueue {
6362
std::vector<Timer> m_timerVector;
6463
};
6564

66-
// Helper class which implements createTimer, deleteTimer and setSendIdleEvents
67-
// for actual TimingModule Example:
68-
// Timing timing;
69-
// timing.createTimer(instance, id, duration, jsScheduleTime, repeat);
70-
// timing.delete(id);
71-
class TimingHelper : public std::enable_shared_from_this<TimingHelper> {
72-
public:
73-
TimingHelper(const std::shared_ptr<facebook::react::MessageQueueThread> &nativeThread)
74-
: m_nativeThread(nativeThread) {}
75-
~TimingHelper();
76-
void createTimer(
77-
std::weak_ptr<facebook::react::Instance> instance,
78-
uint64_t id,
79-
double duration,
80-
double jsSchedulingTime,
81-
bool repeat) noexcept;
82-
void deleteTimer(uint64_t id) noexcept;
83-
void setSendIdleEvents(bool sendIdleEvents) noexcept;
84-
85-
private:
86-
static VOID CALLBACK
87-
ThreadpoolTimerCallback(PTP_CALLBACK_INSTANCE Instance, PVOID Parameter, PTP_TIMER Timer) noexcept;
88-
void OnTimerRaised() noexcept;
89-
void SetInstance(std::weak_ptr<facebook::react::Instance> instance) noexcept;
90-
void SetKernelTimer(DateTime dueTime) noexcept;
91-
void InitializeKernelTimer() noexcept;
92-
void TimersChanged() noexcept;
93-
void StopKernelTimer() noexcept;
94-
bool KernelTimerIsAboutToFire() noexcept;
95-
TimerQueue m_timerQueue;
96-
PTP_TIMER m_threadpoolTimer = NULL;
97-
DateTime m_dueTime;
98-
99-
std::weak_ptr<facebook::react::Instance> m_wkInstance;
100-
std::weak_ptr<facebook::react::MessageQueueThread> m_nativeThread;
101-
};
102-
103-
// Native timing module class. It communicates with JS side to manage timers.
104-
// Example:
105-
// // On JS side
106-
// const {Timing} = require('NativeModules');
107-
// Timing.createTimer(id, duration || 0, Date.now(), /* recurring */
108-
// false); Timing.deleteTimer(timerID);
109-
class TimingModule : public facebook::xplat::module::CxxModule {
110-
public:
111-
TimingModule(std::shared_ptr<TimingHelper> &&timing);
112-
std::string getName() override;
113-
virtual std::map<std::string, folly::dynamic> getConstants() noexcept override;
114-
virtual std::vector<Method> getMethods() noexcept override;
115-
116-
private:
117-
std::shared_ptr<TimingHelper> m_timing;
118-
};
119-
12065
REACT_MODULE(Timing)
12166
struct Timing : public std::enable_shared_from_this<Timing> {
12267
~Timing();

vnext/Microsoft.ReactNative/Modules/Animated/NativeAnimatedNodeManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <IReactInstance.h>
88
#include <UI.Xaml.Media.h>
9-
#include <cxxreact/CxxModule.h>
10-
#include <folly/dynamic.h>
119
#include "AnimatedNode.h"
1210
#include "AnimationDriver.h"
1311
#include "EventAnimationDriver.h"

vnext/Microsoft.ReactNative/Modules/AppThemeModuleUwp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <Utils/ValueUtils.h>
1414
#include <XamlUIService.h>
1515
#include <XamlUtils.h>
16-
#include <cxxreact/CxxModule.h>
1716
#include <functional>
1817
#include <memory>
1918
#if _MSC_VER <= 1913

vnext/Microsoft.ReactNative/Modules/CreateModules.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include <React.h>
88
#include <ReactPropertyBag.h>
99

10-
// React Native
11-
#include <cxxreact/CxxModule.h>
12-
1310
// Windows API
1411
#include <winrt/Windows.Security.Cryptography.Certificates.h>
1512

0 commit comments

Comments
 (0)