Skip to content
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

[Merged by Bors] - Implement TryFromJs for JsObject wrappers #2809

Closed
wants to merge 5 commits into from

Conversation

Razican
Copy link
Member

@Razican Razican commented Apr 11, 2023

This change allows using built-in JsObject wrappers with the TryFromJs logic, which makes it easier to derive it in complex objects containing known built-ins, being able to use all the power of the wrappers even inside complex structures.

It changes the following:

  • Implements TryFromJs for all JsObject wrappers , except for JsProxy and Js<Int>Array wrappers -> This has now been added.
  • Adds checker functions for individual typed array objects.
  • Adds some missing checker functions from Object to JsObject

The reason for not implementing it for JsProxy is that we don't have a way (as far as I can tell) to know if a JsObject is a Proxy object. The reason for the typed arrays (note that JsTypedArray implements TryFromJs) is that I didn't find an easy way to know which type of typed array a JsObject was. Do we have a way of using a JsObject to create a Rust JsUint8Array or the like?

@github-actions
Copy link

Test262 conformance changes

Test result main count PR count difference
Total 94,781 94,781 0
Passed 71,403 71,403 0
Ignored 17,824 17,824 0
Failed 5,554 5,554 0
Panics 0 0 0
Conformance 75.33% 75.33% 0.00%

@codecov
Copy link

codecov bot commented Apr 11, 2023

Codecov Report

Merging #2809 (50e9e1e) into main (2f580bb) will decrease coverage by 0.25%.
The diff coverage is 0.96%.

@@            Coverage Diff             @@
##             main    #2809      +/-   ##
==========================================
- Coverage   51.31%   51.07%   -0.25%     
==========================================
  Files         416      416              
  Lines       41213    41407     +194     
==========================================
- Hits        21149    21148       -1     
- Misses      20064    20259     +195     
Impacted Files Coverage Δ
boa_engine/src/object/builtins/jsarraybuffer.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsdataview.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsdate.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsfunction.rs 52.63% <0.00%> (-47.37%) ⬇️
boa_engine/src/object/builtins/jsgenerator.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsmap.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsmap_iterator.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jspromise.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsproxy.rs 0.00% <0.00%> (ø)
boa_engine/src/object/builtins/jsregexp.rs 0.00% <0.00%> (ø)
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@HalidOdat
Copy link
Member

HalidOdat commented Apr 11, 2023

The reason for not implementing it for JsProxy is that we don't have a way (as far as I can tell) to know if a JsObject is a Proxy object.

Wouldn't Object::is_proxy() solve this ?

The reason for the typed arrays (note that JsTypedArray implements TryFromJs) is that I didn't find an easy way to know which type of typed array a JsObject was.

I think this can be done by getting the IntegerIndexed type from ObjectKind through 'obj.data' then from IntegerIndexed get .typed_array_name which is a flat enum containing all the typed arrays kinds https://github.com/boa-dev/boa/blob/main/boa_engine/src/builtins/typed_array/mod.rs#L3503-L3516

It's not that intuitive, we should probably have helper methods

Do we have a way of using a JsObject to create a Rust JsUint8Array or the like?

We have from JsObject to JsTypedArray but not into the individial typed array kinds, seems like a useful feature that we should probably implement, I'll create an issue about it :)

@Razican
Copy link
Member Author

Razican commented Apr 11, 2023

The reason for not implementing it for JsProxy is that we don't have a way (as far as I can tell) to know if a JsObject is a Proxy object.

Wouldn't Object::is_proxy() solve this ?

Indeed, it was just not available at the JsObject level. I have made it (and others) available at this level.

The reason for the typed arrays (note that JsTypedArray implements TryFromJs) is that I didn't find an easy way to know which type of typed array a JsObject was.

I think this can be done by getting the IntegerIndexed type from ObjectKind through 'obj.data' then from IntegerIndexed get .typed_array_name which is a flat enum containing all the typed arrays kinds https://github.com/boa-dev/boa/blob/main/boa_engine/src/builtins/typed_array/mod.rs#L3503-L3516

It's not that intuitive, we should probably have helper methods

I have added them :)

Do we have a way of using a JsObject to create a Rust JsUint8Array or the like?

We have from JsObject to JsTypedArray but not into the individial typed array kinds, seems like a useful feature that we should probably implement, I'll create an issue about it :)

No need to create an issue, I have added it to this PR :)

Copy link
Member

@HalidOdat HalidOdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect to me! :)

boa_engine/src/object/builtins/jsdate.rs Outdated Show resolved Hide resolved
Co-authored-by: raskad <32105367+raskad@users.noreply.github.com>
@raskad
Copy link
Member

raskad commented Apr 11, 2023

bors r+

bors bot pushed a commit that referenced this pull request Apr 11, 2023
This change allows using built-in `JsObject` wrappers with the `TryFromJs` logic, which makes it easier to derive it in complex objects containing known built-ins, being able to use all the power of the wrappers even inside complex structures.

It changes the following:

 * Implements `TryFromJs` for all `JsObject` wrappers ~, except for `JsProxy` and `Js<Int>Array` wrappers~ -> This has now been added.
 *  Adds checker functions for individual typed array objects.
 * Adds some missing checker functions from `Object` to `JsObject`

~The reason for not implementing it for `JsProxy` is that we don't have a way (as far as I can tell) to know if a `JsObject` is a `Proxy` object. The reason for the typed arrays (note that `JsTypedArray` implements `TryFromJs`) is that I didn't find an easy way to know which type of typed array a `JsObject` was. Do we have a way of using a `JsObject` to create a Rust `JsUint8Array` or the like?~
@bors
Copy link

bors bot commented Apr 11, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Implement TryFromJs for JsObject wrappers [Merged by Bors] - Implement TryFromJs for JsObject wrappers Apr 11, 2023
@bors bors bot closed this Apr 11, 2023
@bors bors bot deleted the conversions branch April 11, 2023 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants