Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for >>>= #711

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boa/src/exec/operator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl BinOp {
AssignOp::Xor => x.bitxor(&y, interpreter),
AssignOp::Shl => x.shl(&y, interpreter),
AssignOp::Shr => x.shr(&y, interpreter),
AssignOp::Ushr => x.ushr(&y, interpreter),
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion boa/src/syntax/ast/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,18 @@ pub enum AssignOp {
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Right_shift_assignment
Shr,
// TODO: Add UShl (unsigned shift left).

/// The unsigned right shift assignment operator moves the specified amount of bits to the right and assigns the result to the variable.
///
/// Syntax: `x >>>= y`
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#prod-AssignmentOperator
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unsigned_right_shift_assignment
Ushr,
}

unsafe impl Trace for AssignOp {
Expand All @@ -962,6 +973,7 @@ impl Display for AssignOp {
Self::Xor => "^=",
Self::Shl => "<<=",
Self::Shr => ">>=",
Self::Ushr => ">>>=",
}
)
}
Expand Down
1 change: 1 addition & 0 deletions boa/src/syntax/ast/punctuator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ impl Punctuator {
Self::AssignPow => Some(BinOp::Assign(AssignOp::Exp)),
Self::AssignRightSh => Some(BinOp::Assign(AssignOp::Shr)),
Self::AssignSub => Some(BinOp::Assign(AssignOp::Sub)),
Self::AssignURightSh => Some(BinOp::Assign(AssignOp::Ushr)),
Self::AssignXor => Some(BinOp::Assign(AssignOp::Xor)),
Self::Add => Some(BinOp::Num(NumOp::Add)),
Self::Sub => Some(BinOp::Num(NumOp::Sub)),
Expand Down
4 changes: 4 additions & 0 deletions boa/src/syntax/parser/expression/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ fn check_assign_operations() {
"a >>= b",
vec![BinOp::new(AssignOp::Shr, Identifier::from("a"), Identifier::from("b")).into()],
);
check_parser(
"a >>>= b",
vec![BinOp::new(AssignOp::Ushr, Identifier::from("a"), Identifier::from("b")).into()],
);
check_parser(
"a %= 10 / 2",
vec![BinOp::new(
Expand Down