react-native 0.73.0-rc.3 → 0.73.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/Libraries/Animated/nodes/AnimatedStyle.js +1 -1
  2. package/Libraries/Core/ReactNativeVersion.js +1 -1
  3. package/React/Base/RCTVersion.m +1 -1
  4. package/ReactAndroid/gradle.properties +1 -1
  5. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/BridgeDevSupportManager.java +0 -11
  6. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +5 -1
  7. package/ReactAndroid/src/main/java/com/facebook/react/modules/devloading/DevLoadingModule.java +3 -9
  8. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.java +1 -1
  9. package/ReactAndroid/src/main/java/com/facebook/react/runtime/JSTimerExecutor.java +4 -1
  10. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java +5 -0
  11. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java +41 -4
  12. package/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java +4 -1
  13. package/ReactCommon/cxxreact/ReactNativeVersion.h +1 -1
  14. package/ReactCommon/react/renderer/attributedstring/conversions.h +6 -0
  15. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm +23 -3
  16. package/ReactCommon/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm +4 -0
  17. package/gradle/libs.versions.toml +1 -1
  18. package/package.json +10 -10
  19. package/scripts/react_native_pods.rb +1 -1
  20. package/sdks/hermesc/osx-bin/hermes +0 -0
  21. package/sdks/hermesc/osx-bin/hermesc +0 -0
  22. package/sdks/hermesc/win64-bin/hermesc.exe +0 -0
  23. package/template/package.json +2 -2
  24. package/ReactCommon/jsinspector/.clang-tidy +0 -6
  25. package/ReactCommon/jsinspector/InspectorInterfaces.cpp +0 -106
  26. package/ReactCommon/jsinspector/InspectorInterfaces.h +0 -92
