1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:07:45 +00:00

LibJS: Rename RegExpLiteral m_content to m_pattern

This is what we call it elsewhere, let's be consistent.
This commit is contained in:
Linus Groh 2021-05-10 11:56:08 +01:00
parent d1a72dc6eb
commit c93c2dc72c
3 changed files with 12 additions and 10 deletions

View file

@ -1791,13 +1791,13 @@ Value NullLiteral::execute(Interpreter& interpreter, GlobalObject&) const
void RegExpLiteral::dump(int indent) const void RegExpLiteral::dump(int indent) const
{ {
print_indent(indent); print_indent(indent);
outln("{} (/{}/{})", class_name(), content(), flags()); outln("{} (/{}/{})", class_name(), pattern(), flags());
} }
Value RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global_object) const Value RegExpLiteral::execute(Interpreter& interpreter, GlobalObject& global_object) const
{ {
InterpreterNodeScope node_scope { interpreter, *this }; InterpreterNodeScope node_scope { interpreter, *this };
return RegExpObject::create(global_object, content(), flags()); return RegExpObject::create(global_object, pattern(), flags());
} }
void ArrayExpression::dump(int indent) const void ArrayExpression::dump(int indent) const

View file

@ -658,21 +658,21 @@ public:
class RegExpLiteral final : public Literal { class RegExpLiteral final : public Literal {
public: public:
explicit RegExpLiteral(SourceRange source_range, String content, String flags) explicit RegExpLiteral(SourceRange source_range, String pattern, String flags)
: Literal(move(source_range)) : Literal(move(source_range))
, m_content(content) , m_pattern(move(pattern))
, m_flags(flags) , m_flags(move(flags))
{ {
} }
virtual Value execute(Interpreter&, GlobalObject&) const override; virtual Value execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override; virtual void dump(int indent) const override;
const String& content() const { return m_content; } const String& pattern() const { return m_pattern; }
const String& flags() const { return m_flags; } const String& flags() const { return m_flags; }
private: private:
String m_content; String m_pattern;
String m_flags; String m_flags;
}; };

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de> * Copyright (c) 2020, Stephan Unverwerth <s.unverwerth@gmx.de>
* Copyright (c) 2020, Linus Groh <linusg@serenityos.org> * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -683,9 +683,11 @@ NonnullRefPtr<Expression> Parser::parse_primary_expression()
NonnullRefPtr<RegExpLiteral> Parser::parse_regexp_literal() NonnullRefPtr<RegExpLiteral> Parser::parse_regexp_literal()
{ {
auto rule_start = push_start(); auto rule_start = push_start();
auto content = consume().value(); auto pattern = consume().value();
// Remove leading and trailing slash.
pattern = pattern.substring_view(1, pattern.length() - 2);
auto flags = match(TokenType::RegexFlags) ? consume().value() : ""; auto flags = match(TokenType::RegexFlags) ? consume().value() : "";
return create_ast_node<RegExpLiteral>({ m_parser_state.m_current_token.filename(), rule_start.position(), position() }, content.substring_view(1, content.length() - 2), flags); return create_ast_node<RegExpLiteral>({ m_parser_state.m_current_token.filename(), rule_start.position(), position() }, pattern, flags);
} }
NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression() NonnullRefPtr<Expression> Parser::parse_unary_prefixed_expression()