|
|
|
@ -28,7 +28,7 @@ impl Value {
|
|
|
|
|
(Self::Null, Self::Null) => true, |
|
|
|
|
|
|
|
|
|
// 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, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 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) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// 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 { |
|
|
|
|
/// 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.
|
|
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
|
return false; |
|
|
|
@ -152,20 +135,20 @@ pub fn same_value(x: &Value, y: &Value) -> bool {
|
|
|
|
|
(Value::Integer(x), Value::Integer(y)) => 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)`,
|
|
|
|
|
/// where `x` and `y` are ECMAScript language values, produces `true` or `false`.
|
|
|
|
|
///
|
|
|
|
|
/// `SameValueZero` differs from SameValue only in its treatment of `+0` and `-0`.
|
|
|
|
|
///
|
|
|
|
|
/// More information:
|
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevaluezero
|
|
|
|
|
pub fn same_value_zero(x: &Value, y: &Value) -> bool { |
|
|
|
|
/// The internal comparison abstract operation `SameValueZero(x, y)`,
|
|
|
|
|
/// where `x` and `y` are ECMAScript language values, produces `true` or `false`.
|
|
|
|
|
///
|
|
|
|
|
/// `SameValueZero` differs from SameValue only in its treatment of `+0` and `-0`.
|
|
|
|
|
///
|
|
|
|
|
/// More information:
|
|
|
|
|
/// - [ECMAScript][spec]
|
|
|
|
|
///
|
|
|
|
|
/// [spec]: https://tc39.es/ecma262/#sec-samevaluezero
|
|
|
|
|
pub fn same_value_zero(x: &Value, y: &Value) -> bool { |
|
|
|
|
if x.get_type() != y.get_type() { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
@ -181,11 +164,11 @@ pub fn same_value_zero(x: &Value, y: &Value) -> bool {
|
|
|
|
|
(Value::Integer(x), Value::Integer(y)) => 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()); |
|
|
|
|
match (x, y) { |
|
|
|
|
(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, |
|
|
|
|
_ => 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) |
|
|
|
|
} |
|
|
|
|