LibJS: Track which Identifier nodes refer to function arguments

This patch adds an "argument index" field to Identifier AST nodes.
If the Identifier refers to a function parameter in the currently
open function scope, we stash the index of the parameter here.

This will allow us to implement much faster direct access to function
argument variables.
This commit is contained in:
Andreas Kling 2021-06-14 09:30:43 +02:00
commit 481cef59b6
Notes: sideshowbarker 2024-07-18 12:16:01 +09:00
4 changed files with 39 additions and 5 deletions

View file

@ -768,13 +768,15 @@ private:
class Identifier final : public Expression {
public:
explicit Identifier(SourceRange source_range, FlyString const& string)
: Expression(move(source_range))
, m_string(string)
explicit Identifier(SourceRange source_range, FlyString string, Optional<size_t> argument_index = {})
: Expression(source_range)
, m_string(move(string))
, m_argument_index(move(argument_index))
{
}
FlyString const& string() const { return m_string; }
Optional<size_t> const& argument_index() const { return m_argument_index; }
virtual Value execute(Interpreter&, GlobalObject&) const override;
virtual void dump(int indent) const override;
@ -785,6 +787,7 @@ private:
virtual bool is_identifier() const override { return true; }
FlyString m_string;
Optional<size_t> m_argument_index;
};
class ClassMethod final : public ASTNode {