mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 11:09:05 +03:00
LibJS: Implement (no-op) debugger statement
This commit is contained in:
parent
ea839861e5
commit
43c1fa9965
Notes:
sideshowbarker
2024-07-19 07:07:45 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/43c1fa99651 Pull-request: https://github.com/SerenityOS/serenity/pull/2033
@ -102,6 +102,7 @@ static TextStyle style_for_token_type(Gfx::Palette palette, JS::TokenType type)
|
||||
case JS::TokenType::Class:
|
||||
case JS::TokenType::Const:
|
||||
case JS::TokenType::Delete:
|
||||
case JS::TokenType::Debugger:
|
||||
case JS::TokenType::Function:
|
||||
case JS::TokenType::In:
|
||||
case JS::TokenType::Instanceof:
|
||||
|
@ -1396,6 +1396,12 @@ Value SequenceExpression::execute(Interpreter& interpreter) const
|
||||
return last_value;
|
||||
}
|
||||
|
||||
Value DebuggerStatement::execute(Interpreter&) const
|
||||
{
|
||||
dbg() << "Sorry, no JavaScript debugger available (yet)!";
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
void ScopeNode::add_variables(NonnullRefPtrVector<VariableDeclaration> variables)
|
||||
{
|
||||
m_variables.append(move(variables));
|
||||
|
@ -923,4 +923,14 @@ private:
|
||||
virtual const char* class_name() const override { return "ContinueStatement"; }
|
||||
};
|
||||
|
||||
class DebuggerStatement final : public Statement {
|
||||
public:
|
||||
DebuggerStatement() {}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "DebuggerStatement"; }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ Lexer::Lexer(StringView source)
|
||||
s_keywords.set("class", TokenType::Class);
|
||||
s_keywords.set("const", TokenType::Const);
|
||||
s_keywords.set("continue", TokenType::Continue);
|
||||
s_keywords.set("debugger", TokenType::Debugger);
|
||||
s_keywords.set("default", TokenType::Default);
|
||||
s_keywords.set("delete", TokenType::Delete);
|
||||
s_keywords.set("do", TokenType::Do);
|
||||
|
@ -253,6 +253,8 @@ NonnullRefPtr<Statement> Parser::parse_statement()
|
||||
return parse_do_while_statement();
|
||||
case TokenType::While:
|
||||
return parse_while_statement();
|
||||
case TokenType::Debugger:
|
||||
return parse_debugger_statement();
|
||||
default:
|
||||
if (match_expression()) {
|
||||
auto expr = parse_expression(0);
|
||||
@ -1044,6 +1046,13 @@ NonnullRefPtr<ForStatement> Parser::parse_for_statement()
|
||||
return create_ast_node<ForStatement>(move(init), move(test), move(update), move(body));
|
||||
}
|
||||
|
||||
NonnullRefPtr<DebuggerStatement> Parser::parse_debugger_statement()
|
||||
{
|
||||
consume(TokenType::Debugger);
|
||||
consume_or_insert_semicolon();
|
||||
return create_ast_node<DebuggerStatement>();
|
||||
}
|
||||
|
||||
bool Parser::match(TokenType type) const
|
||||
{
|
||||
return m_parser_state.m_current_token.type() == type;
|
||||
@ -1156,7 +1165,8 @@ bool Parser::match_statement() const
|
||||
|| type == TokenType::Switch
|
||||
|| type == TokenType::Break
|
||||
|| type == TokenType::Continue
|
||||
|| type == TokenType::Var;
|
||||
|| type == TokenType::Var
|
||||
|| type == TokenType::Debugger;
|
||||
}
|
||||
|
||||
bool Parser::match_identifier_name() const
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
NonnullRefPtr<ContinueStatement> parse_continue_statement();
|
||||
NonnullRefPtr<DoWhileStatement> parse_do_while_statement();
|
||||
NonnullRefPtr<WhileStatement> parse_while_statement();
|
||||
NonnullRefPtr<DebuggerStatement> parse_debugger_statement();
|
||||
NonnullRefPtr<ConditionalExpression> parse_conditional_expression(NonnullRefPtr<Expression> test);
|
||||
|
||||
NonnullRefPtr<Expression> parse_expression(int min_precedence, Associativity associate = Associativity::Right);
|
||||
|
9
Libraries/LibJS/Tests/debugger-statement.js
Normal file
9
Libraries/LibJS/Tests/debugger-statement.js
Normal file
@ -0,0 +1,9 @@
|
||||
load("test-common.js");
|
||||
|
||||
try {
|
||||
debugger;
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
@ -53,6 +53,7 @@ namespace JS {
|
||||
__ENUMERATE_JS_TOKEN(Continue) \
|
||||
__ENUMERATE_JS_TOKEN(CurlyClose) \
|
||||
__ENUMERATE_JS_TOKEN(CurlyOpen) \
|
||||
__ENUMERATE_JS_TOKEN(Debugger) \
|
||||
__ENUMERATE_JS_TOKEN(Default) \
|
||||
__ENUMERATE_JS_TOKEN(Delete) \
|
||||
__ENUMERATE_JS_TOKEN(Do) \
|
||||
|
@ -532,6 +532,7 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case JS::TokenType::Class:
|
||||
case JS::TokenType::Const:
|
||||
case JS::TokenType::Debugger:
|
||||
case JS::TokenType::Delete:
|
||||
case JS::TokenType::Function:
|
||||
case JS::TokenType::In:
|
||||
|
Loading…
Reference in New Issue
Block a user