Browse Source

Added comma operator

pull/589/head
KashParty 4 years ago
parent
commit
dbb39862d6
  1. 4
      boa/src/exec/operator/mod.rs
  2. 4
      boa/src/syntax/ast/op.rs
  3. 1
      boa/src/syntax/ast/punctuator.rs
  4. 2
      boa/src/syntax/parser/expression/assignment/mod.rs

4
boa/src/exec/operator/mod.rs

@ -139,6 +139,10 @@ impl Executable for BinOp {
} }
_ => Ok(Value::undefined()), _ => Ok(Value::undefined()),
}, },
op::BinOp::Comma => {
self.lhs().run(interpreter)?;
Ok(self.rhs().run(interpreter)?)
},
} }
} }
} }

4
boa/src/syntax/ast/op.rs

@ -705,6 +705,9 @@ pub enum BinOp {
/// ///
/// see: [`AssignOp`](enum.AssignOp.html). /// see: [`AssignOp`](enum.AssignOp.html).
Assign(AssignOp), Assign(AssignOp),
/// Comma operation.
Comma,
} }
impl From<NumOp> for BinOp { impl From<NumOp> for BinOp {
@ -748,6 +751,7 @@ impl Display for BinOp {
Self::Comp(ref op) => op.to_string(), Self::Comp(ref op) => op.to_string(),
Self::Log(ref op) => op.to_string(), Self::Log(ref op) => op.to_string(),
Self::Assign(ref op) => op.to_string(), Self::Assign(ref op) => op.to_string(),
Self::Comma => ",".to_string(),
} }
) )
} }

1
boa/src/syntax/ast/punctuator.rs

@ -167,6 +167,7 @@ impl Punctuator {
Self::LeftSh => Some(BinOp::Bit(BitOp::Shl)), Self::LeftSh => Some(BinOp::Bit(BitOp::Shl)),
Self::RightSh => Some(BinOp::Bit(BitOp::Shr)), Self::RightSh => Some(BinOp::Bit(BitOp::Shr)),
Self::URightSh => Some(BinOp::Bit(BitOp::UShr)), Self::URightSh => Some(BinOp::Bit(BitOp::UShr)),
Self::Comma => Some(BinOp::Comma),
_ => None, _ => None,
} }
} }

2
boa/src/syntax/parser/expression/assignment/mod.rs

@ -116,7 +116,7 @@ impl TokenParser for AssignmentExpression {
TokenKind::Punctuator(Punctuator::Assign) => { TokenKind::Punctuator(Punctuator::Assign) => {
lhs = Assign::new(lhs, self.parse(cursor)?).into(); lhs = Assign::new(lhs, self.parse(cursor)?).into();
} }
TokenKind::Punctuator(p) if p.as_binop().is_some() => { TokenKind::Punctuator(p) if p.as_binop().is_some() && p != Punctuator::Comma => {
let expr = self.parse(cursor)?; let expr = self.parse(cursor)?;
let binop = p.as_binop().expect("binop disappeared"); let binop = p.as_binop().expect("binop disappeared");
lhs = BinOp::new(binop, lhs, expr).into(); lhs = BinOp::new(binop, lhs, expr).into();

Loading…
Cancel
Save