-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Reduce the number of Array
-related panics
#919
Reduce the number of Array
-related panics
#919
Conversation
Array
-related panics
Codecov Report
@@ Coverage Diff @@
## master #919 +/- ##
==========================================
+ Coverage 59.21% 59.36% +0.14%
==========================================
Files 166 166
Lines 10570 10719 +149
==========================================
+ Hits 6259 6363 +104
- Misses 4311 4356 +45
Continue to review full report at Codecov.
|
It still needs some work to handle the cases correctly, but doesnt't panic now
eae799a
to
c0e02d6
Compare
Test262 conformance changes:
|
I think following the advice in this SO post we should avoid conversions with |
Yes, we should not use |
I figured since we're changing this part of the code we could try to clean up this part of the code and as other parts are changed in PRs we can ask that those PRs remove those uses. |
OK, let's do 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.
Looks very good, and I'm loving the new panic count :D
As we mentioned in the comments, it's best if we use a try_from()
when casting, or from()
if possible, to avoid casting issues. Moreover, I see we use wrapping_add()
in many places. I'm not familiar with the spec, but are we sure we should be using a wrapping addition?
Thanks for the reviews and comments!
When reading the ECMA specs I had a feeling that they assume that overflow can't happen, since everywhere they operate on JS I think that the whole length/index mgmt needs to be thought over - the new ECMA draft (30.10) uses I will try to write a little bit longer summary of my findings and dig a little bit deeper in the standard to find out what they assume should be done in this case. |
This might also have to do with the fact that we use integers just as an optimization for numeric types. Working with integers is faster than working with floats, but, of course, they are not spec compliant, so sometimes we have to transform them back to floats. |
I went through the file and changed all the casts to Since now the conversions can fail, we need to map errors. I put the Not all casts are possible. There is no I think most of the above errors will go away if a new type will be introduced that reflects the result of enum IntegerOrInfinity {
Integer(isize),
NegativeInfinity,
PositiveInfinity,
} That way we would not need the Regarding the
|
…fill` and `slice`
0df7f61
to
a86ea85
Compare
For tests, I implemented the Tell me what do you think and I can either revert this or go and change rest of the methods. :) |
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!
Check my comments on how to improve this :)
…rt` and `as_relative_end` to array module
Thanks for the comments! They really did help me get back on track. Now the changes are (I think) more targeted and don't pollute unrelated code. To sum up the changes:
|
Let's merge this. I think all concerns were properly treated :) |
Hello 👋 !
This Pull Request addresses some of the panics in Test262 suite #817, most notably the ones in
Array
module.They (most of the time) boil down to changing
get_field("length").as_number().unwrap()
toget_field("length").to_length(context)
. I needed to addcontext: &mut Context
toconstruct_array
andadd_to_array_object
because of that. I've also added a little bit of+/-Inf
,NaN
and out-of-range checks to the code.Basically, this reduced the number of panics in
Array
part of the test suite to 8 (and these are related todisplay
).The main problem that I see with the changes are the semi-random
usize
/isize
/i32
/f64
casts, but I really don't know what would be best to do with them and would appreciate a little bit of guidance here.