guardia-messenger/node_modules/react-native/ReactCommon/jsinspector-modern/RuntimeTarget.cpp
DESKTOP-TKLFCPRython f29f525c77 refactor: 101.79.17.164 → zioinfo.co.kr 전체 도메인 변환 + Manager UI 배포
- 37개 파일 IP → zioinfo.co.kr 치환 (소스/매뉴얼/설정/하네스)
- Manager DrConsole/NetworkConsole/CsapConsole 빌드 + /var/www/manager/ 배포
- 테스트: Manager HTTP 200, ITSM 신규 API 7개 전체 200

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 10:09:17 +09:00

110 lines
3.7 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 "SessionState.h"
#include <jsinspector-modern/RuntimeTarget.h>
using namespace facebook::jsi;
namespace facebook::react::jsinspector_modern {
std::shared_ptr<RuntimeTarget> RuntimeTarget::create(
const ExecutionContextDescription& executionContextDescription,
RuntimeTargetDelegate& delegate,
RuntimeExecutor jsExecutor,
VoidExecutor selfExecutor) {
std::shared_ptr<RuntimeTarget> runtimeTarget{
new RuntimeTarget(executionContextDescription, delegate, jsExecutor)};
runtimeTarget->setExecutor(selfExecutor);
return runtimeTarget;
}
RuntimeTarget::RuntimeTarget(
const ExecutionContextDescription& executionContextDescription,
RuntimeTargetDelegate& delegate,
RuntimeExecutor jsExecutor)
: executionContextDescription_(executionContextDescription),
delegate_(delegate),
jsExecutor_(jsExecutor) {}
std::shared_ptr<RuntimeAgent> RuntimeTarget::createAgent(
FrontendChannel channel,
SessionState& sessionState) {
auto runtimeAgentState =
std::move(sessionState.lastRuntimeAgentExportedState);
auto runtimeAgent = std::make_shared<RuntimeAgent>(
channel,
controller_,
executionContextDescription_,
sessionState,
delegate_.createAgentDelegate(
channel,
sessionState,
std::move(runtimeAgentState.delegateState),
executionContextDescription_));
agents_.insert(runtimeAgent);
return runtimeAgent;
}
RuntimeTarget::~RuntimeTarget() {
// Agents are owned by the session, not by RuntimeTarget, but
// they hold a RuntimeTarget& that we must guarantee is valid.
assert(
agents_.empty() &&
"RuntimeAgent objects must be destroyed before their RuntimeTarget. Did you call InstanceTarget::unregisterRuntime()?");
}
void RuntimeTarget::installBindingHandler(const std::string& bindingName) {
jsExecutor_([bindingName,
selfExecutor = executorFromThis()](jsi::Runtime& runtime) {
auto globalObj = runtime.global();
try {
auto bindingNamePropID = jsi::PropNameID::forUtf8(runtime, bindingName);
globalObj.setProperty(
runtime,
bindingNamePropID,
jsi::Function::createFromHostFunction(
runtime,
bindingNamePropID,
1,
[bindingName, selfExecutor](
jsi::Runtime& rt,
const jsi::Value&,
const jsi::Value* args,
size_t count) -> jsi::Value {
if (count != 1 || !args[0].isString()) {
throw jsi::JSError(
rt, "Invalid arguments: should be exactly one string.");
}
std::string payload = args[0].getString(rt).utf8(rt);
selfExecutor([bindingName, payload](auto& self) {
self.agents_.forEach([bindingName, payload](auto& agent) {
agent.notifyBindingCalled(bindingName, payload);
});
});
return jsi::Value::undefined();
}));
} catch (jsi::JSError&) {
// Per Chrome's implementation, @cdp Runtime.createBinding swallows
// JavaScript exceptions that occur while setting up the binding.
}
});
}
RuntimeTargetController::RuntimeTargetController(RuntimeTarget& target)
: target_(target) {}
void RuntimeTargetController::installBindingHandler(
const std::string& bindingName) {
target_.installBindingHandler(bindingName);
}
} // namespace facebook::react::jsinspector_modern