Skip to content

Commit

Permalink
Add InspectorFlags, conditionally disable Hermes CDP registration (fa…
Browse files Browse the repository at this point in the history
…cebook#41672)

Summary:

Progress towards an opt-in setup for our new CDP backend.

- Adds `InspectorFlags.h`, a singleton intended to allow convienient access to static boolean feature flags for the new CDP backend/inspector features across platforms. This will be written to in upcoming diffs, with the accessor for `enable_modern_cdp_registry` soft-defaulting to `false` here.
- References this to conditionally disable CDP registration in `HermesExecutorFactory` (Bridge) and `HermesInstance` (Bridgeless) code paths.
- Stubs a `false` value for `react_native_devx:enable_modern_cdp_registry` in `EmptyReactNativeConfig` (documentation/convenience point for open source partners and integrators).

Changelog: [Internal]

Differential Revision: D51563107
  • Loading branch information
huntie authored and facebook-github-bot committed Nov 29, 2023
1 parent 5476121 commit 7b7c9fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cxxreact/SystraceSection.h>
#include <hermes/hermes.h>
#include <jsi/decorator.h>
#include <jsinspector-modern/InspectorFlags.h>

#include <hermes/inspector-modern/chrome/Registration.h>
#include <hermes/inspector/RuntimeAdapter.h>
Expand Down Expand Up @@ -200,11 +201,14 @@ std::unique_ptr<JSExecutor> HermesExecutorFactory::createJSExecutor(
}

HermesRuntime& hermesRuntimeRef = *hermesRuntime;
bool enableDebugger =
!jsinspector_modern::InspectorFlags::enableModernCDPRegistry &&
enableDebugger_;
auto decoratedRuntime = std::make_shared<DecoratedRuntime>(
std::move(hermesRuntime),
hermesRuntimeRef,
jsQueue,
enableDebugger_,
enableDebugger,
debuggerName_);

// So what do we have now?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

namespace facebook::react::jsinspector_modern {

/**
* A container for all inspector related feature flags. These will be set
* externally prior to React Native initialization.
*/
class InspectorFlags {
public:
/**
* Primary flag to enable the modern CDP backend.
*/
static bool enableModernCDPRegistry;
};

} // namespace facebook::react::jsinspector_modern
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ Pod::Spec.new do |s|
s.source_files = "*.{cpp,h}"
s.header_dir = 'jsinspector'
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20" }

add_dependency(s, "React-nativeconfig")
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ bool EmptyReactNativeConfig::getBool(const std::string& param) const {
if (param == "react_fabric:enabled_layout_animations_ios") {
return true;
}
if (param == "react_native_devx:enable_modern_cdp_registry") {
return false;
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <hermes/inspector-modern/chrome/Registration.h>
#include <hermes/inspector/RuntimeAdapter.h>
#include <jsi/decorator.h>
#include <jsinspector-modern/InspectorFlags.h>
#endif

using namespace facebook::hermes;
Expand Down Expand Up @@ -141,10 +142,12 @@ std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
hermes::makeHermesRuntime(runtimeConfigBuilder.build());

#ifdef HERMES_ENABLE_DEBUGGER
std::unique_ptr<DecoratedRuntime> decoratedRuntime =
std::make_unique<DecoratedRuntime>(
std::move(hermesRuntime), msgQueueThread);
return std::make_unique<JSIRuntimeHolder>(std::move(decoratedRuntime));
if (!jsinspector_modern::InspectorFlags::enableModernCDPRegistry) {
std::unique_ptr<DecoratedRuntime> decoratedRuntime =
std::make_unique<DecoratedRuntime>(
std::move(hermesRuntime), msgQueueThread);
return std::make_unique<JSIRuntimeHolder>(std::move(decoratedRuntime));
}
#endif

return std::make_unique<JSIRuntimeHolder>(std::move(hermesRuntime));
Expand Down

0 comments on commit 7b7c9fa

Please sign in to comment.