interop.FunctionReference function passed as a block, then as a function pointer, asserts
Les mainteneurs répondent en général sous 2 jours
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 22/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- ios, javascript, objective-c
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- JavaScript
- Étoiles
- 150
- Forks
- 44
- Merge moyen
- 3 j 23 h
- PR mergées (30 j)
- 19
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de NativeScript/ios
-
isImplementedInClass leaks the losing sample instance on re-entrant or racing cache populationOuverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
NativeScript/ios#459 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 3/5 3-5 jours Accessibilité débutants 66/100
NativeScript/ios#414 ·
Les mainteneurs répondent en général sous 2 jours
-
question
Difficulté 4/5 3-5 jours Accessibilité débutants 34/100
NativeScript/ios#364 · 2 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
NativeScript/ios#355 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
NativeScript/ios#292 · 9 commentaires ·
Les mainteneurs répondent en général sous 2 jours
Toutes les issues de NativeScript/ios
Issues similaires
-
Notifications pagination accepts NaN and negative LIMIT/OFFSETPeut-être pris @Senthil455 l’a pris aujourd’hui. OuverteBUGS MEDIUM
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
elixpo/blogs.elixpo#419 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
immich-app/immich#32426 ·
Les mainteneurs répondent en général sous 1 jour
-
automated issue report
Difficulté 1/5 Moins d'une heure Accessibilité débutants 70/100
lirantal/discoprint#45 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
scanaislop/aislop#482 ·
Les mainteneurs répondent en général sous 1 jour