Skip to content

Commit

Permalink
Removed strict parameter in SameValue function.
Browse files Browse the repository at this point in the history
The `SameValue` function is not dependent on strict mode.
  • Loading branch information
HalidOdat committed Jun 22, 2020
1 parent 2853b5a commit 02e8ce4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
3 changes: 1 addition & 2 deletions boa/src/builtins/boolean/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ fn instances_have_correct_proto_set() {

assert!(same_value(
&bool_instance.get_internal_slot("__proto__"),
&bool_prototype,
true
&bool_prototype
));
}
7 changes: 2 additions & 5 deletions boa/src/builtins/json/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,10 @@ fn json_parse_sets_prototypes() {
.get_field("Array")
.get_field(PROTOTYPE);
assert_eq!(
same_value(&object_prototype, &global_object_prototype, true),
true
);
assert_eq!(
same_value(&array_prototype, &global_array_prototype, true),
same_value(&object_prototype, &global_object_prototype),
true
);
assert_eq!(same_value(&array_prototype, &global_array_prototype), true);
}

#[test]
Expand Down
17 changes: 4 additions & 13 deletions boa/src/builtins/object/internal_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ impl Object {
&& !same_value(
&desc.value.clone().unwrap(),
&current.value.clone().unwrap(),
false,
)
{
return false;
Expand All @@ -247,21 +246,13 @@ impl Object {
} else {
if !current.configurable.unwrap() {
if desc.set.is_some()
&& !same_value(
&desc.set.clone().unwrap(),
&current.set.clone().unwrap(),
false,
)
&& !same_value(&desc.set.clone().unwrap(), &current.set.clone().unwrap())
{
return false;
}

if desc.get.is_some()
&& !same_value(
&desc.get.clone().unwrap(),
&current.get.clone().unwrap(),
false,
)
&& !same_value(&desc.get.clone().unwrap(), &current.get.clone().unwrap())
{
return false;
}
Expand Down Expand Up @@ -342,7 +333,7 @@ impl Object {
pub fn set_prototype_of(&mut self, val: Value) -> bool {
debug_assert!(val.is_object() || val.is_null());
let current = self.get_internal_slot(PROTOTYPE);
if same_value(&current, &val, false) {
if same_value(&current, &val) {
return true;
}
if !self.is_extensible() {
Expand All @@ -353,7 +344,7 @@ impl Object {
while !done {
if p.is_null() {
done = true
} else if same_value(&Value::from(self.clone()), &p, false) {
} else if same_value(&Value::from(self.clone()), &p) {
return false;
} else {
p = p.get_internal_slot(PROTOTYPE);
Expand Down
6 changes: 2 additions & 4 deletions boa/src/builtins/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,11 @@ pub fn make_object(_: &Value, args: &[Value], ctx: &mut Interpreter) -> ResultVa
}

/// Uses the SameValue algorithm to check equality of objects
pub fn is(_: &mut Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
pub fn is(_: &Value, args: &[Value], _: &mut Interpreter) -> ResultValue {
let x = args.get(0).cloned().unwrap_or_else(Value::undefined);
let y = args.get(1).cloned().unwrap_or_else(Value::undefined);

let result = same_value(&x, &y, false);

Ok(Value::boolean(result))
Ok(same_value(&x, &y).into())
}

/// Get the `prototype` of an object.
Expand Down
21 changes: 12 additions & 9 deletions boa/src/builtins/value/equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ pub fn string_to_bigint(string: &str) -> Option<BigInt> {
/// The internal comparison abstract operation SameValue(x, y),
/// where x and y are ECMAScript language values, produces true or false.
///
/// https://tc39.es/ecma262/#sec-samevalue
/// strict mode currently compares the pointers
// FIXME: I dont need to have strict
pub fn same_value(x: &Value, y: &Value, _strict: bool) -> bool {
/// 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;
Expand All @@ -161,13 +162,15 @@ pub fn same_value(x: &Value, y: &Value, _strict: bool) -> 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.
/// The internal comparison abstract operation `SameValueZero(x, y)`,
/// where `x` and `y` are ECMAScript language values, produces `true` or `false`.
///
/// Such a comparison is performed as follows:
/// `SameValueZero` differs from SameValue only in its treatment of `+0` and `-0`.
///
/// More information:
/// - [ECMAScript][spec]
///
/// <https://tc39.es/ecma262/#sec-samevaluezero>
/// [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;
Expand Down

0 comments on commit 02e8ce4

Please sign in to comment.