`TryIntoJs` trait and derive macro for it
This Pull Request closes #3874
Notes
- I don't sure about conversion of
HashMapintoJsObject. Should it be converted intoJsMapor into ordinary object{ k1: v1, ..., kN: vN }? Or maybe I need to add a macro attribute to allow choose a way of conversion ofMaptypes?
@HalidOdat
TryFromJs converts JsValue into Rust types, so there will no such type that converts a Rust type via TryFromJs into JsValue.
In std mod we can have an object of any type as value in try_from.
In the definition of the trait we specifically have value: &JsValue.
So
-
TryFromJscan make onlyJsValue --> Rust(value alwaysJsValue) -
TryIntoJscan make onlyRust--> JsValue(result alwaysJsValue)
There is try_js_into fn that do the same as TryFromJs: converts JsValue into Rust type. (self is JsValue)
Codecov Report
Attention: Patch coverage is 33.91304% with 76 lines in your changes missing coverage. Please review.
Project coverage is 52.80%. Comparing base (
6ddc2b4) to head (4be1d56). Report is 276 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| core/macros/src/lib.rs | 0.00% | 52 Missing :warning: |
| core/engine/src/value/conversions/try_into_js.rs | 61.90% | 24 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #3999 +/- ##
==========================================
+ Coverage 47.24% 52.80% +5.55%
==========================================
Files 476 481 +5
Lines 46892 46791 -101
==========================================
+ Hits 22154 24706 +2552
+ Misses 24738 22085 -2653
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I don't sure about conversion of HashMap into JsObject. Should it be converted into JsMap or into ordinary object { k1: v1, ..., kN: vN }? [..]
I should probably be a JsMap by default, it's also more space efficient, since the properties are stored in an hashmap https://github.com/boa-dev/boa/blob/main/core/engine/src/builtins/map/ordered_map.rs#L36-L42, rather that in the shape and object storage.