@@ -30,7 +30,7 @@ function createAnimatedStyle(
30
30
  const animatedStyles: any = {};
31
31
  for (const key in style) {
32
32
  const value = style[key];
33
- if (key === 'transform') {
33
+ if (value != null && key === 'transform') {
34
34
  animatedStyles[key] =
35
35
  ReactNativeFeatureFlags.shouldUseAnimatedObjectForTransform()
36
36
  ? new AnimatedObject(value)
@@ -13,5 +13,5 @@ exports.version = {
13
13
  major: 0,
14
14
  minor: 73,
15
15
  patch: 0,
16
- prerelease: 'rc.3',
16
+ prerelease: 'rc.4',
17
17
  };
@@ -24,7 +24,7 @@ NSDictionary* RCTGetReactNativeVersion(void)
24
24
  RCTVersionMajor: @(0),
25
25
  RCTVersionMinor: @(73),
26
26
  RCTVersionPatch: @(0),
27
- RCTVersionPrerelease: @"rc.3",
27
+ RCTVersionPrerelease: @"rc.4",
28
28
  };
29
29
  });
30
30
  return __rnVersion;
@@ -1,4 +1,4 @@
1
- VERSION_NAME=0.73.0-rc.3
1
+ VERSION_NAME=0.73.0-rc.4
2
2
  react.internal.publishingGroup=com.facebook.react
3
3
 
4
4
  android.useAndroidX=true
@@ -86,9 +86,6 @@ public final class BridgeDevSupportManager extends DevSupportManagerBase {
86
86
  surfaceDelegateFactory,
87
87
  devLoadingViewManager);
88
88
 
89
- mReactInstanceManagerHelper = reactInstanceManagerHelper;
90
- mDevLoadingViewManager = devLoadingViewManager;
91
-
92
89
  if (getDevSettings().isStartSamplingProfilerOnInit()) {
93
90
  // Only start the profiler. If its already running, there is an error
94
91
  if (!mIsSamplingProfilerEnabled) {
@@ -112,14 +109,6 @@ public final class BridgeDevSupportManager extends DevSupportManagerBase {
112
109
  });
113
110
  }
114
111
 
115
- public DevLoadingViewManager getDevLoadingViewManager() {
116
- return mDevLoadingViewManager;
117
- }
118
-
119
- public ReactInstanceDevHelper getReactInstanceManagerHelper() {
120
- return mReactInstanceManagerHelper;
121
- }
122
-
123
112
  @Override
124
113
  protected String getUniqueTag() {
125
114
  return "Bridge";
@@ -695,7 +695,11 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
695
695
  return mDevServerHelper;
696
696
  }
697
697
 
698
- protected ReactInstanceDevHelper getReactInstanceDevHelper() {
698
+ public DevLoadingViewManager getDevLoadingViewManager() {
699
+ return mDevLoadingViewManager;
700
+ }
701
+
702
+ public ReactInstanceDevHelper getReactInstanceDevHelper() {
699
703
  return mReactInstanceDevHelper;
700
704
  }
701
705
 
@@ -13,8 +13,7 @@ import com.facebook.react.bridge.JSExceptionHandler;
13
13
  import com.facebook.react.bridge.NativeModule;
14
14
  import com.facebook.react.bridge.ReactApplicationContext;
15
15
  import com.facebook.react.bridge.UiThreadUtil;
16
- import com.facebook.react.devsupport.BridgeDevSupportManager;
17
- import com.facebook.react.devsupport.DefaultDevLoadingViewImplementation;
16
+ import com.facebook.react.devsupport.DevSupportManagerBase;
18
17
  import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
19
18
  import com.facebook.react.module.annotations.ReactModule;
20
19
 
@@ -28,14 +27,9 @@ public class DevLoadingModule extends NativeDevLoadingViewSpec {
28
27
  public DevLoadingModule(ReactApplicationContext reactContext) {
29
28
  super(reactContext);
30
29
  mJSExceptionHandler = reactContext.getJSExceptionHandler();
31
- if (mJSExceptionHandler != null && mJSExceptionHandler instanceof BridgeDevSupportManager) {
30
+ if (mJSExceptionHandler != null && mJSExceptionHandler instanceof DevSupportManagerBase) {
32
31
  mDevLoadingViewManager =
33
- ((BridgeDevSupportManager) mJSExceptionHandler).getDevLoadingViewManager();
34
- mDevLoadingViewManager =
35
- mDevLoadingViewManager != null
36
- ? mDevLoadingViewManager
37
- : new DefaultDevLoadingViewImplementation(
38
- ((BridgeDevSupportManager) mJSExceptionHandler).getReactInstanceManagerHelper());
32
+ ((DevSupportManagerBase) mJSExceptionHandler).getDevLoadingViewManager();
39
33
  }
40
34
  }
41
35
 
@@ -18,5 +18,5 @@ public class ReactNativeVersion {
18
18
  "major", 0,
19
19
  "minor", 73,
20
20
  "patch", 0,
21
- "prerelease", "rc.3");
21
+ "prerelease", "rc.4");
22
22
  }
@@ -9,13 +9,15 @@ package com.facebook.react.runtime;
9
9
 
10
10
  import com.facebook.infer.annotation.Nullsafe;
11
11
  import com.facebook.jni.HybridData;
12
- import com.facebook.jni.annotations.DoNotStrip;
12
+ import com.facebook.jni.annotations.DoNotStripAny;
13
+ import com.facebook.proguard.annotations.DoNotStrip;
13
14
  import com.facebook.react.bridge.WritableArray;
14
15
  import com.facebook.react.bridge.WritableNativeArray;
15
16
  import com.facebook.react.modules.core.JavaScriptTimerExecutor;
16
17
  import com.facebook.soloader.SoLoader;
17
18
 
18
19
  @Nullsafe(Nullsafe.Mode.LOCAL)
20
+ @DoNotStripAny
19
21
  class JSTimerExecutor implements JavaScriptTimerExecutor {
20
22
 
21
23
  static {
@@ -24,6 +26,7 @@ class JSTimerExecutor implements JavaScriptTimerExecutor {
24
26
 
25
27
  @DoNotStrip private final HybridData mHybridData;
26
28
 
29
+ @DoNotStrip
27
30
  public JSTimerExecutor(HybridData hybridData) {
28
31
  mHybridData = hybridData;
29
32
  }
@@ -638,6 +638,9 @@ public class ReactHostImpl implements ReactHost {
638
638
  final String method = "handleHostException(message = \"" + e.getMessage() + "\")";
639
639
  log(method);
640
640
 
641
+ if (DEV) {
642
+ mDevSupportManager.handleException(e);
643
+ }
641
644
  destroy(method, e);
642
645
  mReactHostDelegate.handleInstanceException(e);
643
646
  }
@@ -922,6 +925,7 @@ public class ReactHostImpl implements ReactHost {
922
925
  final JSBundleLoader bundleLoader = task.getResult();
923
926
  final BridgelessReactContext reactContext = getOrCreateReactContext();
924
927
  final DevSupportManager devSupportManager = getDevSupportManager();
928
+ reactContext.setJSExceptionHandler(devSupportManager);
925
929
 
926
930
  log(method, "Creating ReactInstance");
927
931
  final ReactInstance instance =
@@ -1036,6 +1040,7 @@ public class ReactHostImpl implements ReactHost {
1036
1040
 
1037
1041
  final BridgelessReactContext reactContext = getOrCreateReactContext();
1038
1042
  final DevSupportManager devSupportManager = getDevSupportManager();
1043
+ reactContext.setJSExceptionHandler(devSupportManager);
1039
1044
 
1040
1045
  return getJsBundleLoader()
1041
1046
  .onSuccess(
@@ -71,6 +71,7 @@ import java.util.HashSet;
71
71
  import java.util.List;
72
72
  import java.util.Map;
73
73
  import java.util.Set;
74
+ import java.util.concurrent.ConcurrentHashMap;
74
75
  import javax.annotation.Nullable;
75
76
 
76
77
  /**
@@ -93,6 +94,7 @@ final class ReactInstance {
93
94
  private final TurboModuleManager mTurboModuleManager;
94
95
  private final FabricUIManager mFabricUIManager;
95
96
  private final JavaTimerManager mJavaTimerManager;
97
+ private final Map<String, ViewManager> mViewManagers = new ConcurrentHashMap<>();
96
98
 
97
99
  @DoNotStrip @Nullable private ComponentNameResolverManager mComponentNameResolverManager;
98
100
  @DoNotStrip @Nullable private UIConstantsProviderManager mUIConstantsProviderManager;
@@ -489,8 +491,12 @@ final class ReactInstance {
489
491
  }
490
492
 
491
493
  private @Nullable ViewManager createViewManager(String viewManagerName) {
494
+ // Return cached view manager if available, no matter it's eagerly or lazily loaded
495
+ if (mViewManagers.containsKey(viewManagerName)) {
496
+ return mViewManagers.get(viewManagerName);
497
+ }
498
+ List<ReactPackage> packages = mReactPackages;
492
499
  if (mDelegate != null) {
493
- List<ReactPackage> packages = mReactPackages;
494
500
  if (packages != null) {
495
501
  synchronized (packages) {
496
502
  for (ReactPackage reactPackage : packages) {
@@ -499,6 +505,7 @@ final class ReactInstance {
499
505
  ((ViewManagerOnDemandReactPackage) reactPackage)
500
506
  .createViewManager(mBridgelessReactContext, viewManagerName);
501
507
  if (viewManager != null) {
508
+ mViewManagers.put(viewManagerName, viewManager);
502
509
  return viewManager;
503
510
  }
504
511
  }
@@ -507,7 +514,17 @@ final class ReactInstance {
507
514
  }
508
515
  }
509
516
 
510
- return null;
517
+ // Once a view manager is not found in all react packages via lazy loading, fall back to default
518
+ // implementation: eagerly initialize all view managers
519
+ for (ReactPackage reactPackage : packages) {
520
+ List<ViewManager> viewManagersInPackage =
521
+ reactPackage.createViewManagers(mBridgelessReactContext);
522
+ for (ViewManager viewManager : viewManagersInPackage) {
523
+ mViewManagers.put(viewManager.getName(), viewManager);
524
+ }
525
+ }
526
+
527
+ return mViewManagers.get(viewManagerName);
511
528
  }
512
529
 
513
530
  private @NonNull Collection<String> getViewManagerNames() {
@@ -534,8 +551,28 @@ final class ReactInstance {
534
551
 
535
552
  private @NonNull NativeMap getUIManagerConstants() {
536
553
  List<ViewManager> viewManagers = new ArrayList<ViewManager>();
537
- for (String viewManagerName : getViewManagerNames()) {
538
- viewManagers.add(createViewManager(viewManagerName));
554
+ boolean canLoadViewManagersLazily = true;
555
+
556
+ List<ReactPackage> packages = mReactPackages;
557
+ for (ReactPackage reactPackage : packages) {
558
+ if (!(reactPackage instanceof ViewManagerOnDemandReactPackage)) {
559
+ canLoadViewManagersLazily = false;
560
+ break;
561
+ }
562
+ }
563
+ // 1, Retrive view managers via on demand loading
564
+ if (canLoadViewManagersLazily) {
565
+ for (String viewManagerName : getViewManagerNames()) {
566
+ viewManagers.add(createViewManager(viewManagerName));
567
+ }
568
+ } else {
569
+ // 2, There are packages that don't implement ViewManagerOnDemandReactPackage so we retrieve
570
+ // view managers via eager loading
571
+ for (ReactPackage reactPackage : packages) {
572
+ List<ViewManager> viewManagersInPackage =
573
+ reactPackage.createViewManagers(mBridgelessReactContext);
574
+ viewManagers.addAll(viewManagersInPackage);
575
+ }
539
576
  }
540
577
  Map<String, Object> constants =
541
578
  UIManagerModule.createConstants(viewManagers, new HashMap<>(), new HashMap<>());
@@ -59,6 +59,7 @@ public class TextAttributeProps {
59
59
  public static final short TA_KEY_ACCESSIBILITY_ROLE = 24;
60
60
  public static final short TA_KEY_LINE_BREAK_STRATEGY = 25;
61
61
  public static final short TA_KEY_ROLE = 26;
62
+ public static final short TA_KEY_TEXT_TRANSFORM = 27;
62
63
 
63
64
  public static final int UNSET = -1;
64
65
 
@@ -219,6 +220,9 @@ public class TextAttributeProps {
219
220
  case TA_KEY_ROLE:
220
221
  result.setRole(Role.values()[entry.getIntValue()]);
221
222
  break;
223
+ case TA_KEY_TEXT_TRANSFORM:
224
+ result.setTextTransform(entry.getStringValue());
225
+ break;
222
226
  }
223
227
  }
224
228
 
@@ -226,7 +230,6 @@ public class TextAttributeProps {
226
230
  // setNumberOfLines
227
231
  // setColor
228
232
  // setIncludeFontPadding
229
- // setTextTransform
230
233
  return result;
231
234
  }
232
235
 
@@ -18,7 +18,7 @@ constexpr struct {
18
18
  int32_t Major = 0;
19
19
  int32_t Minor = 73;
20
20
  int32_t Patch = 0;
21
- std::string_view Prerelease = "rc.3";
21
+ std::string_view Prerelease = "rc.4";
22
22
  } ReactNativeVersion;
23
23
 
24
24
  } // namespace facebook::react
@@ -970,6 +970,7 @@ constexpr static MapBuffer::Key TA_KEY_LAYOUT_DIRECTION = 23;
970
970
  constexpr static MapBuffer::Key TA_KEY_ACCESSIBILITY_ROLE = 24;
971
971
  constexpr static MapBuffer::Key TA_KEY_LINE_BREAK_STRATEGY = 25;
972
972
  constexpr static MapBuffer::Key TA_KEY_ROLE = 26;
973
+ constexpr static MapBuffer::Key TA_KEY_TEXT_TRANSFORM = 27;
973
974
 
974
975
  // constants for ParagraphAttributes serialization
975
976
  constexpr static MapBuffer::Key PA_KEY_MAX_NUMBER_OF_LINES = 0;
@@ -1077,6 +1078,11 @@ inline MapBuffer toMapBuffer(const TextAttributes& textAttributes) {
1077
1078
  TA_KEY_LINE_BREAK_STRATEGY,
1078
1079
  toString(*textAttributes.lineBreakStrategy));
1079
1080
  }
1081
+ if (textAttributes.textTransform.has_value()) {
1082
+ builder.putString(
1083
+ TA_KEY_TEXT_TRANSFORM, toString(*textAttributes.textTransform));
1084
+ }
1085
+
1080
1086
  // Decoration
1081
1087
  if (textAttributes.textDecorationColor) {
1082
1088
  builder.putInt(
@@ -74,13 +74,29 @@ static Class getViewManagerFromComponentName(const std::string &componentName)
74
74
  return nil;
75
75
  }
76
76
 
77
+ static Class getViewManagerClass(const std::string &componentName, RCTBridge *bridge, RCTBridgeProxy *bridgeProxy)
78
+ {
79
+ Class viewManager = getViewManagerFromComponentName(componentName);
80
+ if (viewManager != nil) {
81
+ return viewManager;
82
+ }
83
+
84
+ // If all the heuristics fail, let's try to retrieve the view manager from the bridge/bridgeProxy
85
+ if (bridge != nil) {
86
+ return [[bridge moduleForName:RCTNSStringFromString(componentName)] class];
87
+ }
88
+
89
+ if (bridgeProxy != nil) {
90
+ return [[bridgeProxy moduleForName:RCTNSStringFromString(componentName) lazilyLoadIfNecessary:YES] class];
91
+ }
92
+
93
+ return nil;
94
+ }
95
+
77
96
  static const std::shared_ptr<void> constructCoordinator(
78
97
  const ContextContainer::Shared &contextContainer,
79
98
  const ComponentDescriptor::Flavor &flavor)
80
99
  {
81
- auto componentName = *std::static_pointer_cast<std::string const>(flavor);
82
- Class viewManagerClass = getViewManagerFromComponentName(componentName);
83
- assert(viewManagerClass);
84
100
  auto optionalBridge = contextContainer->find<std::shared_ptr<void>>("Bridge");
85
101
  RCTBridge *bridge;
86
102
  if (optionalBridge) {
@@ -93,6 +109,10 @@ static const std::shared_ptr<void> constructCoordinator(
93
109
  bridgeProxy = unwrapManagedObjectWeakly(optionalBridgeProxy.value());
94
110
  }
95
111
 
112
+ auto componentName = *std::static_pointer_cast<std::string const>(flavor);
113
+ Class viewManagerClass = getViewManagerClass(componentName, bridge, bridgeProxy);
114
+ assert(viewManagerClass);
115
+
96
116
  auto optionalEventDispatcher = contextContainer->find<std::shared_ptr<void>>("RCTEventDispatcher");
97
117
  RCTEventDispatcher *eventDispatcher;
98
118
  if (optionalEventDispatcher) {
@@ -101,6 +101,10 @@ using namespace facebook::react;
101
101
  if (props.isObject()) {
102
102
  NSDictionary<NSString *, id> *convertedProps = convertFollyDynamicToId(props);
103
103
  [_componentData setProps:convertedProps forView:view];
104
+
105
+ if ([view respondsToSelector:@selector(didSetProps:)]) {
106
+ [view performSelector:@selector(didSetProps:) withObject:[convertedProps allKeys]];
107
+ }
104
108
  }
105
109
  }
106
110
 
@@ -16,7 +16,7 @@ assertj = "3.21.0"
16
16
  download = "5.4.0"
17
17
  fbjni = "0.5.1"
18
18
  flipper = "0.201.0"
19
- fresco = "3.1.0"
19
+ fresco = "3.1.3"
20
20
  infer-annotation = "0.18.0"
21
21
  javax-inject = "1"
22
22
  jsr305 = "3.0.2"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native",
3
- "version": "0.73.0-rc.3",
3
+ "version": "0.73.0-rc.4",
4
4
  "description": "A framework for building native apps using React",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -93,29 +93,29 @@
93
93
  },
94
94
  "dependencies": {
95
95
  "@jest/create-cache-key-function": "^29.6.3",
96
- "@react-native-community/cli": "12.0.0-alpha.17",
97
- "@react-native-community/cli-platform-android": "12.0.0-alpha.17",
98
- "@react-native-community/cli-platform-ios": "12.0.0-alpha.17",
96
+ "@react-native-community/cli": "12.0.0",
97
+ "@react-native-community/cli-platform-android": "12.0.0",
98
+ "@react-native-community/cli-platform-ios": "12.0.0",
99
99
  "@react-native/assets-registry": "^0.73.1",
100
- "@react-native/community-cli-plugin": "^0.73.7",
100
+ "@react-native/community-cli-plugin": "^0.73.8",
101
101
  "@react-native/codegen": "^0.73.1",
102
- "@react-native/gradle-plugin": "^0.73.2",
102
+ "@react-native/gradle-plugin": "^0.73.3",
103
103
  "@react-native/js-polyfills": "^0.73.1",
104
104
  "@react-native/normalize-colors": "^0.73.2",
105
- "@react-native/virtualized-lists": "^0.73.2",
105
+ "@react-native/virtualized-lists": "^0.73.3",
106
106
  "abort-controller": "^3.0.0",
107
107
  "anser": "^1.4.9",
108
108
  "ansi-regex": "^5.0.0",
109
109
  "base64-js": "^1.5.1",
110
- "deprecated-react-native-prop-types": "4.2.1",
110
+ "deprecated-react-native-prop-types": "^5.0.0",
111
111
  "event-target-shim": "^5.0.1",
112
112
  "flow-enums-runtime": "^0.0.6",
113
113
  "invariant": "^2.2.4",
114
114
  "jest-environment-node": "^29.6.3",
115
115
  "jsc-android": "^250231.0.0",
116
116
  "memoize-one": "^5.0.0",
117
- "metro-runtime": "0.79.1",
118
- "metro-source-map": "0.79.1",
117
+ "metro-runtime": "^0.80.0",
118
+ "metro-source-map": "^0.80.0",
119
119
  "mkdirp": "^0.5.1",
120
120
  "nullthrows": "^1.1.1",
121
121
  "pretty-format": "^26.5.2",
@@ -258,7 +258,7 @@ def react_native_post_install(
258
258
  flipper_post_install(installer)
259
259
  end
260
260
 
261
- fabric_enabled = ReactNativePodsUtils.has_pod(installer, 'React-Fabric')
261
+ fabric_enabled = ENV['RCT_FABRIC_ENABLED'] == '1'
262
262
  hermes_enabled = ReactNativePodsUtils.has_pod(installer, "React-hermes")
263
263
 
264
264
  if hermes_enabled
Binary file
Binary file
Binary file
@@ -11,7 +11,7 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "react": "18.2.0",
14
- "react-native": "0.73.0-rc.3"
14
+ "react-native": "0.73.0-rc.4"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@babel/core": "^7.20.0",
@@ -19,7 +19,7 @@
19
19
  "@babel/runtime": "^7.20.0",
20
20
  "@react-native/babel-preset": "^0.73.18",
21
21
  "@react-native/eslint-config": "^0.73.1",
22
- "@react-native/metro-config": "^0.73.1",
22
+ "@react-native/metro-config": "^0.73.2",
23
23
  "@react-native/typescript-config": "^0.73.1",
24
24
  "@types/react": "^18.2.6",
25
25
  "@types/react-test-renderer": "^18.0.0",
@@ -1,6 +0,0 @@
1
- ---
2
- Checks: '>
3
- clang-diagnostic-*,
4
- '
5
- InheritParentConfig: true
6
- ...
@@ -1,106 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #include "InspectorInterfaces.h"
9
-
10
- #include <mutex>
11
- #include <tuple>
12
- #include <unordered_map>
13
-
14
- namespace facebook::react {
15
-
16
- // pure destructors in C++ are odd. You would think they don't want an
17
- // implementation, but in fact the linker requires one. Define them to be
18
- // empty so that people don't count on them for any particular behaviour.
19
- IDestructible::~IDestructible() {}
20
- ILocalConnection::~ILocalConnection() {}
21
- IRemoteConnection::~IRemoteConnection() {}
22
- IInspector::~IInspector() {}
23
-
24
- namespace {
25
-
26
- class InspectorImpl : public IInspector {
27
- public:
28
- int addPage(
29
- const std::string& title,
30
- const std::string& vm,
31
- ConnectFunc connectFunc) override;
32
- void removePage(int pageId) override;
33
-
34
- std::vector<InspectorPage> getPages() const override;
35
- std::unique_ptr<ILocalConnection> connect(
36
- int pageId,
37
- std::unique_ptr<IRemoteConnection> remote) override;
38
-
39
- private:
40
- mutable std::mutex mutex_;
41
- int nextPageId_{1};
42
- std::unordered_map<int, std::tuple<std::string, std::string>> titles_;
43
- std::unordered_map<int, ConnectFunc> connectFuncs_;
44
- };
45
-
46
- int InspectorImpl::addPage(
47
- const std::string& title,
48
- const std::string& vm,
49
- ConnectFunc connectFunc) {
50
- std::scoped_lock lock(mutex_);
51
-
52
- int pageId = nextPageId_++;
53
- titles_[pageId] = std::make_tuple(title, vm);
54
- connectFuncs_[pageId] = std::move(connectFunc);
55
-
56
- return pageId;
57
- }
58
-
59
- void InspectorImpl::removePage(int pageId) {
60
- std::scoped_lock lock(mutex_);
61
-
62
- titles_.erase(pageId);
63
- connectFuncs_.erase(pageId);
64
- }
65
-
66
- std::vector<InspectorPage> InspectorImpl::getPages() const {
67
- std::scoped_lock lock(mutex_);
68
-
69
- std::vector<InspectorPage> inspectorPages;
70
- for (auto& it : titles_) {
71
- inspectorPages.push_back(InspectorPage{
72
- it.first, std::get<0>(it.second), std::get<1>(it.second)});
73
- }
74
-
75
- return inspectorPages;
76
- }
77
-
78
- std::unique_ptr<ILocalConnection> InspectorImpl::connect(
79
- int pageId,
80
- std::unique_ptr<IRemoteConnection> remote) {
81
- IInspector::ConnectFunc connectFunc;
82
-
83
- {
84
- std::scoped_lock lock(mutex_);
85
-
86
- auto it = connectFuncs_.find(pageId);
87
- if (it != connectFuncs_.end()) {
88
- connectFunc = it->second;
89
- }
90
- }
91
-
92
- return connectFunc ? connectFunc(std::move(remote)) : nullptr;
93
- }
94
-
95
- } // namespace
96
-
97
- IInspector& getInspectorInstance() {
98
- static InspectorImpl instance;
99
- return instance;
100
- }
101
-
102
- std::unique_ptr<IInspector> makeTestInspectorInstance() {
103
- return std::make_unique<InspectorImpl>();
104
- }
105
-
106
- } // namespace facebook::react
@@ -1,92 +0,0 @@
1
- /*
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #pragma once
9
-
10
- #include <functional>
11
- #include <memory>
12
- #include <string>
13
- #include <vector>
14
-
15
- #ifndef JSINSPECTOR_EXPORT
16
- #ifdef _MSC_VER
17
- #ifdef CREATE_SHARED_LIBRARY
18
- #define JSINSPECTOR_EXPORT __declspec(dllexport)
19
- #else
20
- #define JSINSPECTOR_EXPORT
21
- #endif // CREATE_SHARED_LIBRARY
22
- #else // _MSC_VER
23
- #define JSINSPECTOR_EXPORT __attribute__((visibility("default")))
24
- #endif // _MSC_VER
25
- #endif // !defined(JSINSPECTOR_EXPORT)
26
-
27
- namespace facebook::react {
28
-
29
- class IDestructible {
30
- public:
31
- virtual ~IDestructible() = 0;
32
- };
33
-
34
- struct InspectorPage {
35
- const int id;
36
- const std::string title;
37
- const std::string vm;
38
- };
39
-
40
- /// IRemoteConnection allows the VM to send debugger messages to the client.
41
- class JSINSPECTOR_EXPORT IRemoteConnection : public IDestructible {
42
- public:
43
- virtual ~IRemoteConnection() = 0;
44
- virtual void onMessage(std::string message) = 0;
45
- virtual void onDisconnect() = 0;
46
- };
47
-
48
- /// ILocalConnection allows the client to send debugger messages to the VM.
49
- class JSINSPECTOR_EXPORT ILocalConnection : public IDestructible {
50
- public:
51
- virtual ~ILocalConnection() = 0;
52
- virtual void sendMessage(std::string message) = 0;
53
- virtual void disconnect() = 0;
54
- };
55
-
56
- /// IInspector tracks debuggable JavaScript targets (pages).
57
- class JSINSPECTOR_EXPORT IInspector : public IDestructible {
58
- public:
59
- using ConnectFunc = std::function<std::unique_ptr<ILocalConnection>(
60
- std::unique_ptr<IRemoteConnection>)>;
61
-
62
- virtual ~IInspector() = 0;
63
-
64
- /// addPage is called by the VM to add a page to the list of debuggable pages.
65
- virtual int addPage(
66
- const std::string& title,
67
- const std::string& vm,
68
- ConnectFunc connectFunc) = 0;
69
-
70
- /// removePage is called by the VM to remove a page from the list of
71
- /// debuggable pages.
72
- virtual void removePage(int pageId) = 0;
73
-
74
- /// getPages is called by the client to list all debuggable pages.
75
- virtual std::vector<InspectorPage> getPages() const = 0;
76
-
77
- /// connect is called by the client to initiate a debugging session on the
78
- /// given page.
79
- virtual std::unique_ptr<ILocalConnection> connect(
80
- int pageId,
81
- std::unique_ptr<IRemoteConnection> remote) = 0;
82
- };
83
-
84
- /// getInspectorInstance retrieves the singleton inspector that tracks all
85
- /// debuggable pages in this process.
86
- extern IInspector& getInspectorInstance();
87
-
88
- /// makeTestInspectorInstance creates an independent inspector instance that
89
- /// should only be used in tests.
90
- extern std::unique_ptr<IInspector> makeTestInspectorInstance();
91
-
92
- } // namespace facebook::react