|
|
@ -28,7 +28,7 @@ impl Value { |
|
|
|
(Self::Null, Self::Null) => true, |
|
|
|
(Self::Null, Self::Null) => true, |
|
|
|
|
|
|
|
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
(_, _) => same_value_non_numeric(self, other), |
|
|
|
(_, _) => Self::same_value_non_numeric(self, other), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -111,32 +111,15 @@ impl Value { |
|
|
|
_ => false, |
|
|
|
_ => false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// This function takes a string and conversts it to BigInt type.
|
|
|
|
/// The internal comparison abstract operation SameValue(x, y),
|
|
|
|
///
|
|
|
|
/// where x and y are ECMAScript language values, produces true or false.
|
|
|
|
/// If the result is `NaN` than `None` is returned.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// More information:
|
|
|
|
/// More information:
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
/// - [ECMAScript reference][spec]
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevalue
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-stringtobigint
|
|
|
|
pub fn same_value(x: &Value, y: &Value) -> bool { |
|
|
|
pub fn string_to_bigint(string: &str) -> Option<BigInt> { |
|
|
|
|
|
|
|
if string.is_empty() { |
|
|
|
|
|
|
|
return Some(BigInt::from(0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigInt::from_str(string) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The internal comparison abstract operation SameValue(x, y),
|
|
|
|
|
|
|
|
/// where x and y are ECMAScript language values, produces true or false.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// More information:
|
|
|
|
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevalue
|
|
|
|
|
|
|
|
pub fn same_value(x: &Value, y: &Value) -> bool { |
|
|
|
|
|
|
|
// 1. If Type(x) is different from Type(y), return false.
|
|
|
|
// 1. If Type(x) is different from Type(y), return false.
|
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -152,20 +135,20 @@ pub fn same_value(x: &Value, y: &Value) -> bool { |
|
|
|
(Value::Integer(x), Value::Integer(y)) => x == y, |
|
|
|
(Value::Integer(x), Value::Integer(y)) => x == y, |
|
|
|
|
|
|
|
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
(_, _) => same_value_non_numeric(x, y), |
|
|
|
(_, _) => Self::same_value_non_numeric(x, y), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The internal comparison abstract operation `SameValueZero(x, y)`,
|
|
|
|
/// The internal comparison abstract operation `SameValueZero(x, y)`,
|
|
|
|
/// where `x` and `y` are ECMAScript language values, produces `true` or `false`.
|
|
|
|
/// where `x` and `y` are ECMAScript language values, produces `true` or `false`.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// `SameValueZero` differs from SameValue only in its treatment of `+0` and `-0`.
|
|
|
|
/// `SameValueZero` differs from SameValue only in its treatment of `+0` and `-0`.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// More information:
|
|
|
|
/// More information:
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevaluezero
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevaluezero
|
|
|
|
pub fn same_value_zero(x: &Value, y: &Value) -> bool { |
|
|
|
pub fn same_value_zero(x: &Value, y: &Value) -> bool { |
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -181,11 +164,11 @@ pub fn same_value_zero(x: &Value, y: &Value) -> bool { |
|
|
|
(Value::Integer(x), Value::Integer(y)) => x == y, |
|
|
|
(Value::Integer(x), Value::Integer(y)) => x == y, |
|
|
|
|
|
|
|
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
// 3. Return ! SameValueNonNumeric(x, y).
|
|
|
|
(_, _) => same_value_non_numeric(x, y), |
|
|
|
(_, _) => Self::same_value_non_numeric(x, y), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn same_value_non_numeric(x: &Value, y: &Value) -> bool { |
|
|
|
fn same_value_non_numeric(x: &Value, y: &Value) -> bool { |
|
|
|
debug_assert!(x.get_type() == y.get_type()); |
|
|
|
debug_assert!(x.get_type() == y.get_type()); |
|
|
|
match (x, y) { |
|
|
|
match (x, y) { |
|
|
|
(Value::Null, Value::Null) | (Value::Undefined, Value::Undefined) => true, |
|
|
|
(Value::Null, Value::Null) | (Value::Undefined, Value::Undefined) => true, |
|
|
@ -195,4 +178,21 @@ fn same_value_non_numeric(x: &Value, y: &Value) -> bool { |
|
|
|
(Value::Symbol(ref x), Value::Symbol(ref y)) => x == y, |
|
|
|
(Value::Symbol(ref x), Value::Symbol(ref y)) => x == y, |
|
|
|
_ => false, |
|
|
|
_ => false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// This function takes a string and conversts it to BigInt type.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// If the result is `NaN` than `None` is returned.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// More information:
|
|
|
|
|
|
|
|
/// - [ECMAScript reference][spec]
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-stringtobigint
|
|
|
|
|
|
|
|
pub fn string_to_bigint(string: &str) -> Option<BigInt> { |
|
|
|
|
|
|
|
if string.is_empty() { |
|
|
|
|
|
|
|
return Some(BigInt::from(0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BigInt::from_str(string) |
|
|
|
} |
|
|
|
} |
|
|
|