interop.FunctionReference function passed as a block, then as a function pointer, asserts
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 22/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- ios, javascript, objective-c
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 150
- Forks
- 44
- Ø Merge
- 3 T. 23 Std.
- Gemergte PRs (30 T.)
- 19
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus NativeScript/ios
-
isImplementedInClass leaks the losing sample instance on re-entrant or racing cache populationOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 38/100
NativeScript/ios#459 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 3/5 3-5 Tage Anfängerfreundlichkeit 66/100
NativeScript/ios#414 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
question
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 34/100
NativeScript/ios#364 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
NativeScript/ios#355 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
NativeScript/ios#292 · 9 Kommentare ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in NativeScript/ios
Ähnliche Issues
-
needs-website-changes
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Feature] 已有证书托管支持拖拽上传Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 63/100
-
[Bug]: [A11y] Missing accessible name on icon-only standalone links (WCAG 2.1 SC 2.4.4, 4.1.2)Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
jaegertracing/jaeger-ui#4596 ·
Maintainer antworten meist innerhalb von 1 Tag
-
channels:add check:passed
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 9 Tagen