Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions packages/react-native/Libraries/LogBox/Data/LogBoxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
Message,
} from './parseLogBoxLog';

import NativeDebuggerSessionObserver from '../../../src/private/specs/modules/NativeDebuggerSessionObserver';
import DebuggerSessionObserver from '../../../src/private/fusebox/FuseboxSessionObserver';
import parseErrorStack from '../../Core/Devtools/parseErrorStack';
import NativeDevSettings from '../../NativeModules/specs/NativeDevSettings';
import NativeLogBox from '../../NativeModules/specs/NativeLogBox';
Expand Down Expand Up @@ -198,29 +198,23 @@ function appendNewLog(newLog: LogBoxLog) {
}

export function addLog(log: LogData): void {
if (
hostTargetSessionObserverSubscription == null &&
NativeDebuggerSessionObserver != null
) {
hostTargetSessionObserverSubscription =
NativeDebuggerSessionObserver.subscribe(hasActiveSession => {
if (hostTargetSessionObserverSubscription == null) {
hostTargetSessionObserverSubscription = DebuggerSessionObserver.subscribe(
hasActiveSession => {
if (hasActiveSession) {
clearWarnings();
} else {
// Reset the flag so that we can show the message again if new warning was emitted
hasShownFuseboxWarningsMigrationMessage = false;
}
});
},
);
}

// If Host has Fusebox support
if (
log.level === 'warn' &&
global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__ &&
NativeDebuggerSessionObserver != null
) {
if (log.level === 'warn' && global.__FUSEBOX_HAS_FULL_CONSOLE_SUPPORT__) {
// And there is no active debugging session
if (!NativeDebuggerSessionObserver.hasActiveSession()) {
if (!DebuggerSessionObserver.hasActiveSession()) {
showFuseboxWarningsMigrationMessageOnce();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "HostTarget.h"
#include "CdpJson.h"
#include "HostAgent.h"
#include "HostTargetSessionObserver.h"
#include "InspectorInterfaces.h"
#include "InspectorUtilities.h"
#include "InstanceTarget.h"
Expand Down Expand Up @@ -44,13 +43,7 @@ class HostTargetSession {
targetController,
std::move(hostMetadata),
state_,
executor) {
HostTargetSessionObserver::getInstance().onHostTargetSessionCreated();
}

~HostTargetSession() {
HostTargetSessionObserver::getInstance().onHostTargetSessionDestroyed();
}
executor) {}

/**
* Called by CallbackLocalConnection to send a message to this Session's
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ RuntimeAgent::RuntimeAgent(
targetController_.installBindingHandler(name);
}
}

if (sessionState_.isRuntimeDomainEnabled &&
sessionState_.isLogDomainEnabled) {
targetController_.notifyDebuggerSessionCreated();
}
}

bool RuntimeAgent::handleRequest(const cdp::PreparsedRequest& req) {
Expand Down Expand Up @@ -83,6 +88,18 @@ bool RuntimeAgent::handleRequest(const cdp::PreparsedRequest& req) {

return true;
}
if (req.method == "Runtime.enable" && sessionState_.isLogDomainEnabled) {
targetController_.notifyDebuggerSessionCreated();
}
if (req.method == "Log.enable" && sessionState_.isRuntimeDomainEnabled) {
targetController_.notifyDebuggerSessionCreated();
}
if (req.method == "Runtime.disable" && sessionState_.isLogDomainEnabled) {
targetController_.notifyDebuggerSessionDestroyed();
}
if (req.method == "Log.disable" && sessionState_.isRuntimeDomainEnabled) {
targetController_.notifyDebuggerSessionDestroyed();
}
if (delegate_) {
return delegate_->handleRequest(req);
}
Expand Down Expand Up @@ -120,6 +137,11 @@ RuntimeAgent::ExportedState RuntimeAgent::getExportedState() {
}

RuntimeAgent::~RuntimeAgent() {
if (sessionState_.isRuntimeDomainEnabled &&
sessionState_.isLogDomainEnabled) {
targetController_.notifyDebuggerSessionDestroyed();
}

// TODO: Eventually, there may be more than one Runtime per Page, and we'll
// need to store multiple agent states here accordingly. For now let's do
// the simple thing and assume (as we do elsewhere) that only one Runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ using namespace facebook::jsi;

namespace facebook::react::jsinspector_modern {

namespace {

void emitSessionStatusChangeForObserverWithValue(
jsi::Runtime& runtime,
const jsi::Value& value) {
auto globalObj = runtime.global();
auto observer =
globalObj.getPropertyAsObject(runtime, "__DEBUGGER_SESSION_OBSERVER__");
auto onSessionStatusChange =
observer.getPropertyAsFunction(runtime, "onSessionStatusChange");
onSessionStatusChange.call(runtime, value);
}

} // namespace

std::shared_ptr<RuntimeTarget> RuntimeTarget::create(
const ExecutionContextDescription& executionContextDescription,
RuntimeTargetDelegate& delegate,
Expand All @@ -36,6 +51,7 @@ RuntimeTarget::RuntimeTarget(
void RuntimeTarget::installGlobals() {
// NOTE: RuntimeTarget::installConsoleHandler is in RuntimeTargetConsole.cpp
installConsoleHandler();
installDebuggerSessionObserver();
}

std::shared_ptr<RuntimeAgent> RuntimeTarget::createAgent(
Expand Down Expand Up @@ -105,6 +121,28 @@ void RuntimeTarget::installBindingHandler(const std::string& bindingName) {
});
}

void RuntimeTarget::emitDebuggerSessionCreated() {
jsExecutor_([selfExecutor = executorFromThis()](jsi::Runtime& runtime) {
try {
emitSessionStatusChangeForObserverWithValue(runtime, jsi::Value(true));
} catch (jsi::JSError&) {
// Suppress any errors, they should not be visible to the user
// and should not affect runtime.
}
});
}

void RuntimeTarget::emitDebuggerSessionDestroyed() {
jsExecutor_([selfExecutor = executorFromThis()](jsi::Runtime& runtime) {
try {
emitSessionStatusChangeForObserverWithValue(runtime, jsi::Value(false));
} catch (jsi::JSError&) {
// Suppress any errors, they should not be visible to the user
// and should not affect runtime.
}
});
}

RuntimeTargetController::RuntimeTargetController(RuntimeTarget& target)
: target_(target) {}

Expand All @@ -113,4 +151,12 @@ void RuntimeTargetController::installBindingHandler(
target_.installBindingHandler(bindingName);
}

void RuntimeTargetController::notifyDebuggerSessionCreated() {
target_.emitDebuggerSessionCreated();
}

void RuntimeTargetController::notifyDebuggerSessionDestroyed() {
target_.emitDebuggerSessionDestroyed();
}

} // namespace facebook::react::jsinspector_modern
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ class RuntimeTargetController {
*/
void installBindingHandler(const std::string& bindingName);

/**
* Notifies the target to emit some message that debugger session is
* created.
*/
void notifyDebuggerSessionCreated();

/**
* Notifies the target to emit some message that debugger session is
* destroyed.
*/
void notifyDebuggerSessionDestroyed();

private:
RuntimeTarget& target_;
};
Expand Down Expand Up @@ -206,6 +218,25 @@ class JSINSPECTOR_EXPORT RuntimeTarget
*/
void installConsoleHandler();

/**
* Installs __DEBUGGER_SESSION_OBSERVER__ object on the JavaScript's global
* object, which later could be referenced from JavaScript side for
* determining the status of the debugger session.
*/
void installDebuggerSessionObserver();

/**
* Propagates the debugger session state change to the JavaScript via calling
* onStatusChange on __DEBUGGER_SESSION_OBSERVER__.
*/
void emitDebuggerSessionCreated();

/**
* Propagates the debugger session state change to the JavaScript via calling
* onStatusChange on __DEBUGGER_SESSION_OBSERVER__.
*/
void emitDebuggerSessionDestroyed();

// Necessary to allow RuntimeAgent to access RuntimeTarget's internals in a
// controlled way (i.e. only RuntimeTargetController gets friend access, while
// RuntimeAgent itself doesn't).
Expand Down
Loading