-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add InspectorFlags, conditionally disable Hermes CDP registration (#4…
…1672) Summary: Pull Request resolved: #41672 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 legacy ~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] Reviewed By: motiz88 Differential Revision: D51563107 fbshipit-source-id: 446f319228ec627fdc0ecba9517a1a3faad9d262
- Loading branch information
1 parent
1727ffa
commit b6adbf7
Showing
9 changed files
with
191 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/react-native/ReactCommon/jsinspector-modern/InspectorFlags.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <glog/logging.h> | ||
#include <cassert> | ||
|
||
#include "InspectorFlags.h" | ||
|
||
namespace facebook::react::jsinspector_modern { | ||
|
||
InspectorFlags& InspectorFlags::getInstance() { | ||
static InspectorFlags instance; | ||
return instance; | ||
} | ||
|
||
void InspectorFlags::initFromConfig( | ||
const ReactNativeConfig& reactNativeConfig) { | ||
bool enableModernCDPRegistry = | ||
reactNativeConfig.getBool("react_native_devx:enable_modern_cdp_registry"); | ||
if (enableModernCDPRegistry_.has_value()) { | ||
assert( | ||
*enableModernCDPRegistry_ == enableModernCDPRegistry && | ||
"Flag value was changed after init"); | ||
} | ||
enableModernCDPRegistry_ = enableModernCDPRegistry; | ||
} | ||
|
||
bool InspectorFlags::getEnableModernCDPRegistry() const { | ||
if (!enableModernCDPRegistry_.has_value()) { | ||
LOG(WARNING) | ||
<< "InspectorFlags::getEnableModernCDPRegistry was called before init"; | ||
} | ||
return enableModernCDPRegistry_.value_or(false); | ||
} | ||
|
||
} // namespace facebook::react::jsinspector_modern |
45 changes: 45 additions & 0 deletions
45
packages/react-native/ReactCommon/jsinspector-modern/InspectorFlags.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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 | ||
|
||
#include <optional> | ||
|
||
#include <react/config/ReactNativeConfig.h> | ||
|
||
namespace facebook::react::jsinspector_modern { | ||
|
||
/** | ||
* A container for all inspector related feature flags (Meyers singleton | ||
* pattern). Flags must be set before they are accessed and are static for the | ||
* lifetime of the app. | ||
*/ | ||
class InspectorFlags { | ||
public: | ||
static InspectorFlags& getInstance(); | ||
|
||
/** | ||
* Initialize flags from a `ReactNativeConfig` instance. Validates that flag | ||
* values are not changed across multiple calls. | ||
*/ | ||
void initFromConfig(const ReactNativeConfig& reactNativeConfig); | ||
|
||
/** | ||
* Flag determining if the modern CDP backend should be enabled. | ||
*/ | ||
bool getEnableModernCDPRegistry() const; | ||
|
||
private: | ||
InspectorFlags() = default; | ||
InspectorFlags(const InspectorFlags&) = delete; | ||
InspectorFlags& operator=(const InspectorFlags&) = delete; | ||
~InspectorFlags() = default; | ||
|
||
std::optional<bool> enableModernCDPRegistry_; | ||
}; | ||
|
||
} // namespace facebook::react::jsinspector_modern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.