feat(engine): support f32 TryFromJs - #5444
Conversation
|
I have a few issues with this one, and they're more philosophical than technical. Two points:
So in the end I'd rather a user converts a JS type to I'm willing to hear a counterargument, but this is actually the reason we've not implemented There is a slight loss of performance when doing integers JsValues to f64 to f32 conversions instead of doing f32 directly, but that's so minimal that I don't think it would matter in a real application. |
|
Yeah, that's fair. One small thing though: Either way I'll close this. Want me to do a quick docs PR instead saying |
|
Sure. As for f32 -> JsValue, there is no loss of precision going from f32 to f64. |
|
Opened the docs PR here: #5455 |
## Summary - Document that `TryFromJs` intentionally omits `f32` because JS numbers are `f64` and the `f32` cast is lossy - Point users at `f64` + explicit `as f32`, `#[boa(from_js_with = "...")]` for derives, or `JsValue::to_f32` for JS-style coercion - Follow-up to the discussion in boa-dev#5444 / boa-dev#5360 ## Test plan - [x] Confirm the new docs render correctly via `cargo doc -p boa_engine --no-deps` - [x] Skim the wording against the rationale in boa-dev#5444 Co-authored-by: Hans Larsen <681969+hansl@users.noreply.github.com>
Fixes #5360.
Summary
TryFromJsforf32TypeErrorfor non-number valuesTesting
cargo test --workspacecargo check --workspace --all-targetscargo test -p boa_enginecargo clippy -p boa_engine --all-targets -- -D warningscargo fmt --all -- --check