Skip to content

Commit

Permalink
Assert only -0 being an acceptable Value::Float PropertyKey
Browse files Browse the repository at this point in the history
  • Loading branch information
aapoalas committed Dec 17, 2023
1 parent c808d21 commit a12a8b0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions nova_vm/src/ecmascript/types/language/object/property_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ impl TryFrom<Value> for PropertyKey {
fn try_from(value: Value) -> Result<Self, Self::Error> {
match value {
Value::Integer(x) => Ok(PropertyKey::Integer(x)),
Value::Float(x)
if x.fract() == 0.0
&& (SmallInteger::MIN_NUMBER..=SmallInteger::MAX_NUMBER)
.contains(&(x as i64)) =>
{
if let Ok(x) = SmallInteger::try_from(x as i64) {
Ok(PropertyKey::Integer(x))
Value::Float(x) => {
if x == -0.0f32 {
Ok(PropertyKey::Integer(0))
} else if x.fract() == 0.0
&& (SmallInteger::MIN_NUMBER..=SmallInteger::MAX_NUMBER).contains(&(x as i64))
{
unreachable!("Value::Float should not contain safe integers");
} else {
Err(())
}
Expand Down

0 comments on commit a12a8b0

Please sign in to comment.