Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRewrite FromJSValConvertible to better support unions #284
Conversation
|
r? @nox |
|
Updated. |
| if value.get().is_null_or_undefined() { | ||
| Ok(None) | ||
| Ok(ConversionResult::Failure(Cow::Owned("Value is null or undefined.".to_owned()))) |
This comment has been minimized.
This comment has been minimized.
emilio
Aug 6, 2016
Member
What's the point of returning a Cow if we only return owned values? Can't this be Cow::Borrowed("Value is null or undefined")?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
emilio
Aug 8, 2016
Member
@GuillaumeGomez: I'm pretty sure being able to return a borrowed cow is the reason for @nox to propose it, can you change it in the relevant places?
This comment has been minimized.
This comment has been minimized.
| } else { | ||
| let result: Result<T, ()> = FromJSValConvertible::from_jsval(cx, value, option); | ||
| result.map(Some) | ||
| match FromJSValConvertible::from_jsval(cx, value, option) { |
This comment has been minimized.
This comment has been minimized.
| @@ -553,7 +576,7 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T | |||
| let iterator = &mut *iterator.root; | |||
|
|
|||
| if !iterator.init(value, ForOfIterator_NonIterableBehavior::ThrowOnNonIterable) { | |||
| return Err(()) | |||
| return Ok(ConversionResult::Failure(Cow::Owned("Not iterable".to_owned()))) | |||
This comment has been minimized.
This comment has been minimized.
Ms2ger
Aug 8, 2016
Collaborator
This doesn't agree with the ThrowOnNonIterable argument passed above. Please keep returning Err(())
|
|
|
Updated. |
| @@ -129,7 +149,7 @@ unsafe fn enforce_range<D>(cx: *mut JSContext, d: f64) -> Result<D, ()> | |||
|
|
|||
| let rounded = d.round(); | |||
| if D::min_value().cast() <= rounded && rounded <= D::max_value().cast() { | |||
| Ok(rounded.cast()) | |||
| Ok(ConversionResult::Success(rounded.cast())) | |||
| } else { | |||
| throw_type_error(cx, "value out of range in an EnforceRange argument"); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors-servo r+ |
|
@bors-servo r+ |
|
|
Rewrite FromJSValConvertible to better support unions Fixes #282. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/284) <!-- Reviewable:end -->
|
|
|
@bors-servo r+ |
|
|
Rewrite FromJSValConvertible to better support unions Fixes #282. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-mozjs/284) <!-- Reviewable:end -->
|
|
GuillaumeGomez commentedAug 5, 2016
•
edited
Fixes #282.
This change is