first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
# 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.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
include(${REACT_ANDROID_DIR}/src/main/jni/first-party/jni-lib-merge/SoMerging-utils.cmake)
add_compile_options(
-fexceptions
-std=c++20
-Wall
-Wpedantic)
file(GLOB jsinspector_cdp_SRC CONFIGURE_DEPENDS *.cpp)
add_library(jsinspector_cdp OBJECT ${jsinspector_cdp_SRC})
target_merge_so(jsinspector_cdp)
target_include_directories(jsinspector_cdp PUBLIC ${REACT_COMMON_DIR})
target_link_libraries(jsinspector_cdp
folly_runtime
)

View File

@@ -0,0 +1,72 @@
/*
* 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 "CdpJson.h"
#include <folly/dynamic.h>
#include <folly/json.h>
namespace facebook::react::jsinspector_modern::cdp {
PreparsedRequest preparse(std::string_view message) {
folly::dynamic parsed = folly::parseJson(message);
return PreparsedRequest{
.id = parsed["id"].getInt(),
.method = parsed["method"].getString(),
.params = parsed.count("params") != 0u ? parsed["params"] : nullptr};
}
std::string PreparsedRequest::toJson() const {
folly::dynamic obj = folly::dynamic::object;
obj["id"] = id;
obj["method"] = method;
if (params != nullptr) {
obj["params"] = params;
}
return folly::toJson(obj);
}
std::string jsonError(
std::optional<RequestId> id,
ErrorCode code,
std::optional<std::string> message) {
auto dynamicError = folly::dynamic::object("code", static_cast<int>(code));
if (message) {
dynamicError("message", *message);
}
return folly::toJson(
(id ? folly::dynamic::object("id", *id)
: folly::dynamic::object("id", nullptr))(
"error", std::move(dynamicError)));
}
std::string jsonResult(RequestId id, const folly::dynamic& result) {
return folly::toJson(folly::dynamic::object("id", id)("result", result));
}
std::string jsonNotification(
const std::string& method,
std::optional<folly::dynamic> params) {
auto dynamicNotification = folly::dynamic::object("method", method);
if (params) {
dynamicNotification("params", *params);
}
return folly::toJson(std::move(dynamicNotification));
}
std::string jsonRequest(
RequestId id,
const std::string& method,
std::optional<folly::dynamic> params) {
auto dynamicRequest = folly::dynamic::object("id", id)("method", method);
if (params) {
dynamicRequest("params", *params);
}
return folly::toJson(std::move(dynamicRequest));
}
} // namespace facebook::react::jsinspector_modern::cdp

View File

@@ -0,0 +1,129 @@
/*
* 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 <folly/dynamic.h>
#include <folly/json.h>
#include <string>
#include <string_view>
namespace facebook::react::jsinspector_modern::cdp {
using RequestId = long long;
/**
* Error codes to be used in CDP responses.
* https://www.jsonrpc.org/specification#error_object
*/
enum class ErrorCode {
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603
/* -32000 to -32099: Implementation-defined server errors. */
};
/**
* An incoming CDP request that has been parsed into a more usable form.
*/
struct PreparsedRequest {
public:
/**
* The ID of the request.
*/
RequestId id{};
/**
* The name of the method being invoked.
*/
std::string method;
/**
* The parameters passed to the method, if any.
*/
folly::dynamic params;
/**
* Equality operator, useful for unit tests
*/
inline bool operator==(const PreparsedRequest &rhs) const
{
return id == rhs.id && method == rhs.method && params == rhs.params;
}
std::string toJson() const;
};
/**
* Parse a JSON-encoded CDP request into its constituent parts.
* \throws ParseError If the input cannot be parsed.
* \throws TypeError If the input does not conform to the expected format.
*/
PreparsedRequest preparse(std::string_view message);
/**
* A type error that may be thrown while preparsing a request, or while
* accessing dynamic params on a request.
*/
using TypeError = folly::TypeError;
/**
* A parse error that may be thrown while preparsing a request.
*/
using ParseError = folly::json::parse_error;
/**
* Helper functions for creating CDP (loosely JSON-RPC) messages of various
* types, returning a JSON string ready for sending over the wire.
*/
/**
* Returns a JSON-formatted string representing an error.
*
* {"id": <id>, "error": { "code": <cdp error code>, "message": <message> }}
*
* \param id Request ID. Mandatory, null only if the request omitted it or
* could not be parsed.
* \param code Integer code from cdp::ErrorCode.
* \param message Optional, brief human-readable error message.
*/
std::string jsonError(std::optional<RequestId> id, ErrorCode code, std::optional<std::string> message = std::nullopt);
/**
* Returns a JSON-formatted string representing a successful response.
*
* {"id": <id>, "result": <result>}
*
* \param id The id of the request that this response corresponds to.
* \param result Result payload, defaulting to {}.
*/
std::string jsonResult(RequestId id, const folly::dynamic &result = folly::dynamic::object());
/**
* Returns a JSON-formatted string representing a unilateral notification.
*
* {"method": <method>, "params": <params>}
*
* \param method Notification (aka "event") method.
* \param params Optional payload object.
*/
std::string jsonNotification(const std::string &method, std::optional<folly::dynamic> params = std::nullopt);
/**
* Returns a JSON-formatted string representing a request.
*
* {"id": <id>, "method": <method>, "params": <params>}
*
* \param id Request ID.
* \param method Requested method.
* \param params Optional payload object.
*/
std::string jsonRequest(RequestId id, const std::string &method, std::optional<folly::dynamic> params = std::nullopt);
} // namespace facebook::react::jsinspector_modern::cdp

View File

@@ -0,0 +1,48 @@
# 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.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
header_search_paths = []
if ENV['USE_FRAMEWORKS']
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../..\""
end
header_dir = 'jsinspector-modern/cdp'
module_name = "jsinspector_moderncdp"
Pod::Spec.new do |s|
s.name = "React-jsinspectorcdp"
s.version = version
s.summary = "Common helper functions for working with CDP messages in jsinspector-modern"
s.homepage = "https://reactnative.dev/"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.source = source
s.source_files = podspec_sources("*.{cpp,h}", "*.h")
s.header_dir = header_dir
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"DEFINES_MODULE" => "YES"}
resolve_use_frameworks(s, header_mappings_dir: "../..", module_name: module_name)
add_rn_third_party_dependencies(s)
add_rncore_dependency(s)
end