mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
LibJS: Add parsing and evaluation of private fields and methods
This commit is contained in:
parent
c7a6572789
commit
16cc82460f
9 changed files with 368 additions and 69 deletions
|
@ -1000,6 +1000,23 @@ private:
|
|||
mutable Optional<EnvironmentCoordinate> m_cached_environment_coordinate;
|
||||
};
|
||||
|
||||
class PrivateIdentifier final : public Expression {
|
||||
public:
|
||||
explicit PrivateIdentifier(SourceRange source_range, FlyString string)
|
||||
: Expression(source_range)
|
||||
, m_string(move(string))
|
||||
{
|
||||
}
|
||||
|
||||
FlyString const& string() const { return m_string; }
|
||||
|
||||
virtual Value execute(Interpreter&, GlobalObject&) const override;
|
||||
virtual void dump(int indent) const override;
|
||||
|
||||
private:
|
||||
FlyString m_string;
|
||||
};
|
||||
|
||||
class ClassElement : public ASTNode {
|
||||
public:
|
||||
ClassElement(SourceRange source_range, bool is_static)
|
||||
|
@ -1019,15 +1036,19 @@ public:
|
|||
virtual ElementKind class_element_kind() const = 0;
|
||||
bool is_static() const { return m_is_static; }
|
||||
|
||||
using ClassElementName = Variant<PropertyName, PrivateName>;
|
||||
|
||||
struct ClassFieldDefinition {
|
||||
PropertyName name;
|
||||
ClassElementName name;
|
||||
ECMAScriptFunctionObject* initializer { nullptr };
|
||||
};
|
||||
|
||||
// We use the Completion also as a ClassStaticBlockDefinition Record.
|
||||
using ClassValue = Variant<ClassFieldDefinition, Completion>;
|
||||
using ClassValue = Variant<ClassFieldDefinition, Completion, PrivateElement>;
|
||||
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter&, GlobalObject&, Object& home_object) const = 0;
|
||||
|
||||
virtual Optional<FlyString> private_bound_identifier() const { return {}; };
|
||||
|
||||
private:
|
||||
bool m_is_static { false };
|
||||
};
|
||||
|
@ -1054,6 +1075,7 @@ public:
|
|||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter&, GlobalObject&, Object& home_object) const override;
|
||||
virtual Optional<FlyString> private_bound_identifier() const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_key;
|
||||
|
@ -1078,6 +1100,7 @@ public:
|
|||
|
||||
virtual void dump(int indent) const override;
|
||||
virtual ThrowCompletionOr<ClassValue> class_element_evaluation(Interpreter& interpreter, GlobalObject& object, Object& home_object) const override;
|
||||
virtual Optional<FlyString> private_bound_identifier() const override;
|
||||
|
||||
private:
|
||||
NonnullRefPtr<Expression> m_key;
|
||||
|
@ -1536,6 +1559,8 @@ public:
|
|||
|
||||
String to_string_approximation() const;
|
||||
|
||||
bool ends_in_private_name() const;
|
||||
|
||||
private:
|
||||
virtual bool is_member_expression() const override { return true; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue