Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample (#57985) - #57985
Open
christophpurrer wants to merge 4 commits into
Open
Align SampleTurboModuleExample UI with NativeCxxModuleExampleExample (#57985)#57985christophpurrer wants to merge 4 commits into
christophpurrer wants to merge 4 commits into
Conversation
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D116375214. |
…ct#57983) Summary: Pull Request resolved: react#57983 Follow-ups in the ObjC `ArrayBuffer` conversion path. Correctness: - Copy JS-heap `ArrayBuffer` arguments whenever the call can carry them past it. A function argument becomes a block the module may invoke after the call returns, so the copy decision now scans the argument list instead of looking only at the return kind. The scan is memoized in `ArrayBufferCopyPolicy` and runs at most once per call, only when a JS-heap buffer is actually converted. - Thread that policy through array and object conversion, so buffers nested inside array/object arguments follow the same alias/copy rules as top-level ones. They were previously always copied. - Make the copy decision, and reject detached buffers, before reading `data()`/`size()`. The scan runs arbitrary JS (accessors, Proxy traps), which could otherwise detach or resize the buffer behind an already-read pointer. - Share one detached check, `detail::throwIfDetached`, with the C++ bridging path, and skip it for free once a runtime has shown it doesn't implement `ArrayBuffer.prototype.detached`. Hermes doesn't, so this drops a property get and a thrown-and-caught exception from every conversion. - Turn a runtime that cannot expose an ArrayBuffer's bytes into a `jsi::JSError` naming the method, instead of letting `std::logic_error` escape through JSI. - Convert `NSException` raised during argument conversion into a `JSError`. That conversion runs outside the `try` in `performMethodInvocation`, and `RCTArrayBuffer` can raise. - Run the caller's `cleanup` block before the designated initializer raises on a NULL/non-zero-length mismatch; nothing else would ever release those bytes. - Normalize `mutableBytes` to NULL for zero-length buffers, so the documented "NULL iff empty" invariant holds for every factory. - Warn, once per class, when `convertObjCObjectToJSIValue` falls through to `undefined` instead of doing so silently. A warning rather than an error: that fallthrough is reached by any module returning an `NSDate`, `NSURL` or custom object, and an `RCTLogError` there would redbox in dev. Build fix: - Migrate the macOS sample TurboModule to `RCTArrayBuffer`. It still used `NSData`/`NSMutableData`, which no longer matches the generated spec. Docs: `RCTArrayBuffer.h` spells out that a non-owning buffer must not be captured in a block, stored, or passed to a callback or promise block, that the framework copies whenever the method signature reveals such an escape, and that a buffer nested in an `NSArray`/`NSDictionary` argument follows the same rules — the one case the ObjC signature does not reveal. Changelog: [iOS][Fixed] - Copy ArrayBuffer arguments in ObjC TurboModules whenever they can outlive the call, including buffers nested in objects and arrays Differential Revision: D115767439
Summary: Work on top of [D115767439](https://www.internalfb.com/intern/diff/115767439/) / hg commit id 9fc956a2d543bd26f04648cb254e4955f040b3b1 and fix any issues still left in the C++, ObjC and Java/Kotlin Array Buffer implementation except these 2 tasks which are handled separatly. [T285167897](https://www.internalfb.com/tasks/T285167897) / [T285167853](https://www.internalfb.com/tasks/T285167853) I want to remove any duplicate code e.g. check if we have redundant subclasses of jsi::MutableBuffer [https://www.internalfb.com/code/search?q=filepath%3Areact-native-github%20repo%3Afbsource%20jsi%3A%3AMutableBuffer](https://www.internalfb.com/code/search?q=filepath%3Areact-native-github%20repo%3Afbsource%20jsi%3A%3AMutableBuffer) We should also align the C++, ObjC and Java/Kotlin implementation if possible: Naming, style, order of methods e.t Differential Revision: D116358593
…oad the correct commit data. Differential Revision: D116345031
…eact#57985) Summary: Pull Request resolved: react#57985 The two RNTester TurboModule example screens had drifted apart, making it hard to compare TurboModule and C++ TurboModule behaviour side by side. Align `SampleTurboModuleExample` with the style already used by `NativeCxxModuleExampleExample`: - Order and group the entries in `_tests` the same way (callback, ArrayBuffer group, `get*` group, promises, `voidFunc`), so the buttons render in the same order on both screens. - Make the `Examples` union match the tests that actually exist; it still listed many entries copied from the C++ example that `SampleTurboModule` does not implement (`getCustomHostObject`, `getSet`, `setMenuItem`, ...) and was missing `getEnum`, `getRootTag` and `getUnsafeObject`. - Add the missing `installJSIBindings` entry to `ErrorExamples` and type `_renderResult` as `Examples | ErrorExamples`. - Surface rejected promises from the error tests in the UI instead of only logging them to the console, matching the other screen. - Fix `getUnsafeObject` to call `getUnsafeObject` instead of `getObject`. - Merge the duplicated `NativeSampleTurboModule` imports and drop a stale Flow suppression. Changelog: [Internal] Differential Revision: D116375214
christophpurrer
force-pushed
the
export-D116375214
branch
from
August 18, 2026 01:06
0e2db48 to
b306383
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
The two RNTester TurboModule example screens had drifted apart, making it hard to
compare TurboModule and C++ TurboModule behaviour side by side. Align
SampleTurboModuleExamplewith the style already used byNativeCxxModuleExampleExample:_teststhe same way (callback, ArrayBuffergroup,
get*group, promises,voidFunc), so the buttons render in the sameorder on both screens.
Examplesunion match the tests that actually exist; it still listedmany entries copied from the C++ example that
SampleTurboModuledoes notimplement (
getCustomHostObject,getSet,setMenuItem, ...) and was missinggetEnum,getRootTagandgetUnsafeObject.installJSIBindingsentry toErrorExamplesand type_renderResultasExamples | ErrorExamples.logging them to the console, matching the other screen.
getUnsafeObjectto callgetUnsafeObjectinstead ofgetObject.NativeSampleTurboModuleimports and drop a stale Flowsuppression.
Changelog:
[Internal]
Differential Revision: D116375214