PHP 7.4.33
Preview: RuntimeTargetDebuggerSessionObserver.cpp Size: 4.71 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/ReactCommon/jsinspector-modern/RuntimeTargetDebuggerSessionObserver.cpp
/*
 * 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 <jsinspector-modern/RuntimeTarget.h>

namespace facebook::react::jsinspector_modern {

void RuntimeTarget::installDebuggerSessionObserver() {
  jsExecutor_([](jsi::Runtime& runtime) {
    auto globalObj = runtime.global();
    try {
      auto observer = jsi::Object(runtime);

      observer.setProperty(runtime, "hasActiveSession", jsi::Value(false));

      auto setFunction = globalObj.getPropertyAsFunction(runtime, "Set");
      auto set = setFunction.callAsConstructor(runtime);
      observer.setProperty(runtime, "subscribers", set);

      observer.setProperty(
          runtime,
          "onSessionStatusChange",
          jsi::Function::createFromHostFunction(
              runtime,
              jsi::PropNameID::forAscii(runtime, "onSessionStatusChange"),
              1,
              [](jsi::Runtime& onSessionStatusChangeRuntime,
                 const jsi::Value& /* onSessionStatusChangeThisVal */,
                 const jsi::Value* onSessionStatusChangeArgs,
                 size_t onSessionStatusChangeArgsCount) {
                if (onSessionStatusChangeArgsCount != 1 ||
                    !onSessionStatusChangeArgs[0].isBool()) {
                  throw jsi::JSError(
                      onSessionStatusChangeRuntime,
                      "Invalid arguments: onSessionStatusChange expects 1 boolean argument");
                }

                bool updatedStatus = onSessionStatusChangeArgs[0].getBool();

                auto observerInstanceFromOnSessionStatusChange =
                    onSessionStatusChangeRuntime.global().getPropertyAsObject(
                        onSessionStatusChangeRuntime,
                        "__DEBUGGER_SESSION_OBSERVER__");
                auto subscribersToNotify =
                    observerInstanceFromOnSessionStatusChange
                        .getPropertyAsObject(
                            onSessionStatusChangeRuntime, "subscribers");

                observerInstanceFromOnSessionStatusChange.setProperty(
                    onSessionStatusChangeRuntime,
                    "hasActiveSession",
                    updatedStatus);

                if (subscribersToNotify
                        .getProperty(onSessionStatusChangeRuntime, "size")
                        .asNumber() == 0) {
                  return jsi::Value::undefined();
                }

                auto forEachSubscriber =
                    subscribersToNotify.getPropertyAsFunction(
                        onSessionStatusChangeRuntime, "forEach");
                auto forEachSubscriberCallback =
                    jsi::Function::createFromHostFunction(
                        onSessionStatusChangeRuntime,
                        jsi::PropNameID::forAscii(
                            onSessionStatusChangeRuntime, "forEachCallback"),
                        1,
                        [updatedStatus](
                            jsi::Runtime& forEachCallbackRuntime,
                            const jsi::Value& /* forEachCallbackThisVal */,
                            const jsi::Value* forEachCallbackArgs,
                            size_t forEachCallbackArgsCount) {
                          if (forEachCallbackArgsCount < 1 ||
                              !forEachCallbackArgs[0].isObject() ||
                              !forEachCallbackArgs[0]
                                   .getObject(forEachCallbackRuntime)
                                   .isFunction(forEachCallbackRuntime)) {
                            throw jsi::JSError(
                                forEachCallbackRuntime,
                                "Invalid arguments: forEachSubscriberCallback expects function as a first argument");
                          }

                          forEachCallbackArgs[0]
                              .getObject(forEachCallbackRuntime)
                              .asFunction(forEachCallbackRuntime)
                              .call(forEachCallbackRuntime, updatedStatus);

                          return jsi::Value::undefined();
                        });

                forEachSubscriber.callWithThis(
                    onSessionStatusChangeRuntime,
                    subscribersToNotify,
                    forEachSubscriberCallback);

                return jsi::Value::undefined();
              }));

      globalObj.setProperty(runtime, "__DEBUGGER_SESSION_OBSERVER__", observer);
    } catch (jsi::JSError&) {
      // Suppress any errors, they should not be visible to the user
      // and should not affect runtime.
    }
  });
}

} // namespace facebook::react::jsinspector_modern

Directory Contents

Dirs: 2 × Files: 54
Name Size Perms Modified Actions
tests DIR
- drwxr-xr-x 2025-03-28 11:04:41
Edit Download
tracing DIR
- drwxr-xr-x 2025-03-28 11:04:43
Edit Download
2.54 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.03 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.49 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.02 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.26 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.13 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.17 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.81 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.01 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
500 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
512 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.10 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.28 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.49 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.31 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.27 KB lrw-r--r-- 2025-03-28 11:04:40
Edit Download
8.55 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.77 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
445 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
8.41 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
9.62 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.21 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.65 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.07 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.99 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
11.52 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.71 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
3.80 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1015 B lrw-r--r-- 2025-03-28 11:04:39
Edit Download
1.45 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
4.96 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.08 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.63 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.72 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
14.16 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
8.33 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.51 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
544 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.77 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
3.22 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.74 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
5.25 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
9.06 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
15.77 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
4.71 KB lrw-r--r-- 2025-03-28 11:04:39
Edit Download
2.78 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.02 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
855 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.79 KB lrw-r--r-- 2025-03-28 11:04:40
Edit Download
1.01 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.40 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.25 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
2.03 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.97 KB lrw-r--r-- 2025-03-28 11:04:41
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).