Repository navigation
fix(ffi/objc): forward off-thread method and function callbacks to the JS thread - #103
NathanWalker wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
This PR fixes four unrelated problems at once, and three of them change behavior outside the Node build. Please split it up. Notes on each part: Context: none of this affects NativeScript apps on iOS. There our runtime owns the engine. A background-thread callback takes the V8 lock and runs JS on its own thread, and Hermes releases its lock during native calls, which is how the VideoToolbox-style deadlock is avoided there. Every framework is also linked at launch, so all classes exist when we register them. In Node we can't do any of that, so the threadsafe function is the only way back to the JS thread. 1. Off-thread method and function callbacks crash. 2. Queueing void callbacks so the caller returns at once.
3. Metadata generator change. 4. 5. Class lookup for lazily loaded frameworks. Also:
|
…e JS thread Methods and C function pointers implemented in JS ran on the caller's thread when invoked from another one, which aborts V8. They now take the same blocking threadsafe-function path blocks use. One threadsafe function per env replaces the one created per block, and each forwarded call runs in its own autorelease pool.
b6b27f6 to
e4c8455
Compare
|
Thanks for the review. I split this into five PRs as suggested:
All the reformatting is dropped. Every PR passes |
Stacked on #102 (
feat/napi-host-runloop-callbacks).This is part 1 of the split requested in review: the off-thread method/function crash fix only. The other parts are now separate PRs:
__releaseNativeCounterpart: feat(ffi/objc): add __releaseNativeCounterpart to the Node-API bridge #113Summary
ENABLE_JS_RUNTIMEbuilds are unchanged.Evidence
macOS 26.6.2 (arm64),
--macos --no-enginebuild. Checks: a JS method invoked withperformSelectorInBackground:withObject:(5 calls), a JS block on a global dispatch queue, a JS C function pointer throughdispatch_async_f, and a second block afterwards.Fatal error in v8::HandleScope::CreateHandle().MACOS_TEST_FFI_BACKEND=napi npm run test:macos: tests=714, failures=0, errors=0, skipped=17 (the napi bridge in engine builds; the changed code is Node-API-only, so this checks engine builds are unaffected)Merge Danger
Door: two-way
Blast Radius: Node-API builds, off-thread callbacks