Skip to content

Commit d04bb7d

Browse files
committed
Revert "Cleanup all the JSC 1st party code. (#51949)"
This reverts commit 8174d02.
1 parent 7f25e6c commit d04bb7d

18 files changed

Lines changed: 404 additions & 13 deletions

File tree

packages/gradle-plugin/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ internal object NdkConfiguratorUtils {
126126
): Pair<List<String>, List<String>> {
127127
val excludes = mutableListOf<String>()
128128
val includes = mutableListOf<String>()
129-
130-
// note: libjsctooling.so is kept here for backward compatibility.
131129
when {
132130
hermesEnabled -> {
133131
excludes.add("**/libjsc.so")

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,10 @@ - (NSString *)accessibilityLabel
12301230
return label;
12311231
}
12321232

1233-
return RCTRecursiveAccessibilityLabel(self.currentContainerView);
1233+
if (self.isAccessibilityElement) {
1234+
return RCTRecursiveAccessibilityLabel(self.currentContainerView);
1235+
}
1236+
return nil;
12341237
}
12351238

12361239
- (NSString *)accessibilityLabelForCoopting

packages/react-native/React/Views/RCTView.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ - (NSString *)accessibilityLabel
240240
if (label) {
241241
return label;
242242
}
243-
return RCTRecursiveAccessibilityLabel(self);
243+
if (self.isAccessibilityElement) {
244+
return RCTRecursiveAccessibilityLabel(self);
245+
}
246+
return nil;
244247
}
245248

246249
- (NSArray<UIAccessibilityCustomAction *> *)accessibilityCustomActions

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,6 +2448,19 @@ public abstract interface class com/facebook/react/interfaces/fabric/ReactSurfac
24482448
public abstract fun stop ()Lcom/facebook/react/interfaces/TaskInterface;
24492449
}
24502450

2451+
public final class com/facebook/react/jscexecutor/JSCExecutor : com/facebook/react/bridge/JavaScriptExecutor {
2452+
public fun getName ()Ljava/lang/String;
2453+
public static final fun loadLibrary ()V
2454+
}
2455+
2456+
public final class com/facebook/react/jscexecutor/JSCExecutorFactory : com/facebook/react/bridge/JavaScriptExecutorFactory {
2457+
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
2458+
public fun create ()Lcom/facebook/react/bridge/JavaScriptExecutor;
2459+
public fun startSamplingProfiler ()V
2460+
public fun stopSamplingProfiler (Ljava/lang/String;)V
2461+
public fun toString ()Ljava/lang/String;
2462+
}
2463+
24512464
public final class com/facebook/react/jstasks/HeadlessJsTaskConfig {
24522465
public fun <init> (Lcom/facebook/react/jstasks/HeadlessJsTaskConfig;)V
24532466
public fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
@@ -3122,6 +3135,10 @@ public class com/facebook/react/runtime/CoreReactPackage$$ReactModuleInfoProvide
31223135
public fun getReactModuleInfos ()Ljava/util/Map;
31233136
}
31243137

3138+
public final class com/facebook/react/runtime/JSCInstance : com/facebook/react/runtime/JSRuntimeFactory {
3139+
public fun <init> ()V
3140+
}
3141+
31253142
public abstract class com/facebook/react/runtime/JSRuntimeFactory {
31263143
public fun <init> (Lcom/facebook/jni/HybridData;)V
31273144
}
@@ -3236,6 +3253,10 @@ public final class com/facebook/react/soloader/OpenSourceMergedSoMapping : com/f
32363253
public final fun libhermes_executor_so ()I
32373254
public final fun libhermesinstancejni_so ()I
32383255
public final fun libhermestooling_so ()I
3256+
public final fun libjscexecutor_so ()I
3257+
public final fun libjscinstance_so ()I
3258+
public final fun libjscruntime_so ()I
3259+
public final fun libjsctooling_so ()I
32393260
public final fun libjsijniprofiler_so ()I
32403261
public final fun libjsinspector_so ()I
32413262
public final fun libmapbufferjni_so ()I

