Skip to content
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
14 changes: 1 addition & 13 deletions core/ast/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ pub enum Expression {
/// It is not a valid expression node.
#[doc(hidden)]
FormalParameterList(FormalParameterList),

#[doc(hidden)]
Debugger,
}

impl Expression {
Expand Down Expand Up @@ -233,7 +230,6 @@ impl Expression {
Self::Parenthesized(expr) => expr.to_interned_string(interner),
Self::RegExpLiteral(regexp) => regexp.to_interned_string(interner),
Self::FormalParameterList(_) => unreachable!(),
Self::Debugger => "debugger".to_owned(),
}
}

Expand Down Expand Up @@ -327,7 +323,7 @@ impl Spanned for Expression {
Self::Parenthesized(expr) => expr.span(),
Self::RegExpLiteral(regexp) => regexp.span(),
// TODO: Remove `FormalParameterList` and `Debugger` nodes
Self::FormalParameterList(_) | Self::Debugger => Span::EMPTY,
Self::FormalParameterList(_) => Span::EMPTY,
}
}
}
Expand Down Expand Up @@ -386,10 +382,6 @@ impl VisitWith for Expression {
Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list(fpl),
Self::NewTarget(new_target) => visitor.visit_new_target(new_target),
Self::ImportMeta(import_meta) => visitor.visit_import_meta(import_meta),
Self::Debugger => {
// do nothing; can be handled as special case by visitor
ControlFlow::Continue(())
}
}
}

Expand Down Expand Up @@ -432,10 +424,6 @@ impl VisitWith for Expression {
Self::FormalParameterList(fpl) => visitor.visit_formal_parameter_list_mut(fpl),
Self::NewTarget(new_target) => visitor.visit_new_target_mut(new_target),
Self::ImportMeta(import_meta) => visitor.visit_import_meta_mut(import_meta),
Self::Debugger => {
// do nothing; can be handled as special case by visitor
ControlFlow::Continue(())
}
}
}
}
3 changes: 3 additions & 0 deletions core/ast/src/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ impl<'ast> Visitor<'ast> for VarDeclaredNamesVisitor<'_> {
fn visit_statement(&mut self, node: &'ast Statement) -> ControlFlow<Self::BreakTy> {
match node {
Statement::Empty
| Statement::Debugger
| Statement::Expression(_)
| Statement::Continue(_)
| Statement::Break(_)
Expand Down Expand Up @@ -1451,6 +1452,7 @@ where
Statement::Block(node) => self.visit_block(node),
Statement::Var(_)
| Statement::Empty
| Statement::Debugger
| Statement::Expression(_)
| Statement::Return(_)
| Statement::Throw(_) => ControlFlow::Continue(()),
Expand Down Expand Up @@ -2091,6 +2093,7 @@ impl<'ast> Visitor<'ast> for VarScopedDeclarationsVisitor<'_> {
Statement::Try(s) => self.visit(s),
Statement::With(s) => self.visit(s),
Statement::Empty
| Statement::Debugger
| Statement::Expression(_)
| Statement::Continue(_)
| Statement::Break(_)
Expand Down
17 changes: 15 additions & 2 deletions core/ast/src/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ pub enum Statement {

/// See [`With`].
With(With),

/// A `debugger` statement.
///
/// The debugger statement invokes any available debugging functionality.
///
/// More information:
/// - [ECMAScript reference][spec]
/// - [MDN documentation][mdn]
///
/// [spec]: https://tc39.es/ecma262/#sec-debugger-statement
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
Debugger,
}

impl Statement {
Expand Down Expand Up @@ -134,6 +146,7 @@ impl Statement {
Self::Throw(throw) => throw.to_interned_string(interner),
Self::Try(try_catch) => return try_catch.to_indented_string(interner, indentation),
Self::With(with) => return with.to_interned_string(interner),
Self::Debugger => "debugger".to_owned(),
};
s.push(';');
s
Expand Down Expand Up @@ -195,7 +208,7 @@ impl VisitWith for Statement {
match self {
Self::Block(b) => visitor.visit_block(b),
Self::Var(v) => visitor.visit_var_declaration(v),
Self::Empty => {
Self::Empty | Self::Debugger => {
// do nothing; there is nothing to visit here
ControlFlow::Continue(())
}
Expand Down Expand Up @@ -224,7 +237,7 @@ impl VisitWith for Statement {
match self {
Self::Block(b) => visitor.visit_block_mut(b),
Self::Var(v) => visitor.visit_var_declaration_mut(v),
Self::Empty => {
Self::Empty | Self::Debugger => {
// do nothing; there is nothing to visit here
ControlFlow::Continue(())
}
Expand Down
1 change: 0 additions & 1 deletion core/engine/src/bytecompiler/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ impl ByteCompiler<'_> {
}
// TODO: try to remove this variant somehow
Expression::FormalParameterList(_) => unreachable!(),
Expression::Debugger => (),
}
}
}
2 changes: 1 addition & 1 deletion core/engine/src/bytecompiler/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ByteCompiler<'_> {
self.register_allocator.dealloc(value);
}
Statement::With(with) => self.compile_with(with, use_expr),
Statement::Empty => {}
Statement::Empty | Statement::Debugger => {}
}
}

Expand Down
4 changes: 0 additions & 4 deletions core/parser/src/parser/expression/primary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ where
.parse(cursor, interner)
.map(Into::into)
}
TokenKind::Keyword((Keyword::Debugger, _)) => {
cursor.advance(interner);
Ok(ast::Expression::Debugger)
}
TokenKind::Keyword((Keyword::Async, contain_escaped_char)) => {
let contain_escaped_char = *contain_escaped_char;
let skip_n = if cursor.peek_is_line_terminator(0, interner).or_abrupt()? {
Expand Down
6 changes: 5 additions & 1 deletion core/parser/src/parser/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ where

ExpressionStatement::new(self.allow_yield, self.allow_await).parse(cursor, interner)
}

TokenKind::Keyword((Keyword::Debugger, _)) => {
cursor.advance(interner);
cursor.expect_semicolon("debugger statement", interner)?;
Ok(ast::Statement::Debugger)
}
_ => {
ExpressionStatement::new(self.allow_yield, self.allow_await).parse(cursor, interner)
}
Expand Down
21 changes: 21 additions & 0 deletions core/parser/src/parser/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,24 @@ fn stress_test_operations() {
.is_ok()
);
}

#[test]
fn debugger_statement() {
check_script_parser(
"debugger;",
vec![Statement::Debugger.into()],
&mut Interner::default(),
);

check_script_parser(
"debugger",
vec![Statement::Debugger.into()],
&mut Interner::default(),
);

check_invalid_script("!debugger");

check_invalid_script("let x = debugger;");

check_invalid_script("debugger + debugger");
}
Loading