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

未关闭
#107 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 小时
30 天内合并 PR
12

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NativeScript/runtimes 的其他 Issue

查看 NativeScript/runtimes 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。