mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
LibJS: Remove UndefinedLiteral, add undefined to global object
There is no such thing as a "undefined literal" in JS - undefined is just a property on the global object with a value of undefined. This is pretty similar to NaN. var undefined = "foo"; is a perfectly fine AssignmentExpression :^)
This commit is contained in:
parent
543c6e00db
commit
2636cac6e4
Notes:
sideshowbarker
2024-07-19 07:59:03 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/2636cac6e47 Pull-request: https://github.com/SerenityOS/serenity/pull/1591 Reviewed-by: https://github.com/awesomekling ✅
6 changed files with 1 additions and 30 deletions
|
@ -490,12 +490,6 @@ void BooleanLiteral::dump(int indent) const
|
|||
printf("BooleanLiteral %s\n", m_value ? "true" : "false");
|
||||
}
|
||||
|
||||
void UndefinedLiteral::dump(int indent) const
|
||||
{
|
||||
print_indent(indent);
|
||||
printf("undefined\n");
|
||||
}
|
||||
|
||||
void NullLiteral::dump(int indent) const
|
||||
{
|
||||
print_indent(indent);
|
||||
|
@ -812,11 +806,6 @@ Value BooleanLiteral::execute(Interpreter&) const
|
|||
return Value(m_value);
|
||||
}
|
||||
|
||||
Value UndefinedLiteral::execute(Interpreter&) const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
Value NullLiteral::execute(Interpreter&) const
|
||||
{
|
||||
return js_null();
|
||||
|
|
|
@ -440,19 +440,6 @@ private:
|
|||
virtual const char* class_name() const override { return "NullLiteral"; }
|
||||
};
|
||||
|
||||
class UndefinedLiteral final : public Literal {
|
||||
public:
|
||||
explicit UndefinedLiteral()
|
||||
{
|
||||
}
|
||||
|
||||
virtual Value execute(Interpreter&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "UndefinedLiteral"; }
|
||||
};
|
||||
|
||||
class Identifier final : public Expression {
|
||||
public:
|
||||
explicit Identifier(const FlyString& string)
|
||||
|
|
|
@ -69,7 +69,6 @@ Lexer::Lexer(StringView source)
|
|||
s_keywords.set("true", TokenType::BoolLiteral);
|
||||
s_keywords.set("try", TokenType::Try);
|
||||
s_keywords.set("typeof", TokenType::Typeof);
|
||||
s_keywords.set("undefined", TokenType::UndefinedLiteral);
|
||||
s_keywords.set("var", TokenType::Var);
|
||||
s_keywords.set("void", TokenType::Void);
|
||||
s_keywords.set("while", TokenType::While);
|
||||
|
|
|
@ -329,9 +329,6 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
|
|||
case TokenType::NullLiteral:
|
||||
consume();
|
||||
return create_ast_node<NullLiteral>();
|
||||
case TokenType::UndefinedLiteral:
|
||||
consume();
|
||||
return create_ast_node<UndefinedLiteral>();
|
||||
case TokenType::CurlyOpen:
|
||||
return parse_object_expression();
|
||||
case TokenType::Function:
|
||||
|
@ -821,7 +818,6 @@ bool Parser::match_expression() const
|
|||
return type == TokenType::BoolLiteral
|
||||
|| type == TokenType::NumericLiteral
|
||||
|| type == TokenType::StringLiteral
|
||||
|| type == TokenType::UndefinedLiteral
|
||||
|| type == TokenType::NullLiteral
|
||||
|| type == TokenType::Identifier
|
||||
|| type == TokenType::New
|
||||
|
|
|
@ -21,6 +21,7 @@ GlobalObject::GlobalObject()
|
|||
// FIXME: These are read-only in ES5
|
||||
put("NaN", js_nan());
|
||||
put("Infinity", js_infinity());
|
||||
put("undefined", js_undefined());
|
||||
|
||||
put("console", heap().allocate<ConsoleObject>());
|
||||
put("Date", heap().allocate<DateConstructor>());
|
||||
|
|
|
@ -114,7 +114,6 @@ namespace JS {
|
|||
__ENUMERATE_JS_TOKEN(Tilde) \
|
||||
__ENUMERATE_JS_TOKEN(Try) \
|
||||
__ENUMERATE_JS_TOKEN(Typeof) \
|
||||
__ENUMERATE_JS_TOKEN(UndefinedLiteral) \
|
||||
__ENUMERATE_JS_TOKEN(UnsignedShiftRight) \
|
||||
__ENUMERATE_JS_TOKEN(UnsignedShiftRightEquals) \
|
||||
__ENUMERATE_JS_TOKEN(UnterminatedStringLiteral) \
|
||||
|
|
Loading…
Add table
Reference in a new issue