napi backend: unguarded selector dispatch turns unrecognized selector into process abort (NSException cannot unwind through ffi_call)

オープン
#107 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
40/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
ios, macos, objective-c
領域
backend

調査の方向性

Start in NativeScript/ffi/napi/ClassMember.mm, comparing tryObjCNapiDispatch and objcNativeCall against the respondsToSelector: guard in NativeScript/ffi/shared/jsi/NativeApiJsiInvocation.h (callObjCSelector). Reproduce by calling an instance member the receiver lacks, such as NSView.alloc().init().autoscroll, on a generic-napi macOS build. Done when that call throws a JS error instead of aborting, and resolveInstanceMethod: receivers still dispatch.

索引モデルが issue の本文から書いたものです。

説明

Summary

The napi backend dispatches objc_msgSend without verifying the receiver implements the selector. When metadata names a member the concrete receiver lacks — phantom metagen entries (#106), optional protocol members, SDK drift — the send enters ___forwarding___ → doesNotRecognizeSelector: → objc_exception_throw. The NSException cannot unwind through ffi_call's frames, so the process dies in __cxxabiv1::failed_throw (SIGABRT) before the surrounding @try/@catch — or any JS try/catch — can run.

The jsi backend already guards the same dispatch with respondsToSelector: (NativeScript/ffi/shared/jsi/NativeApiJsiInvocation.h, callObjCSelector). NativeScript/ffi/napi/ClassMember.mm — both tryObjCNapiDispatch (generated-invoker path) and objcNativeCall (ffi/super path) — does not.

Reproduction

macOS arm64, generic-napi build (-DTARGET_ENGINE=none -DNS_FFI_BACKEND=napi), metadata carrying a phantom member (see #106):

NSView.alloc().init().autoscroll

→ -[NSView isAutoscroll]: unrecognized selector sent to instance → libc++abi: terminating due to uncaught exception of type NSException → SIGABRT. More generally, any unrecognized selector reached through bridged dispatch aborts the process rather than raising a JS error.

Expected

Verify respondsToSelector: before self-targeted dispatch (one check per call) and rethrow the unrecognized-selector failure as a JS error — matching the jsi backend's tradeoff: forwarding-only receivers get a JS error, while resolveInstanceMethod: receivers still work because the check triggers method resolution.

Environment

  • NativeScript/runtimes main (verified identical at 5b697b39)
  • Generic napi backend, TARGET_PLATFORM=macos, arm64; same code path ships in the iOS napi runtime.
主要言語
C++
スター
27
フォーク
4
平均マージ
5日 11時間
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NativeScript/runtimes のほかの issue

NativeScript/runtimes の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。