Run the API tests on the sandbox (#59238)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/59238

Add HermesSandboxRuntime to runtimeGenerators() in APITestFactory.cpp,
so HermesUnitTests runs the parameterized HermesRuntimeTest cases on
the sandbox as well, like the legacy Hermes API tests do. Until now no
static_h test ran the sandbox.

The sandbox does not support everything HermesRuntime does, so the
tests skip what it lacks, with the same
dynamic_cast<HermesSandboxRuntime *> checks the file already uses:
- instrumentation(): GetHeapInfo and ExternalMemoryNoOpTest.
- ArrayBuffers created from a MutableBuffer: the rest of
  TryGetMutableBuffer after its first check, and
  TryGetMutableBufferAfterHiddenClassTransition.
- createValueFromJsonUtf8 is the default implementation, which calls
  the global JSON.parse: CreateValueFromJsonUtf8IgnoresGlobalJSON.
- utf16() converts through UTF-8, which turns lone surrogates into
  U+FFFD: the lone surrogate checks at the end of UTF16ConversionTest
  and CreateFromUtf16Test.

The sandbox implements neither ISerialization nor Worker, so
HermesSerializationTest and HermesWorkerTest run on the new
hermesRuntimeGenerators(), which returns just the two HermesRuntime
factories.

The same factory backs JSITests-SHTrunk, JSITestsUnstable-SHTrunk and
JSIDynamicTests-SHTrunk in xplat/jsi, FBJSValueTests-SHTrunk on Apple,
and the CMake APITests, so those now run on the sandbox too. In
testlib, ArrayBufferDetachedTest assumed that a runtime with
ArrayBuffer.prototype.detached can also detach a buffer from JS. The
sandbox has neither transfer() nor HermesInternal.detachArrayBuffer,
so the test now stops after its first check in that case.

The CMake sanitizer jobs build with Clang's UBSan, whose function
type check aborts on the generated code's indirect calls: they pass
the instance as void * to functions defined with a typed instance
pointer. Nothing ran the sandbox before, so this never fired. Build
the generated C with -fno-sanitize=function under Clang.

Changelog: [Internal]

Reviewed By: avp

Differential Revision: D125561036

fbshipit-source-id: 65d82faf50745489321a04a3b12162d3f4983be4
This commit is contained in:
Gang Zhao authored and meta-codesync[bot] committed 2026-10-21 18:04:25 -07:00
1 parent a340eec183
commit 05a2e4c799
2 files changed
+12

No files matched your search

@@ -2719,6 +2719,17 @@ TEST_P(JSITest, ArrayBufferDetachedTest) {
return;
}
// Skip the rest if the runtime has no way to detach an ArrayBuffer from JS.
bool canDetach =
eval(
"typeof buf.transfer === 'function' || "
"(typeof HermesInternal !== 'undefined' && "
" typeof HermesInternal.detachArrayBuffer === 'function')")
.getBool();
if (!canDetach) {
return;
}
// Detach the ArrayBuffer. Use transfer() if available, otherwise fall back
// to HermesInternal.detach for Hermes runtime.
eval(
@@ -22,6 +22,7 @@ class Runtime;
using RuntimeFactory = std::function<std::shared_ptr<Runtime>()>;
std::vector<RuntimeFactory> runtimeGenerators();
std::vector<RuntimeFactory> runtimeGeneratorsWithSandBox();
class JSITestBase : public ::testing::TestWithParam<RuntimeFactory> {
public: