Title: interop.FunctionReference function passed as a block, then as a function pointer, asserts · Issue #503 · NativeScript/ios · GitHub
Open Graph Title: interop.FunctionReference function passed as a block, then as a function pointer, asserts · Issue #503 · NativeScript/ios
X Title: interop.FunctionReference function passed as a block, then as a function pointer, asserts · Issue #503 · NativeScript/ios
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::SetFFIPa...
Open Graph 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...
X 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...
Opengraph URL: https://github.com/NativeScript/ios/issues/503
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"interop.FunctionReference function passed as a block, then as a function pointer, asserts","articleBody":"## Summary\n\nA 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.\n\n## Repro\n\n```js\nconst fn = function () {};\nconst ref = new interop.FunctionReference(fn); // returns fn itself\n\n// Any API taking a block, e.g.:\nNSOperationQueue.mainQueue.addOperationWithBlock(ref);\n\n// Any API taking a C function pointer, e.g. a struct field or a C function parameter\n// typed as a function pointer:\nsomeFunctionTakingAFunctionPointer(ref); // -> tns::Assert(false)\n```\n\n## Cause\n\nBoth wrapper kinds live in the same per-object slot (`tns::SetValue` / `tns::GetValue`):\n\n- `FunctionReference`'s constructor stores a `FunctionReferenceWrapper` on `fn` and registers `fn` with `ObjectManager` (`FunctionReference.cpp`).\n- The block branch of `Interop::SetFFIParams` doesn't recognise a `FunctionReferenceWrapper` as a cached block. It builds a `JSBlock` and overwrites the slot with its `BlockWrapper`. `tns::SetValue` doesn't free the previous wrapper, so the `FunctionReferenceWrapper` leaks, along with the trampoline it may have cached.\n- The function-pointer branch accepts only `Pointer`, `AnonymousFunction` and `FunctionReference` wrappers. With a `BlockWrapper` in the slot it falls through to `tns::Assert(false, isolate)` (`NativeScript/runtime/Interop.mm`, function-pointer branch of `SetFFIParams`).\n\nIn 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.\n\n## Expected\n\nOne function can be used both as a block and as a function pointer. Possible directions:\n- keep the block cache and the FunctionReference state in separate slots;\n- let the block path recognise a `FunctionReferenceWrapper` and keep the block alongside it.\n\nEither 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.\n\n## Context\n\nFound 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.\n","author":{"url":"https://github.com/edusperoni","@type":"Person","name":"edusperoni"},"datePublished":"2026-10-09T18:25:54Z","url":"https://github.com/NativeScript/ios/issues/503"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:af9013d2-d3ff-1ee6-1035-1adf3eb6da8b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA2C:3A347:17FB212:1FB7DCD:6B013C74 |
| html-safe-nonce | 961cbed2cd8ae39b002334b20362dfed0ddced3d7c3e0ba69d12c5f1e74ef046 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTJDOjNBMzQ3OjE3RkIyMTI6MUZCN0RDRDo2QjAxM0M3NCIsInZpc2l0b3JfaWQiOiI3MzY1NjEwNDU2MTg4MjcxNzMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 168ee65322b32e7f5977be11fffd872dbdf995fa0c59f7095c95e0d1bcaba2b6 |
| hovercard-subject-tag | issue:5782792559 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/ios/503/issue_layout |
| twitter:image | https://opengraph.githubassets.com/067c4746f4fc3eaac47d16bf8dd829b1e78ae9918b94f70e8699436ede9e9f8a/NativeScript/ios/issues/503 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/067c4746f4fc3eaac47d16bf8dd829b1e78ae9918b94f70e8699436ede9e9f8a/NativeScript/ios/issues/503 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | edusperoni |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/ios git https://github.com/NativeScript/ios.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 172934359 |
| octolytics-dimension-repository_nwo | NativeScript/ios |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 172934359 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/ios |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width