Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix outstanding modern debugger issues",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
73 changes: 73 additions & 0 deletions vnext/Desktop.UnitTests/UtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,79 @@ TEST_CLASS(UtilsTest)
}

#pragma endregion Base64 Tests

#pragma region string_format Tests

TEST_METHOD(UtilsTest_StringFormat_Simple)
{
auto result = Microsoft::React::string_format("Hello, %s!", "World");
Assert::AreEqual("Hello, World!", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_Integer)
{
auto result = Microsoft::React::string_format("Port: %d", 8081);
Assert::AreEqual("Port: 8081", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_Multiple)
{
auto result = Microsoft::React::string_format("%s:%d", "localhost", 8081);
Assert::AreEqual("localhost:8081", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_Complex)
{
auto result = Microsoft::React::string_format(
"http://%s/%s.bundle?platform=%s&dev=%s&hot=%s",
"localhost:8081",
"index",
"windows",
"true",
"false");
Assert::AreEqual(
"http://localhost:8081/index.bundle?platform=windows&dev=true&hot=false",
result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_EmptyString)
{
auto result = Microsoft::React::string_format("");
Assert::AreEqual("", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_NoArgs)
{
auto result = Microsoft::React::string_format("no args here");
Assert::AreEqual("no args here", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_LargeString)
{
std::string longString(1000, 'a');
auto result = Microsoft::React::string_format("%s", longString.c_str());
Assert::AreEqual(longString.c_str(), result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_MixedTypes)
{
auto result = Microsoft::React::string_format(
"Int: %d, Uint: %u, Hex: %x, String: %s, Float: %.2f",
-42,
42u,
255,
"test",
3.14159);
Assert::AreEqual("Int: -42, Uint: 42, Hex: ff, String: test, Float: 3.14", result.c_str());
}

TEST_METHOD(UtilsTest_StringFormat_SpecialChars)
{
auto result = Microsoft::React::string_format("100%% complete");
Assert::AreEqual("100% complete", result.c_str());
}

#pragma endregion string_format Tests
};

// clang-format on
Expand Down
4 changes: 0 additions & 4 deletions vnext/Microsoft.ReactNative/IReactDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ void ReactDispatcher::InvokeElsePost(Mso::DispatchTask &&task) const noexcept {
return jsThreadDispatcherProperty;
}

/*static*/ IReactDispatcher ReactDispatcher::GetJSDispatcher(IReactPropertyBag const &properties) noexcept {
return properties.Get(JSDispatcherProperty()).try_as<IReactDispatcher>();
}

/*static*/ IReactPropertyName ReactDispatcher::JSDispatcherTaskStartingEventName() noexcept {
static IReactPropertyName jsThreadDispatcherProperty{ReactPropertyBagHelper::GetName(
ReactPropertyBagHelper::GetNamespace(L"ReactNative.Dispatcher"), L"JSDispatcherTaskStartingEventName")};
Expand Down
1 change: 0 additions & 1 deletion vnext/Microsoft.ReactNative/IReactDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct ReactDispatcher : implements<ReactDispatcher, IReactDispatcher, Mso::Reac
static void SetUIThreadDispatcher(IReactPropertyBag const &properties) noexcept;

static IReactPropertyName JSDispatcherProperty() noexcept;
static IReactDispatcher GetJSDispatcher(IReactPropertyBag const &properties) noexcept;
static IReactPropertyName JSDispatcherTaskStartingEventName() noexcept;
static IReactPropertyName JSDispatcherIdleWaitStartingEventName() noexcept;
static IReactPropertyName JSDispatcherIdleWaitCompletedEventName() noexcept;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ ReactInstanceWin::ReactInstanceWin(
propBag = m_options.Properties,
reactContext = m_reactContext]() noexcept {
whenLoaded.TryCancel(); // It only has an effect if whenLoaded was not set before
Microsoft::ReactNative::HermesRuntimeHolder::storeTo(ReactPropertyBag(reactContext->Properties()), nullptr);
if (onDestroyed) {
onDestroyed.Get()->Invoke(reactContext);
}
Expand Down
26 changes: 0 additions & 26 deletions vnext/Microsoft.ReactNative/Views/DevMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "DevMenu.h"

#include <winrt/Windows.ApplicationModel.DataTransfer.h>
#include "Hermes/HermesSamplingProfiler.h"
#include "IReactDispatcher.h"
#include "Modules/DevSettingsModule.h"

Expand Down Expand Up @@ -68,30 +67,11 @@ void ToggleFastRefresh(Mso::CntPtr<Mso::React::IReactContext> const &reactContex
DevSettings::Reload(React::ReactPropertyBag(reactContext->Properties()));
}

winrt::fire_and_forget ToggleHermesProfiler(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
if (!Microsoft::ReactNative::HermesSamplingProfiler::IsStarted()) {
Microsoft::ReactNative::HermesSamplingProfiler::Start(reactContext);
} else {
auto traceFilePath = co_await Microsoft::ReactNative::HermesSamplingProfiler::Stop(reactContext);
auto uiDispatcher = React::implementation::ReactDispatcher::GetUIDispatcher(reactContext->Properties());
uiDispatcher.Post([traceFilePath]() {
DataTransfer::DataPackage data;
data.SetText(winrt::to_hstring(traceFilePath));
DataTransfer::Clipboard::SetContentWithOptions(data, nullptr);
});
}
}

const wchar_t *FastRefreshLabel(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
return Mso::React::ReactOptions::UseFastRefresh(reactContext->Properties()) ? L"Disable Fast Refresh"
: L"Enable Fast Refresh";
}

const wchar_t *HermesProfilerLabel(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) noexcept {
return !Microsoft::ReactNative::HermesSamplingProfiler::IsStarted() ? L"Start Hermes sampling profiler"
: L"Stop and copy trace path to clipboard";
}

struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from_this<WindowsPopupMenuDevMenu> {
WindowsPopupMenuDevMenu(Mso::CntPtr<Mso::React::IReactContext> const &reactContext) : m_context(reactContext) {}

Expand Down Expand Up @@ -127,12 +107,6 @@ struct WindowsPopupMenuDevMenu : public IDevMenu, public std::enable_shared_from
DevSettings::ToggleElementInspector(*context);
}));

if (Mso::React::ReactOptions::JsiEngine(m_context->Properties()) == Mso::React::JSIEngine::Hermes) {
m_menu.Commands().Append(winrt::Windows::UI::Popups::UICommand(
HermesProfilerLabel(m_context),
[context = m_context](winrt::Windows::UI::Popups::IUICommand const &) { ToggleHermesProfiler(context); }));
}

m_menu.ShowAsync({0, 0});
}

Expand Down
36 changes: 16 additions & 20 deletions vnext/Shared/DevServerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <cxxreact/JSExecutor.h>
#include "Utils.h"

namespace facebook {
namespace react {
Expand All @@ -13,13 +14,14 @@ class DevServerHelper {
DevServerHelper() = default;

static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return string_format(WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
return Microsoft::React::string_format(
WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}

static std::string get_LaunchDevToolsCommandUrl(
const std::string &sourceBundleHost,
const uint16_t sourceBundlePort) {
return string_format(
return Microsoft::React::string_format(
LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}

Expand All @@ -36,16 +38,17 @@ class DevServerHelper {
std::string hermesBytecodeVersionQuery;
if (hermesBytecodeVersion > 0) {
static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d";
hermesBytecodeVersionQuery = string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
hermesBytecodeVersionQuery =
Microsoft::React::string_format(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
}

std::string appIdQuery;
if (bundleAppId.size() > 0) {
static constexpr const char AppIdQueryFormat[] = "&app=%s";
appIdQuery = string_format(AppIdQueryFormat, bundleAppId.c_str());
appIdQuery = Microsoft::React::string_format(AppIdQueryFormat, bundleAppId.c_str());
}

return string_format(
return Microsoft::React::string_format(
BundleUrlFormat,
GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str(),
jsbundle.c_str(),
Expand All @@ -58,17 +61,19 @@ class DevServerHelper {
}

static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return string_format(OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
return Microsoft::React::string_format(
OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}

static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return string_format(PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
return Microsoft::React::string_format(
PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}

static std::string get_PackagerOpenStackFrameUrl(
const std::string &sourceBundleHost,
const uint16_t sourceBundlePort) {
return string_format(
return Microsoft::React::string_format(
PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}

Expand All @@ -78,7 +83,7 @@ class DevServerHelper {
const std::string &deviceName,
const std::string &packageName,
const std::string &deviceId) {
return string_format(
return Microsoft::React::string_format(
InspectorDeviceUrlFormat,
GetDeviceLocalHost(packagerHost, packagerPort).c_str(),
deviceName.c_str(),
Expand All @@ -88,7 +93,7 @@ class DevServerHelper {

static std::string
get_OpenDebuggerUrl(const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) {
return string_format(
return Microsoft::React::string_format(
OpenDebuggerUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceId.c_str());
}

Expand All @@ -97,7 +102,7 @@ class DevServerHelper {

private:
static std::string GetDeviceLocalHost(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return string_format(
return Microsoft::React::string_format(
DeviceLocalHostFormat,
sourceBundleHost.empty() ? DefaultPackagerHost : sourceBundleHost.c_str(),
sourceBundlePort ? sourceBundlePort : DefaultPackagerPort);
Expand All @@ -118,15 +123,6 @@ class DevServerHelper {

static constexpr const char PackagerOkStatus[] = "packager-status:running";
const int LongPollFailureDelayMs = 5000;

// TODO: [vmoroz] avoid using vaiadic args for the format and move it to a utility class.
template <typename... Args>
static std::string string_format(const char *format, Args... args) {
size_t size = snprintf(nullptr, 0, format, args...) + 1;
std::unique_ptr<char[]> buf(new char[size]);
snprintf(buf.get(), size, format, args...);
return std::string(buf.get(), buf.get() + size - 1);
}
};

} // namespace react
Expand Down
16 changes: 0 additions & 16 deletions vnext/Shared/DevSupportManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,6 @@ void DevSupportManager::StopPollingLiveReload() {
m_cancellation_token = true;
}

// TODO: (vmoroz) Use or delete this function
void DevSupportManager::OpenDevTools(const std::string &bundleAppId) {
winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter filter;
filter.CacheControl().ReadBehavior(winrt::Windows::Web::Http::Filters::HttpCacheReadBehavior::NoCache);
winrt::Windows::Web::Http::HttpClient httpClient(filter);
// TODO: Use currently configured dev server host
winrt::Windows::Foundation::Uri uri(
Microsoft::Common::Unicode::Utf8ToUtf16(facebook::react::DevServerHelper::get_OpenDebuggerUrl(
std::string{DevServerHelper::DefaultPackagerHost},
DevServerHelper::DefaultPackagerPort,
GetDeviceId(GetPackageName(bundleAppId)))));

winrt::Windows::Web::Http::HttpRequestMessage request(winrt::Windows::Web::Http::HttpMethod::Post(), uri);
httpClient.SendRequestAsync(request);
}

void DevSupportManager::EnsureInspectorPackagerConnection(
[[maybe_unused]] const std::string &packagerHost,
[[maybe_unused]] const uint16_t packagerPort,
Expand Down
1 change: 0 additions & 1 deletion vnext/Shared/DevSupportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class DevSupportManager final : public facebook::react::IDevSupportManager {
const uint16_t sourceBundlePort,
std::function<void()> onChangeCallback) override;
virtual void StopPollingLiveReload() override;
virtual void OpenDevTools(const std::string &bundleAppId) override;

virtual void EnsureInspectorPackagerConnection(
const std::string &packagerHost,
Expand Down
6 changes: 5 additions & 1 deletion vnext/Shared/Hermes/HermesRuntimeTargetDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "HermesRuntimeTargetDelegate.h"
#include <jsinspector-modern/RuntimeTarget.h>
#include <windows.h>
#include <utility>
#include "HermesRuntimeAgentDelegate.h"

Expand Down Expand Up @@ -268,7 +269,10 @@ tracing::RuntimeSamplingProfile HermesRuntimeTargetDelegate::collectSamplingProf

// Return the complete profile with samples. Wrap the raw profile since it owns the strings.
return tracing::RuntimeSamplingProfile(
"Hermes", 1234, std::move(readerState.samples), std::make_unique<HermesRawRuntimeProfile>(std::move(profile)));
"Hermes",
GetCurrentProcessId(),
std::move(readerState.samples),
std::make_unique<HermesRawRuntimeProfile>(std::move(profile)));
}

} // namespace Microsoft::ReactNative
Loading
Loading