interop.FunctionReference function passed as a block, then as a function pointer, asserts
维护者通常 2 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 22/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- ios, javascript, objective-c
调研方向
Start in NativeScript/runtime/Interop.mm, in the block branch and the function-pointer branch of Interop::SetFFIParams, and in FunctionReference.cpp, where the constructor stores a FunctionReferenceWrapper on the function. Reproduce with the block-then-pointer order and confirm the tns::Assert(false) fires. Done means both wrappers can coexist on one function, or the pointer path throws a JS error instead of asserting, with the worker test from #500 still passing.
由索引模型根据 Issue 内容生成。
描述
Summary
A function wrapped with interop.FunctionReference and then passed to a native API as a block loses its FunctionReference identity. A later attempt to pass it as a function pointer then hits tns::Assert(false) in Interop::SetFFIParams, which crashes the app.
Repro
const fn = function () {};
const ref = new interop.FunctionReference(fn); // returns fn itself
// Any API taking a block, e.g.:
NSOperationQueue.mainQueue.addOperationWithBlock(ref);
// Any API taking a C function pointer, e.g. a struct field or a C function parameter
// typed as a function pointer:
someFunctionTakingAFunctionPointer(ref); // -> tns::Assert(false)
Cause
Both wrapper kinds live in the same per-object slot (tns::SetValue / tns::GetValue):
FunctionReference's constructor stores aFunctionReferenceWrapperonfnand registersfnwithObjectManager(FunctionReference.cpp).- The block branch of
Interop::SetFFIParamsdoesn't recognise aFunctionReferenceWrapperas a cached block. It builds aJSBlockand overwrites the slot with itsBlockWrapper.tns::SetValuedoesn't free the previous wrapper, so theFunctionReferenceWrapperleaks, along with the trampoline it may have cached. - The function-pointer branch accepts only
Pointer,AnonymousFunctionandFunctionReferencewrappers. With aBlockWrapperin the slot it falls through totns::Assert(false, isolate)(NativeScript/runtime/Interop.mm, function-pointer branch ofSetFFIParams).
In the opposite order (block first, then new interop.FunctionReference(fn)), the constructor overwrites the block's wrapper. Every later block marshal of fn then builds a new block instead of reusing the cached one, and the next one overwrites the FunctionReferenceWrapper again.
Expected
One function can be used both as a block and as a function pointer. Possible directions:
- keep the block cache and the FunctionReference state in separate slots;
- let the block path recognise a
FunctionReferenceWrapperand keep the block alongside it.
Either way, neither marshal should evict the other's wrapper, and the function-pointer path should never assert on a wrapper type it can explain to the user. At minimum it should throw a JS error instead.
Context
Found while reviewing #500, which makes JS block wrappers owned by their JSBlock. The worker test added there (blockFunctionReferenceWorker.js) relies on the current overwrite behaviour to reach the teardown path.
- 主要语言
- JavaScript
- 星标
- 150
- 派生
- 44
- 平均合并
- 3 天 23 小时
- 30 天内合并 PR
- 19
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NativeScript/ios 的其他 Issue
-
难度 5/5 一周以上 新手友好度 38/100
NativeScript/ios#459 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 3/5 3-5 天 新手友好度 66/100
NativeScript/ios#414 ·
维护者通常 2 天内回复
-
question
难度 4/5 3-5 天 新手友好度 34/100
NativeScript/ios#364 · 2 条评论 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
NativeScript/ios#355 ·
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
NativeScript/ios#292 · 9 条评论 ·
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
dusk-network/exu#17 ·
-
难度 1/5 1 小时以内 新手友好度 88/100
jspreadsheet/ce#1809 ·
-
documentation
难度 1/5 1 小时以内 新手友好度 91/100
githubnext/gh-aw-workshop#4458 ·
维护者通常 1 天内回复
-
Add: Cartoonito未关闭check:failed feeds:add
难度 2/5 1-3 小时 新手友好度 63/100
iptv-org/database#37390 · 1 条评论 ·
维护者通常 9 天内回复
-
bug: directory index route root priority is overwritten when wildcard is false可能已有人在做 @TalhaHunter101 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
fastify/fastify-static#617 ·