Browse Source

Fix logical expressions evaluation (#999)

* Fix logical expressions evaluation

* Remove redundant clones

Co-authored-by: tofpie <tofpie@users.noreply.github.com>
pull/1001/head
tofpie 4 years ago committed by GitHub
parent
commit
f34e0b58e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      boa/src/syntax/ast/node/operator/bin_op/mod.rs
  2. 26
      boa/src/value/display.rs

30
boa/src/syntax/ast/node/operator/bin_op/mod.rs

@ -150,18 +150,24 @@ impl Executable for BinOp {
}
}))
}
op::BinOp::Log(op) => {
// turn a `Value` into a `bool`
let to_bool = |value| bool::from(&value);
Ok(match op {
LogOp::And => Value::from(
to_bool(self.lhs().run(context)?) && to_bool(self.rhs().run(context)?),
),
LogOp::Or => Value::from(
to_bool(self.lhs().run(context)?) || to_bool(self.rhs().run(context)?),
),
})
}
op::BinOp::Log(op) => Ok(match op {
LogOp::And => {
let left = self.lhs().run(context)?;
if !left.to_boolean() {
left
} else {
self.rhs().run(context)?
}
}
LogOp::Or => {
let left = self.lhs().run(context)?;
if left.to_boolean() {
left
} else {
self.rhs().run(context)?
}
}
}),
op::BinOp::Assign(op) => match self.lhs() {
Node::Identifier(ref name) => {
let v_a = context

26
boa/src/value/display.rs

@ -48,18 +48,22 @@ macro_rules! print_obj_value {
};
(props of $obj:expr, $display_fn:ident, $indent:expr, $encounters:expr, $print_internals:expr) => {
print_obj_value!(impl $obj, |(key, val)| {
let v = &val
// FIXME: handle accessor descriptors
.as_data_descriptor()
.unwrap()
.value();
if val.is_data_descriptor() {
let v = &val
.as_data_descriptor()
.unwrap()
.value();
format!(
"{:>width$}: {}",
key,
$display_fn(v, $encounters, $indent.wrapping_add(4), $print_internals),
width = $indent,
)
format!(
"{:>width$}: {}",
key,
$display_fn(v, $encounters, $indent.wrapping_add(4), $print_internals),
width = $indent,
)
} else {
// FIXME: handle accessor descriptors
"".to_string()
}
})
};

Loading…
Cancel
Save