interop.FunctionReference function passed as a block, then as a function pointer, asserts
Mantenedores costumam responder em até 2 dias
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 22/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- ios, javascript, objective-c
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- JavaScript
- Estrelas
- 150
- Forks
- 44
- Merge médio
- 3d 23h
- PRs com merge (30d)
- 19
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de NativeScript/ios
-
isImplementedInClass leaks the losing sample instance on re-entrant or racing cache populationAberta
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 38/100
NativeScript/ios#459 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 3/5 3-5 dias Facilidade para iniciantes 66/100
NativeScript/ios#414 ·
Mantenedores costumam responder em até 2 dias
-
question
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 34/100
NativeScript/ios#364 · 2 comentários ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 35/100
NativeScript/ios#355 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 25/100
NativeScript/ios#292 · 9 comentários ·
Mantenedores costumam responder em até 2 dias
Todas as issues de NativeScript/ios
Issues semelhantes
-
documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 91/100
githubnext/gh-aw-workshop#4458 ·
Mantenedores costumam responder em até 1 dia
-
Add: CartoonitoAbertacheck:failed feeds:add
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 63/100
iptv-org/database#37390 · 1 comentário ·
Mantenedores costumam responder em até 9 dias
-
bug: directory index route root priority is overwritten when wildcard is falseTalvez já em andamento @TalhaHunter101 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
fastify/fastify-static#617 ·
-
agent/sec-check hive/hosted-available-lke648397-260827-5n31 security
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Tool errors containing cycles or BigInt crash getErrorMessage and replace the original failureAbertafactory-active factory-automatic task-bug-reproduction-success task-identify-harness-labels-done task-identify-issue-type-done
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
vercel/ai#22796 · 2 comentários ·
Mantenedores costumam responder em até 1 dia