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 ResolveLocale helper #2036

Closed

Conversation

NorbertGarfield
Copy link
Contributor

This Pull Request implements ResolveLocale abstract method. It is required for further InitializeDateTimeFormat development.

It changes the following:

  • Adds several helpers to operate with locale extensions
  • Adds DefaultLocale placeholder
  • Implements BestAvailableLocale and locale matchers
  • Implements UnicodeExtensionsComponents
  • Introduces testing

@codecov
Copy link

codecov bot commented Apr 19, 2022

Codecov Report

Merging #2036 (6a923dc) into main (20f72d1) will increase coverage by 0.14%.
The diff coverage is 63.00%.

@@            Coverage Diff             @@
##             main    #2036      +/-   ##
==========================================
+ Coverage   44.16%   44.31%   +0.14%     
==========================================
  Files         212      212              
  Lines       18812    18912     +100     
==========================================
+ Hits         8309     8380      +71     
- Misses      10503    10532      +29     
Impacted Files Coverage Δ
boa_engine/src/builtins/intl/mod.rs 56.00% <63.00%> (+28.00%) ⬆️
boa_engine/src/realm.rs 38.46% <0.00%> (-7.70%) ⬇️
boa_engine/src/syntax/lexer/template.rs 36.36% <0.00%> (-2.77%) ⬇️
boa_engine/src/environments/compile.rs 40.62% <0.00%> (-1.05%) ⬇️
boa_engine/src/builtins/string/mod.rs 63.55% <0.00%> (+0.07%) ⬆️
boa_engine/src/builtins/number/mod.rs 76.66% <0.00%> (+0.08%) ⬆️
boa_engine/src/object/internal_methods/mod.rs 68.39% <0.00%> (+0.43%) ⬆️
boa_engine/src/string.rs 59.72% <0.00%> (+0.69%) ⬆️
boa_engine/src/builtins/function/mod.rs 30.76% <0.00%> (+0.85%) ⬆️
...ntax/parser/expression/left_hand_side/arguments.rs 37.50% <0.00%> (+2.50%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20f72d1...6a923dc. Read the comment docs.

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution.

I commented on some things but I have some more general comments here.

Instead of working with Strings, it would probably be better to use JsStrings. We plan to switch to UTF-16 strings and these would need to be converted too.

There are some data structures in this code that the spec defines as Records. For example I commented on the return value of ResolveLocale. These are currently either JsValues or JsObjects. I think it would be much better to have them as distinct struct types.

Also available_locales and requested_locales are JsValues but you convert them to objects and then use them as array-like objects. The spec specifies to use a List, so it would be probably better to use a Vec<SomeType> instead.

boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
@NorbertGarfield
Copy link
Contributor Author

@raskad do I need to change '&str' to '&JsString' as well?

boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
@raskad
Copy link
Member

raskad commented Apr 23, 2022

@raskad do I need to change '&str' to '&JsString' as well?

In theory I think yes. But think we can probably fix that later. Currently the most correct thing we could do is to use core::str::encode_utf16 everywhere. For example any (String|str).len() usage is in theory wrong, because it uses utf8. We would need to use (String|str).encode_utf16().count() to get the utf16 length.

But I think this is probably not a top priority for this right now. Let's first get some working code, get some 262 tests to pass and then we can go from there ;)

@raskad raskad added this to the v0.15.0 milestone Apr 24, 2022
@raskad raskad added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics labels Apr 24, 2022
Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

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

Just got my one comment left. Really nice work. Thank you for taking this on!

Copy link
Member

@raskad raskad left a comment

Choose a reason for hiding this comment

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

Thank you, really nice work! I'm really exited for the first intl test to pass ;)

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

Looks very good, just some documentation and Debug derives missing, along with some coding standards improvements.

boa_engine/src/builtins/intl/mod.rs Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/mod.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/tests.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/tests.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/tests.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/tests.rs Outdated Show resolved Hide resolved
boa_engine/src/builtins/intl/tests.rs Outdated Show resolved Hide resolved
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 good to me! :)

Copy link
Member

@Razican Razican left a comment

Choose a reason for hiding this comment

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

It looks great now!

@Razican
Copy link
Member

Razican commented May 4, 2022

bors r+

bors bot pushed a commit that referenced this pull request May 4, 2022
<!---
Thank you for contributing to Boa! Please fill out the template below, and remove or add any
information as you feel neccesary.
--->

This Pull Request implements ResolveLocale abstract method. It is required for further InitializeDateTimeFormat development.

It changes the following:

- Adds several helpers to operate with locale extensions
- Adds DefaultLocale placeholder
- Implements BestAvailableLocale and locale matchers
- Implements UnicodeExtensionsComponents
- Introduces testing
@bors
Copy link

bors bot commented May 4, 2022

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title Implement ResolveLocale helper [Merged by Bors] - Implement ResolveLocale helper May 4, 2022
@bors bors bot closed this May 4, 2022
Razican pushed a commit that referenced this pull request Jun 8, 2022
<!---
Thank you for contributing to Boa! Please fill out the template below, and remove or add any
information as you feel neccesary.
--->

This Pull Request implements ResolveLocale abstract method. It is required for further InitializeDateTimeFormat development.

It changes the following:

- Adds several helpers to operate with locale extensions
- Adds DefaultLocale placeholder
- Implements BestAvailableLocale and locale matchers
- Implements UnicodeExtensionsComponents
- Introduces testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants