From 561f8439987a8200b385c9720c67eaa154dfff80 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Fri, 28 Jul 2023 06:08:53 -0700 Subject: [PATCH] Migrate jscexecutor to kotlin (#38254) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38254 In this diff I'm migrating jscexecutor to kotlin changelog: [internal] internal Reviewed By: christophpurrer Differential Revision: D47309460 fbshipit-source-id: f3d04277813ff7314eb7e5b011475bd2d4c72c7f --- .../react/jscexecutor/JSCExecutor.java | 37 -------------- .../facebook/react/jscexecutor/JSCExecutor.kt | 36 ++++++++++++++ .../react/jscexecutor/JSCExecutorFactory.java | 48 ------------------- .../react/jscexecutor/JSCExecutorFactory.kt | 37 ++++++++++++++ 4 files changed, 73 insertions(+), 85 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.java deleted file mode 100644 index 17e7ce7bf16..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ - -package com.facebook.react.jscexecutor; - -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.bridge.JavaScriptExecutor; -import com.facebook.react.bridge.ReadableNativeMap; -import com.facebook.soloader.SoLoader; - -@DoNotStrip -public class JSCExecutor extends JavaScriptExecutor { - - static { - loadLibrary(); - } - - public static void loadLibrary() throws UnsatisfiedLinkError { - SoLoader.loadLibrary("jscexecutor"); - } - - /* package */ JSCExecutor(ReadableNativeMap jscConfig) { - super(initHybrid(jscConfig)); - } - - @Override - public String getName() { - return "JSCExecutor"; - } - - private static native HybridData initHybrid(ReadableNativeMap jscConfig); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt new file mode 100644 index 00000000000..8dc018deca0 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutor.kt @@ -0,0 +1,36 @@ +/* + * 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. + */ + +package com.facebook.react.jscexecutor + +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip +import com.facebook.react.bridge.JavaScriptExecutor +import com.facebook.react.bridge.ReadableNativeMap +import com.facebook.soloader.SoLoader + +@DoNotStrip +class JSCExecutor internal constructor(jscConfig: ReadableNativeMap) : + JavaScriptExecutor(initHybrid(jscConfig)) { + override fun getName(): String { + return "JSCExecutor" + } + + companion object { + init { + loadLibrary() + } + + @JvmStatic + @Throws(UnsatisfiedLinkError::class) + fun loadLibrary() { + SoLoader.loadLibrary("jscexecutor") + } + + private external fun initHybrid(jscConfig: ReadableNativeMap): HybridData? + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.java deleted file mode 100644 index ddd913b77a3..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ - -package com.facebook.react.jscexecutor; - -import com.facebook.react.bridge.JavaScriptExecutor; -import com.facebook.react.bridge.JavaScriptExecutorFactory; -import com.facebook.react.bridge.WritableNativeMap; - -public class JSCExecutorFactory implements JavaScriptExecutorFactory { - private final String mAppName; - private final String mDeviceName; - - public JSCExecutorFactory(String appName, String deviceName) { - this.mAppName = appName; - this.mDeviceName = deviceName; - } - - @Override - public JavaScriptExecutor create() throws Exception { - WritableNativeMap jscConfig = new WritableNativeMap(); - jscConfig.putString("OwnerIdentity", "ReactNative"); - jscConfig.putString("AppIdentity", mAppName); - jscConfig.putString("DeviceIdentity", mDeviceName); - return new JSCExecutor(jscConfig); - } - - @Override - public void startSamplingProfiler() { - throw new UnsupportedOperationException( - "Starting sampling profiler not supported on " + toString()); - } - - @Override - public void stopSamplingProfiler(String filename) { - throw new UnsupportedOperationException( - "Stopping sampling profiler not supported on " + toString()); - } - - @Override - public String toString() { - return "JSIExecutor+JSCRuntime"; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.kt new file mode 100644 index 00000000000..6a464495977 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/jscexecutor/JSCExecutorFactory.kt @@ -0,0 +1,37 @@ +/* + * 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. + */ + +package com.facebook.react.jscexecutor + +import com.facebook.react.bridge.JavaScriptExecutor +import com.facebook.react.bridge.JavaScriptExecutorFactory +import com.facebook.react.bridge.WritableNativeMap + +class JSCExecutorFactory(private val appName: String, private val deviceName: String) : + JavaScriptExecutorFactory { + + @Throws(Exception::class) + override fun create(): JavaScriptExecutor { + val jscConfig = + WritableNativeMap().apply { + putString("OwnerIdentity", "ReactNative") + putString("AppIdentity", appName) + putString("DeviceIdentity", deviceName) + } + return JSCExecutor(jscConfig) + } + + override fun startSamplingProfiler() { + throw UnsupportedOperationException("Starting sampling profiler not supported on ${toString()}") + } + + override fun stopSamplingProfiler(filename: String) { + throw UnsupportedOperationException("Stopping sampling profiler not supported on ${toString()}") + } + + override fun toString(): String = "JSIExecutor+JSCRuntime" +}