-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Update Temporal ToIntegerIfIntegral, ToIntegerWithTruncation, and ToPositiveIntegerWithTruncation implementation #4081
base: main
Are you sure you want to change the base?
Conversation
Test262 conformance changes
Fixed tests (111):
Broken tests (35):
|
43bfaf1
to
5e3edf5
Compare
I'm all for having the more specific / representative types in the
I'm not 100% updated on how the current APIs look, but I think instead of silently doing this, there should be helper APIs / types provided by
Does that make sense? |
Definitely agreed! 😄 That's why boa-dev/temporal#131 exists and this is still a draft. The helper functions were primarily to double check the approach was working how I thought it would be in Boa before committing to it. Right now, I'm mostly waiting for reviews on the temporal_rs PR and then this can be updated with the change and switched off draft. |
…ntegerIfIntegral methods to `FiniteF64` (#131) This PR adds the `truncate` method to `FiniteF64`. The main goal of this PR is to provide engines with a better way of truncating and clamping JavaScript numbers. For reference, please see boa-dev/boa#4081. EDIT: Also, add positive truncation method and to integer if integral method.
After looking at the broken tests, one appears to be a regression (case insensitive calendar ids) with a PR submitted on |
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.
Looks good!
Posting this as a draft to hopefully get comments.
TLDR: I'm convinced the way we currently handle converting JsValue to integers in the Temporal implementation is wrong and this is a way to update it.
Baseline issue
Currently, we are using
to_integer_with_truncation
,to_positive_integer_with_truncation
andto_integer_if_integral
to convert values intoi32
. These methods are still hold over from the initial prototype of Temporal prior totemporal_rs
being split off. At the time, I think it was ultimately an optimistic approach, but I'm now fairly certain it's wrong long term and should probably addressed (hence the draft PR) ASAP.Also, every argument being truncated to
i32
negatively impactstemporal_rs
's API by forcing us to keep the values ati32
. This change would allow us to changetemporal_rs
's API, and move it away from onlyi32
.General approach / Order of Operations
So the general approach of this PR is to first get the value and transform it to a
FiniteF64
by callingToNumber()
and checking that it's finite, which was essentially all the previous functions were doing anyways besides the truncation.Once the values are made
FiniteF64
s, we then get the options object and determine theArithmeticOverflow
from the options object. This is needed for the observability tests which may check for the finite check throwing prior to a wrong options object throwing.After the options object, we then truncate the value into the integer type that is expected by
temporal_rs
with the user definedArithmeticOverflow
. If ArithmeticOverflow::Reject and the value is not contained within T::MIN and T::MAX, we throw an early far exceeds range RangeError. If ArithemeticOverflow::Constrain, then we clamp the value to T::MAX or T::MIN.There is also an argument to just always silently constrain the value to T::MAX or T::MIN and let
temporal_rs
handle the error. I think I may like this option more, because it does allow us to truncate early withoutArithmeticOverflow
and deferring truncation to after reading options.Anyways, general thoughts would be appreciated. Technically, this is probably more of a
temporal_rs
leaning PR as I think the currenttruncate
function in this PR should live intemporal_rs
, but it does handle specifically the Boa's glue code to the library.