Title: fix: convert callback results the return type can hold by edusperoni · Pull Request #2097 · NativeScript/android · GitHub
Open Graph Title: fix: convert callback results the return type can hold by edusperoni · Pull Request #2097 · NativeScript/android
X Title: fix: convert callback results the return type can hold by edusperoni · Pull Request #2097 · NativeScript/android
Description: Description Stacked on #2096 (base perf/primitive-callback-returns). That PR added a spec pinning how a JS callback's result converts to each primitive return type, and the spec exposed real crashes, fixed here. A callback result only reached Java when the generic converter happened to produce exactly the declared wrapper type, which is all the generated binding's cast accepts. So these all threw ClassCastException, a crash when it happens on an Android callback: a double callback returning a whole number (return 1); a float callback returning a negative or whole number; a byte/short callback returning any plain number; a char callback returning a string. New rule: a result converts whenever the declared type can hold it. Return type Accepted byte / short / int / long whole numbers in the type's range float 0, NaN, ±Infinity, or a magnitude within float range double any number char a one-character string boolean booleans, and Boolean objects by their value Number objects follow the same rules as numbers. Values the type can't hold still throw, matching the deliberate specs in numericConversionTests.js (an out-of-range long for int, 1e-40 for float): non-whole or out-of-range numbers for integer types; float underflow or overflow; strings for numeric types; numbers for boolean/char. null/undefined/{} still become the default value, and cast markers behave as before. Behavior changes: 35 cells of the 33×8 matrix go from throwing to a value, and one value changes: new Boolean(false) returned true and now returns false. Nothing that converted before now throws. Every changed cell JS value return type before after 0 byte throws ClassCastException 0 0 short throws ClassCastException 0 0 float throws ClassCastException 0.0 0 double throws ClassCastException 0.0 1 byte throws ClassCastException 1 1 short throws ClassCastException 1 1 float throws ClassCastException 1.0 1 double throws ClassCastException 1.0 -1 byte throws ClassCastException -1 -1 short throws ClassCastException -1 -1 float throws ClassCastException -1.0 -1 double throws ClassCastException -1.0 -0 byte throws ClassCastException 0 -0 short throws ClassCastException 0 -0 float throws ClassCastException -0.0 -0 double throws ClassCastException -0.0 2^31 float throws ClassCastException 2.1474836E9 2^31 double throws ClassCastException 2.147483648E9 -2^31-1 float throws ClassCastException -2.1474836E9 -2^31-1 double throws ClassCastException -2.147483649E9 2^40 float throws ClassCastException 1.0995116E12 2^40 double throws ClassCastException 1.099511627776E12 2^60 float throws ClassCastException 1.1529215E18 2^60 double throws ClassCastException 1.152921504606847E18 -1.5 float throws ClassCastException -1.5 NaN float throws ClassCastException NaN Infinity float throws ClassCastException Infinity -Infinity float throws ClassCastException -Infinity -2.5 float throws ClassCastException -2.5 '1' char throws ClassCastException 49 'a' char throws ClassCastException 97 Number(5) byte throws ClassCastException 5 Number(5) short throws ClassCastException 5 Number(5) float throws ClassCastException 5.0 Number(5) double throws ClassCastException 5.0 Boolean(false) boolean true false Does your pull request have unit tests? Yes. testPrimitiveCallbackReturns.js is updated to the new matrix. numericConversionTests.js is unchanged and still passes, including its exception cases. Full suite: 1484 specs, 0 failures. Summary by CodeRabbit New Features JavaScript callbacks now support more return-value conversions for Java primitive types, including booleans, characters, and numeric values. Primitive and boxed values are handled where supported, with range and format checks applied to integral returns. Float and double results now preserve clearer formatting for special values and decimal precision.
Open Graph Description: Description Stacked on #2096 (base perf/primitive-callback-returns). That PR added a spec pinning how a JS callback's result converts to each primitive return type, and the spec exposed real cr...
X Description: Description Stacked on #2096 (base perf/primitive-callback-returns). That PR added a spec pinning how a JS callback's result converts to each primitive return type, and the spec exposed rea...
Opengraph URL: https://github.com/NativeScript/android/pull/2097
X: @github
Domain: github.com
| 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 | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0e9274f3-a312-4515-c56d-3660befc8ede |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9F16:240CD1:204DF0E:2909672:6B017082 |
| html-safe-nonce | 049322c3b772984321f2c7364edd650c96db293a45a8fd80f6513631c5fd46b5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjE2OjI0MENEMToyMDRERjBFOjI5MDk2NzI6NkIwMTcwODIiLCJ2aXNpdG9yX2lkIjoiMjg5MjM0OTM1NjgxMDI2ODgwMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 12ff3ea50e28b8cc621249941b7670a95589ece03b6a29a311f5666ac8944c90 |
| hovercard-subject-tag | pull_request:5215192664 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/NativeScript/android/pull/2097/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | Description Stacked on #2096 (base perf/primitive-callback-returns). That PR added a spec pinning how a JS callback's result converts to each primitive return type, and the spec exposed real cr... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/android git https://github.com/NativeScript/android.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 29137950 |
| octolytics-dimension-repository_nwo | NativeScript/android |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29137950 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/android |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| 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 |
Links:
Viewport: width=device-width