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

Simplify the number unboxing logic #43271

Closed
wants to merge 3 commits into from

Conversation

lewing
Copy link
Member

@lewing lewing commented Oct 11, 2020

From the js binding perspective all of these types are numbers (see the method binding) so treat them that way.

@kg
Copy link
Member

kg commented Oct 11, 2020

This stops being a good idea once i64/u64 support is added, though, because those aren't Number

@lewing
Copy link
Member Author

lewing commented Oct 11, 2020

longs will have to be handled specially in any case. This preserves the current behavior while simplifying code.

@lewing lewing force-pushed the wasm-unbox-number branch from 63faddc to 576cd53 Compare October 12, 2020 23:46
Copy link
Member

@kg kg left a comment

Choose a reason for hiding this comment

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

Other than my comments, seems fine - let's wait until my bindings optimizations are landed before landing this since they will conflict.

if (d >= int.MinValue && d <= int.MaxValue)
return (int)d;
else if (d >= uint.MinValue && d <= uint.MaxValue)
return (uint)d;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this. We're arbitrarily deciding whether a number should be signed or not based on ranges, this is going to cause reflective code like x = (int)obj to break for no obvious reason. I guess we could tell the end-user to just use Convert.xxx methods...

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like it either, this works in more cases than the current code.

Copy link
Member Author

@lewing lewing Oct 14, 2020

Choose a reason for hiding this comment

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

To clarify, this code is only called by the number boxing code on the js side which does an even less effective check and would require another method binding to achieve the same result (while this removes one),

src/mono/wasm/runtime/binding_support.js Show resolved Hide resolved
@lewing
Copy link
Member Author

lewing commented Oct 14, 2020

blocked against #41808 which is prefered

@lewing lewing added the blocked Issue/PR is blocked on something - see comments label Oct 14, 2020
@lewing lewing closed this Oct 23, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-System.Runtime.InteropServices.JavaScript blocked Issue/PR is blocked on something - see comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants