Skip to content

Commit 82def6e

Browse files
mrousavymeta-codesync[bot]
authored andcommitted
Run the With hooks around WithRuntimeDecorator::createArrayBuffer (#58935)
Summary: Pull Request resolved: #58935 `WithRuntimeDecorator` wraps every override in `Around around{with_};` except `createArrayBuffer(std::shared_ptr<MutableBuffer>)`, which calls `RD::createArrayBuffer` directly. It has been like that since external ArrayBuffers were added in facebook/hermes#793, where the overrides next to it did get the guard. `HermesRuntimeImpl::createArrayBuffer` allocates a `JSArrayBuffer` on the GC heap, so on `makeThreadSafeHermesRuntime` it runs without the runtime lock, and reentrancy checks built on `WithRuntimeDecorator` never see the call. #45042 and #45049 fixed the same kind of gap for methods that had no `WithRuntimeDecorator` override at all. This one has an override that just skips the guard, so it wasn't caught there. A small stress program shows the race: one thread runs an allocating JS loop on a thread-safe runtime while another creates external ArrayBuffers. In a Debug build it fails the `makeA() calls can not be interleaved` assert in HadesGC. With the guard it runs clean. I didn't add it as a test because it depends on timing. React Native's copy of `decorator.h` has the same line. X-link: facebook/hermes#2204 Test Plan: Added `HermesRuntimeDecoratorTest.CreateArrayBufferCallsWith`. It wraps `makeHermesRuntime()` in a counting `WithRuntimeDecorator`, creates an ArrayBuffer from a `MutableBuffer`, and checks that `before()` and `after()` each ran once. Without the change both counts are 0 and the test fails. With it the test passes, and so does the full `APITests` binary (356 tests) in a Debug + ASan build. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed By: avp Differential Revision: D123939407 Pulled By: lavenzg fbshipit-source-id: 165a7807ecc9cf68f56a1f2b188642dbd68d136d
1 parent 0dbd23b commit 82def6e

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎packages/react-native/ReactCommon/jsi/jsi/decorator.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ class WithRuntimeDecorator : public RuntimeDecorator<Plain, Base> {
10051005
}
10061006
ArrayBuffer createArrayBuffer(
10071007
std::shared_ptr<MutableBuffer> buffer) override {
1008+
Around around{with_};
10081009
return RD::createArrayBuffer(std::move(buffer));
10091010
}
10101011
size_t size(const Array& a) override {

0 commit comments

Comments
 (0)