mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
51af7cdcde
Summary: changelog: [internal] Enable two new clang tidy checks: - modernize-concat-nested-namespaces - google-build-using-namespace jest_e2e[run_all_tests] Reviewed By: rshest Differential Revision: D40020646 fbshipit-source-id: f3be80b5f829dd0ba376bdd70ed13332e114d48a
104 lines
2.6 KiB
C++
104 lines
2.6 KiB
C++
/*
|
|
* 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 "RawProps.h"
|
|
|
|
#include <react/debug/react_native_assert.h>
|
|
#include <react/renderer/core/RawPropsKey.h>
|
|
#include <react/renderer/core/RawPropsParser.h>
|
|
|
|
namespace facebook::react {
|
|
|
|
RawProps::RawProps() {
|
|
mode_ = Mode::Empty;
|
|
}
|
|
|
|
/*
|
|
* Creates an object with given `runtime` and `value`.
|
|
*/
|
|
RawProps::RawProps(jsi::Runtime &runtime, jsi::Value const &value) noexcept {
|
|
if (value.isNull()) {
|
|
mode_ = Mode::Empty;
|
|
return;
|
|
}
|
|
|
|
mode_ = mode_ = Mode::JSI;
|
|
runtime_ = &runtime;
|
|
value_ = jsi::Value(runtime, value);
|
|
}
|
|
|
|
/*
|
|
* Creates an object with given `folly::dynamic` object.
|
|
* Deprecated. Do not use.
|
|
* We need this temporary, only because we have a callsite that does not have
|
|
* a `jsi::Runtime` behind the data.
|
|
*/
|
|
RawProps::RawProps(folly::dynamic const &dynamic) noexcept {
|
|
if (dynamic.isNull()) {
|
|
mode_ = Mode::Empty;
|
|
return;
|
|
}
|
|
|
|
mode_ = Mode::Dynamic;
|
|
dynamic_ = dynamic;
|
|
}
|
|
|
|
void RawProps::parse(
|
|
RawPropsParser const &parser,
|
|
const PropsParserContext & /*unused*/) const noexcept {
|
|
react_native_assert(parser_ == nullptr && "A parser was already assigned.");
|
|
parser_ = &parser;
|
|
parser.preparse(*this);
|
|
}
|
|
|
|
/*
|
|
* Deprecated. Do not use.
|
|
* The support for explicit conversion to `folly::dynamic` is deprecated and
|
|
* will be removed as soon Android implementation does not need it.
|
|
*/
|
|
RawProps::operator folly::dynamic() const noexcept {
|
|
switch (mode_) {
|
|
case Mode::Empty:
|
|
return folly::dynamic::object();
|
|
case Mode::JSI:
|
|
return jsi::dynamicFromValue(*runtime_, value_);
|
|
case Mode::Dynamic:
|
|
return dynamic_;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Returns `true` if the object is empty.
|
|
* Empty `RawProps` does not have any stored data.
|
|
*/
|
|
bool RawProps::isEmpty() const noexcept {
|
|
return mode_ == Mode::Empty;
|
|
}
|
|
|
|
/*
|
|
* Returns a const unowning pointer to `RawValue` of a prop with a given name.
|
|
* Returns `nullptr` if a prop with the given name does not exist.
|
|
*/
|
|
const RawValue *RawProps::at(
|
|
char const *name,
|
|
char const *prefix,
|
|
char const *suffix) const noexcept {
|
|
react_native_assert(
|
|
parser_ &&
|
|
"The object is not parsed. `parse` must be called before `at`.");
|
|
return parser_->at(*this, RawPropsKey{prefix, name, suffix});
|
|
}
|
|
|
|
void RawProps::iterateOverValues(
|
|
std::function<
|
|
void(RawPropsPropNameHash, const char *, RawValue const &)> const &fn)
|
|
const {
|
|
return parser_->iterateOverValues(*this, fn);
|
|
}
|
|
|
|
} // namespace facebook::react
|