-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntoJsValue and TryFromJsValue #1995
Conversation
…value-from-primitives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly agree with the changes, but I think there are some API questions that need to be discussed.
impl<T: IntoJsValue> IntoJsValue for Vec<T> { | ||
fn into_js_value(self, context: &mut Context) -> JsValue { | ||
let js_values = self.into_iter().map(|item| item.into_js_value(context)).collect::<Vec<JsValue>>(); | ||
|
||
Array::create_array_from_list( | ||
js_values, | ||
context | ||
).into() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing Array
is pretty unnecessary, since there's already an API that allows to convert any Iterator<Item=JsValue>
into an array.
https://github.com/boa-dev/boa/blob/main/boa_engine/src/object/jsarray.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm a bit confused on how to do this the right way, can you give me a little code snippet hint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think I see, from_iter would give me a JsArray and then I could get it to a JsValue from there, let me work on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been addressed
Codecov Report
@@ Coverage Diff @@
## main #1995 +/- ##
==========================================
- Coverage 43.50% 43.38% -0.12%
==========================================
Files 220 222 +2
Lines 19962 20014 +52
==========================================
Hits 8684 8684
- Misses 11278 11330 +52
Continue to review full report at Codecov.
|
Closing in favour of #2276. |
I'd love to get feedback on this, especially how I should handle errors and any other idiomatic Rust improvements you'd like me to make (I'm still kind of new to Rust).
This pull request also depends on making the Array builtin public, and in my opinion all of the builtins should be made public. I can open another pull request to make all of those public if I get the go-ahead.
This pull request also depends on implementing my opinion that
i128
,u128
,i64
andu64
should always be converted into a JSbigint
since it's the only native JS number type that will not lose precision. More discussion here: #1991This Pull Request fixes/closes #1975.
It changes the following:
IntoJsValue
trait with many implementationsTryFromJsValue
trait with many implementations