napi backend: incoming ObjC blocks are bridged without retention — async completion/decision handlers die after the delegate returns

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
cpp, objective-c
领域
backend

调研方向

The payload names no files. Start from the code that marshals incoming ObjC block parameters into JS FunctionPointer values, and check whether it retains the block. The fix must either copy the block (_Block_copy, released when the JS handle is released) or document the call-before-return limit. Done means an async JS call to a completion handler still works after the delegate returns, without the WebKit CompletionHandlerCallChecker abort. The maintainers have not chosen between copying and documenting, so confirm that choice before writing code.

由索引模型根据 Issue 内容生成。

描述

Summary

ObjC blocks that arrive as method parameters — completion handlers and decision handlers — are marshalled to JS as FunctionPointers over the raw NSBlock*, with no _Block_copy/retention. The block is only guaranteed alive for the duration of the delegate call; a JS caller that invokes it asynchronously — the standard pattern for WKUIDelegate runJavaScript*Panel/openPanel handlers, webView:requestMediaCapturePermissionFor… decisions, photo/auth completion handlers, and the like — dereferences a dead block. WebKit's CompletionHandlerCallChecker then aborts the process ("completion handler was not called") when its block deallocates un-invoked.

Expected

Either copy incoming blocks when marshalling them to JS — so a JS-held FunctionPointer keeps the handler alive until explicitly released — or expose/document the call-before-return constraint. Today the pointer looks callable indefinitely; there is no lifetime signal until the abort.

Workaround we run: grab the raw pointer (__ns_native_ptr) and _Block_copy/_Block_release around the async call window.

Environment

  • NativeScript/runtimes 5b697b39, generic napi backend, TARGET_PLATFORM=macos (the same block-marshalling path ships in the iOS napi runtime, where async WKUIDelegate/PHPhotoLibrary-style completions hit the same lifetime gap)
主要语言
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 摘要。