packages/react-native/ReactAndroid/build.gradle.kts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ val preparePrefab by
8787
// hermes_executor
8888
// This prefab targets is used by Expo & Reanimated
8989
Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/"),
90+
// jscexecutor
91+
Pair("../ReactCommon/jsc/", "jsc/"),
9092
// fabricjni
9193
Pair("src/main/jni/react/fabric", "react/fabric/"),
9294
// glog
@@ -234,6 +236,10 @@ val preparePrefab by
234236
"hermestooling",
235237
// hermes_executor
236238
Pair("../ReactCommon/hermes/inspector-modern/", "hermes/inspector-modern/")),
239+
PrefabPreprocessingEntry(
240+
"jsctooling",
241+
// jsc
242+
Pair("../ReactCommon/jsc/", "jsc/")),
237243
))
238244
outputDir.set(prefabHeadersDir)
239245
}
@@ -528,6 +534,7 @@ android {
528534
"reactnative",
529535
"jsi",
530536
"hermestooling",
537+
"jsctooling",
531538
)
532539
}
533540
}
@@ -576,9 +583,10 @@ android {
576583
resources.excludes.add("META-INF/LICENSE")
577584
// We intentionally don't want to bundle any JS Runtime inside the Android AAR
578585
// we produce. The reason behind this is that we want to allow users to pick the
579-
// JS engine by specifying a dependency on either `hermes-engine` or other engines
586+
// JS engine by specifying a dependency on either `hermes-engine` or `android-jsc`
580587
// that will include the necessary .so files to load.
581588
jniLibs.excludes.add("**/libhermes.so")
589+
jniLibs.excludes.add("**/libjsc.so")
582590
}
583591

