-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[dotnet] Handle negative zero BiDi response #15898
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
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
/// Serializes and deserializes <see cref="double"/> into a | ||
/// <see href="https://w3c.github.io/webdriver-bidi/#type-script-PrimitiveProtocolValue">BiDi spec-compliant number value</see>. | ||
/// </summary> | ||
internal sealed class BiDiDoubleConverter : JsonConverter<double> |
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.
I don't like BiDi
entry in the name because it is already in BiDi namespace. Just DoubleConverter
looks better, but it seems so abstract name. Probably SpecialNumberConverter
is perfect?
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.
I chose BiDiDouble
because it follows BiDi's unique concept of "number". The logic is unique to the BiDi spec.
I think you are right about Double
though.
I like BiDiNumberConverter
. What do you think of 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.
I have even better proposal:
- Declare two converters:
NumberLocalValueConverter
/NumberRemoteValueConverter
which convertsNumberLocalValue
/NumberRemoteValue
types (as I remember local value can be serialized only, remote - deserialized) - Register it globally in one place
It makes naming clearer, and it allows to use the same approach for all converters where all of them are still global. I still remember our challenge #15329 (comment). At least in this PR we don't not introduce new knowledge and follows current patterns.
dotnet/src/webdriver/BiDi/Communication/Json/Converters/BiDiDoubleConverter.cs
Show resolved
Hide resolved
|
||
var str = reader.GetString() ?? throw new JsonException(); | ||
|
||
if (str.Equals("-0", StringComparison.Ordinal)) |
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.
InvariantCulture
better? At least this comparer is used in json everywhere.
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.
An in other places please.
return d; | ||
} | ||
|
||
var str = reader.GetString() ?? throw new JsonException(); |
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.
We need a message what is going wrong.
writer.WriteNumberValue(value); | ||
} | ||
|
||
static bool IsNegativeZero(double x) |
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.
I guess this method is unnecessary. Based on your comment you rely on ==
operator in unit tests. I hope there is simple way to do it better.
Thanks Mike, in general this approach looks good, let's review minor comments. |
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.
In Pr description you mentioned:
// BiDi returns special numbers such as "NaN" as strings
// Additionally, -0 is returned as a string "-0"
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals | JsonNumberHandling.AllowReadingFromString,
I propose to remove it. My strong opinion: we should understand what we are doing.
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.
It seems like "we enable all serializations features supported by system.text.json, but we don't know whether it is necessary".
User description
🔗 Related Issues
Per resolution in w3c/webdriver-bidi#887
💥 What does this PR do?
Allow handling of "-0" as a response value, with the understanding that this is intended behavior from BiDi.
🔧 Implementation Notes
Note that
Broker.cs
retains handling of numbers-as-strings, even if that is strictly speaking, not necessary to keep around.I personally do not see the harm in keeping this as is, but I do not have a strong opinion.
selenium/dotnet/src/webdriver/BiDi/Communication/Broker.cs
Lines 69 to 71 in 9be77c1
💡 Additional Considerations
🔄 Types of changes
PR Type
Bug fix
Description
• Add BiDi JSON converter for handling negative zero double values
• Enable proper serialization/deserialization of special double values (-0, NaN, Infinity)
• Remove browser-specific test ignores for negative zero handling
Changes walkthrough 📝
BiDiDoubleConverter.cs
Add BiDi double JSON converter
dotnet/src/webdriver/BiDi/Communication/Json/Converters/BiDiDoubleConverter.cs
• Create new JSON converter for BiDi double values
• Handle special
cases: -0, NaN, Infinity, -Infinity
• Implement bit pattern comparison
for negative zero detection
• Provide spec-compliant
serialization/deserialization
LocalValue.cs
Apply double converter to LocalValue
dotnet/src/webdriver/BiDi/Script/LocalValue.cs
• Apply BiDiDoubleConverter to NumberLocalValue double property
• Add
converter import statement
RemoteValue.cs
Apply double converter to RemoteValue
dotnet/src/webdriver/BiDi/Script/RemoteValue.cs
• Apply BiDiDoubleConverter to NumberRemoteValue double property
• Add
converter import statement
CallFunctionLocalValueTest.cs
Remove negative zero test ignores
dotnet/test/common/BiDi/Script/CallFunctionLocalValueTest.cs
• Remove browser-specific test ignores for Chrome and Edge
• Enable
negative zero test for all browsers