1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +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:
Linus Groh 2020-04-02 22:08:14 +01:00 committed by Andreas Kling
parent 543c6e00db
commit 2636cac6e4
6 changed files with 1 additions and 30 deletions

View file

@ -490,12 +490,6 @@ void BooleanLiteral::dump(int indent) const
printf("BooleanLiteral %s\n", m_value ? "true" : "false"); 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 void NullLiteral::dump(int indent) const
{ {
print_indent(indent); print_indent(indent);
@ -812,11 +806,6 @@ Value BooleanLiteral::execute(Interpreter&) const
return Value(m_value); return Value(m_value);
} }
Value UndefinedLiteral::execute(Interpreter&) const
{
return {};
}
Value NullLiteral::execute(Interpreter&) const Value NullLiteral::execute(Interpreter&) const
{ {
return js_null(); return js_null();

View file

@ -440,19 +440,6 @@ private:
virtual const char* class_name() const override { return "NullLiteral"; } 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 { class Identifier final : public Expression {
public: public:
explicit Identifier(const FlyString& string) explicit Identifier(const FlyString& string)

View file

@ -69,7 +69,6 @@ Lexer::Lexer(StringView source)
s_keywords.set("true", TokenType::BoolLiteral); s_keywords.set("true", TokenType::BoolLiteral);
s_keywords.set("try", TokenType::Try); s_keywords.set("try", TokenType::Try);
s_keywords.set("typeof", TokenType::Typeof); s_keywords.set("typeof", TokenType::Typeof);
s_keywords.set("undefined", TokenType::UndefinedLiteral);
s_keywords.set("var", TokenType::Var); s_keywords.set("var", TokenType::Var);
s_keywords.set("void", TokenType::Void); s_keywords.set("void", TokenType::Void);
s_keywords.set("while", TokenType::While); s_keywords.set("while", TokenType::While);

View file

@ -329,9 +329,6 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
case TokenType::NullLiteral: case TokenType::NullLiteral:
consume(); consume();
return create_ast_node<NullLiteral>(); return create_ast_node<NullLiteral>();
case TokenType::UndefinedLiteral:
consume();
return create_ast_node<UndefinedLiteral>();
case TokenType::CurlyOpen: case TokenType::CurlyOpen:
return parse_object_expression(); return parse_object_expression();
case TokenType::Function: case TokenType::Function:
@ -821,7 +818,6 @@ bool Parser::match_expression() const
return type == TokenType::BoolLiteral return type == TokenType::BoolLiteral
|| type == TokenType::NumericLiteral || type == TokenType::NumericLiteral
|| type == TokenType::StringLiteral || type == TokenType::StringLiteral
|| type == TokenType::UndefinedLiteral
|| type == TokenType::NullLiteral || type == TokenType::NullLiteral
|| type == TokenType::Identifier || type == TokenType::Identifier
|| type == TokenType::New || type == TokenType::New

View file

@ -21,6 +21,7 @@ GlobalObject::GlobalObject()
// FIXME: These are read-only in ES5 // FIXME: These are read-only in ES5
put("NaN", js_nan()); put("NaN", js_nan());
put("Infinity", js_infinity()); put("Infinity", js_infinity());
put("undefined", js_undefined());
put("console", heap().allocate<ConsoleObject>()); put("console", heap().allocate<ConsoleObject>());
put("Date", heap().allocate<DateConstructor>()); put("Date", heap().allocate<DateConstructor>());

View file

@ -114,7 +114,6 @@ namespace JS {
__ENUMERATE_JS_TOKEN(Tilde) \ __ENUMERATE_JS_TOKEN(Tilde) \
__ENUMERATE_JS_TOKEN(Try) \ __ENUMERATE_JS_TOKEN(Try) \
__ENUMERATE_JS_TOKEN(Typeof) \ __ENUMERATE_JS_TOKEN(Typeof) \
__ENUMERATE_JS_TOKEN(UndefinedLiteral) \
__ENUMERATE_JS_TOKEN(UnsignedShiftRight) \ __ENUMERATE_JS_TOKEN(UnsignedShiftRight) \
__ENUMERATE_JS_TOKEN(UnsignedShiftRightEquals) \ __ENUMERATE_JS_TOKEN(UnsignedShiftRightEquals) \
__ENUMERATE_JS_TOKEN(UnterminatedStringLiteral) \ __ENUMERATE_JS_TOKEN(UnterminatedStringLiteral) \