584592
buildFeatures {
@@ -591,6 +599,7 @@ android {
591599
create("jsi") { headers = File(prefabHeadersDir, "jsi").absolutePath }
592600
create("reactnative") { headers = File(prefabHeadersDir, "reactnative").absolutePath }
593601
create("hermestooling") { headers = File(prefabHeadersDir, "hermestooling").absolutePath }
602+
create("jsctooling") { headers = File(prefabHeadersDir, "jsctooling").absolutePath }
594603
}
595604

596605
publishing {
@@ -635,9 +644,10 @@ dependencies {
635644
compileOnly(libs.javax.annotation.api)
636645
api(libs.javax.inject)
637646

638-
// It's up to the consumer to decide if hermes or other engines should be included or not.
639-
// Therefore hermes-engine is a compileOnly dependencies.
647+
// It's up to the consumer to decide if hermes/jsc should be included or not.
648+
// Therefore hermes-engine and jsc are compileOnly dependencies.
640649
compileOnly(project(":packages:react-native:ReactAndroid:hermes-engine"))
650+
compileOnly(libs.jsc.android)
641651

642652
testImplementation(libs.junit)
643653
testImplementation(libs.assertj)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.facebook.react.common.annotations.UnstableReactNativeAPI
1717
import com.facebook.react.common.build.ReactBuildConfig
1818
import com.facebook.react.fabric.ComponentFactory
1919
import com.facebook.react.runtime.BindingsInstaller
20+
import com.facebook.react.runtime.JSCInstance
2021
import com.facebook.react.runtime.JSRuntimeFactory
2122
import com.facebook.react.runtime.ReactHostImpl
2223
import com.facebook.react.runtime.cxxreactpackage.CxxReactPackage
@@ -207,7 +208,7 @@ public object DefaultReactHost {
207208
jsMainModulePath,
208209
jsBundleAssetPath,
209210
jsBundleFilePath,
210-
HermesInstance(),
211+
if (isHermesEnabled) HermesInstance() else JSCInstance(),
211212
useDevSupport,
212213
cxxReactPackageProviders,
213214
exceptionHandler,
@@ -263,7 +264,7 @@ public object DefaultReactHost {
263264
jsMainModulePath,
264265
jsBundleAssetPath,
265266
jsBundleFilePath,
266-
HermesInstance(),
267+
if (isHermesEnabled) HermesInstance() else JSCInstance(),
267268
useDevSupport,
268269
cxxReactPackageProviders,
269270
)

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactNativeHost.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import com.facebook.react.bridge.UIManagerProvider
1717
import com.facebook.react.common.annotations.UnstableReactNativeAPI
1818
import com.facebook.react.fabric.ComponentFactory
1919
import com.facebook.react.fabric.FabricUIManagerProviderImpl
20+
import com.facebook.react.runtime.JSCInstance
2021
import com.facebook.react.runtime.JSRuntimeFactory
2122
import com.facebook.react.runtime.hermes.HermesInstance
2223
import com.facebook.react.uimanager.ViewManagerRegistry
@@ -92,9 +93,6 @@ protected constructor(
9293
* If true, the app will load the Hermes engine, and fail if not found. If false, the app will
9394
* load the JSC engine, and fail if not found.
9495
*/
95-
@Deprecated(
96-
"Setting isHermesEnabled inside `ReactNativeHost` is deprecated and this field will be ignored. If this field is set to true, you can safely remove it. If this field is set to false, please follow the setup on https://github.com/react-native-community/javascriptcore to continue using JSC",
97-
ReplaceWith(""))
9896
protected open val isHermesEnabled: Boolean
9997
get() = true
10098

@@ -108,7 +106,8 @@ protected constructor(
108106
context: Context,
109107
jsRuntimeFactory: JSRuntimeFactory? = null
110108
): ReactHost {
111-
val concreteJSRuntimeFactory = jsRuntimeFactory ?: HermesInstance()
109+
val concreteJSRuntimeFactory =
110+
jsRuntimeFactory ?: if (isHermesEnabled) HermesInstance() else JSCInstance()
112111
return DefaultReactHost.getDefaultReactHost(
113112
context,
114113
packages,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
package com.facebook.react.jscexecutor
9+
10+
import com.facebook.jni.HybridData
11+
import com.facebook.proguard.annotations.DoNotStrip
12+
import com.facebook.react.bridge.JavaScriptExecutor
13+
import com.facebook.react.bridge.ReadableNativeMap
14+
import com.facebook.react.common.annotations.internal.LegacyArchitecture
15+
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
16+
import com.facebook.soloader.SoLoader
17+
18+
@DoNotStrip
19+
@LegacyArchitecture
20+
public class JSCExecutor internal constructor(jscConfig: ReadableNativeMap) :
21+
JavaScriptExecutor(initHybrid(jscConfig)) {
22+
23+
override fun getName(): String {
24+
return "JSCExecutor"
25+
}
26+
27+
internal companion object {
28+
init {
29+
loadLibrary()
30+
LegacyArchitectureLogger.assertLegacyArchitecture("JSCExecutor")
31+
}
32+
33+
@JvmStatic
34+
@Throws(UnsatisfiedLinkError::class)
35+
fun loadLibrary() {
36+
SoLoader.loadLibrary("jscexecutor")
37+
}
38+
39+
@JvmStatic private external fun initHybrid(jscConfig: ReadableNativeMap): HybridData
40+
}
41+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
package com.facebook.react.jscexecutor
9+
10+
import com.facebook.react.bridge.JavaScriptExecutor
11+
import com.facebook.react.bridge.JavaScriptExecutorFactory
12+
import com.facebook.react.bridge.WritableNativeMap
13+
import com.facebook.react.common.annotations.internal.LegacyArchitecture
14+
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel
15+
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger
16+
17+
@LegacyArchitecture(logLevel = LegacyArchitectureLogLevel.ERROR)
18+
public class JSCExecutorFactory(private val appName: String, private val deviceName: String) :
19+
JavaScriptExecutorFactory {
20+
21+
init {
22+
LegacyArchitectureLogger.assertLegacyArchitecture(
23+
"JSCExecutorFactory", LegacyArchitectureLogLevel.ERROR)
24+
}
25+
26+
@Throws(Exception::class)
27+
override fun create(): JavaScriptExecutor {
28+
val jscConfig =
29+
WritableNativeMap().apply {
30+
putString("OwnerIdentity", "ReactNative")
31+
putString("AppIdentity", appName)
32+
putString("DeviceIdentity", deviceName)
33+
}
34+
return JSCExecutor(jscConfig)
35+
}
36+
37+
override fun startSamplingProfiler() {
38+
throw UnsupportedOperationException("Starting sampling profiler not supported on ${toString()}")
39+
}
40+
41+
override fun stopSamplingProfiler(filename: String) {
42+
throw UnsupportedOperationException("Stopping sampling profiler not supported on ${toString()}")
43+
}
44+
45+
override fun toString(): String = "JSIExecutor+JSCRuntime"
46+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
package com.facebook.react.runtime
9+
10+
import com.facebook.jni.HybridData
11+
import com.facebook.jni.annotations.DoNotStrip
12+
import com.facebook.jni.annotations.DoNotStripAny
13+
import com.facebook.soloader.SoLoader
14+
15+
@DoNotStripAny
16+
public class JSCInstance : JSRuntimeFactory(initHybrid()) {
17+
private companion object {
18+
init {
19+
SoLoader.loadLibrary("jscinstance")
20+
}
21+
22+
@DoNotStrip @JvmStatic private external fun initHybrid(): HybridData
23+
}
24+
}

0 commit comments

Comments
 (0)