Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,15 @@ package com.facebook.hermes.reactexecutor
import com.facebook.jni.HybridData
import com.facebook.jni.annotations.DoNotStrip
import com.facebook.react.bridge.JavaScriptExecutor
import com.facebook.react.common.build.ReactBuildConfig
import com.facebook.soloader.SoLoader

public class HermesExecutor internal constructor(enableDebugger: Boolean, debuggerName: String) :
JavaScriptExecutor(initHybridDefaultConfig(enableDebugger, debuggerName)) {

override fun getName(): String = "HermesExecutor$mode"
override fun getName(): String = "HermesExecutor"

public companion object {
private var mode: String? = null

init {
loadLibrary()
}

@JvmStatic
@Throws(UnsatisfiedLinkError::class)
public fun loadLibrary() {
if (mode == null) {
// libhermesvm must be loaded explicitly to invoke its JNI_OnLoad.
SoLoader.loadLibrary("hermesvm")
SoLoader.loadLibrary("hermes_executor")
// libhermes_executor is built differently for Debug & Release so we load the proper mode.
mode = if (ReactBuildConfig.DEBUG) "Debug" else "Release"
}
}
/** Retained for compatibility; this method no longer loads native libraries. */
@JvmStatic public fun loadLibrary() {}

@DoNotStrip
@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ public class HermesExecutorFactory : JavaScriptExecutorFactory {
this.debuggerName = debuggerName
}

override fun create(): JavaScriptExecutor = HermesExecutor(enableDebugger, debuggerName)
/**
* Compatibility factory for the unsupported legacy Hermes executor.
*
* @throws UnsupportedOperationException when creating an executor; use the New Architecture
* runtime instead.
*/
override fun create(): JavaScriptExecutor {
throw UnsupportedOperationException(
"HermesExecutorFactory is no longer supported. Use the New Architecture runtime instead.",
)
}

override fun startSamplingProfiler() {
enable()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.hermes.reactexecutor

import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test

class HermesExecutorFactoryTest {
@Test
fun loadLibraryIsNoOp() {
HermesExecutor.loadLibrary()
HermesExecutor.loadLibrary()
}

@Test
fun createIsUnsupported() {
val factory = HermesExecutorFactory()
factory.setEnableDebugger(false)
factory.setDebuggerName("test")

repeat(2) {
assertThatThrownBy { factory.create() }
.isInstanceOf(UnsupportedOperationException::class.java)
.hasMessage(
"HermesExecutorFactory is no longer supported. Use the New Architecture runtime instead.",
)
}
}
}
Loading