diff options
author | davidot <davidot@serenityos.org> | 2022-08-20 17:27:02 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-20 23:53:55 +0100 |
commit | ae349ec6a877cd20d0dc857b56290da4ee2b1ddb (patch) | |
tree | 34351b0dd406efb856ae4eb55bc5b8acb1eeed3f /Userland/Libraries/LibJS/AST.h | |
parent | b79f03182d98a10ee234ae33fe68d4a8f3d95406 (diff) | |
download | serenity-ae349ec6a877cd20d0dc857b56290da4ee2b1ddb.zip |
LibJS: Use a synthetic constructor if class with parent doesn't have one
We already did this but it called the @@iterator method of
%Array.prototype% visible to the user for example by overriding that
method. This should not be visible so we use a special version of
SuperCall now.
Diffstat (limited to 'Userland/Libraries/LibJS/AST.h')
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 8586ba0cf6..1c6c7886ef 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -1492,10 +1492,26 @@ public: class SuperCall final : public Expression { public: + // This is here to be able to make a constructor like + // constructor(...args) { super(...args); } which does not use @@iterator of %Array.prototype%. + enum class IsPartOfSyntheticConstructor { + No, + Yes, + }; + SuperCall(SourceRange source_range, Vector<CallExpression::Argument> arguments) : Expression(source_range) , m_arguments(move(arguments)) + , m_is_synthetic(IsPartOfSyntheticConstructor::No) + { + } + + SuperCall(SourceRange source_range, IsPartOfSyntheticConstructor is_part_of_synthetic_constructor, CallExpression::Argument constructor_argument) + : Expression(source_range) + , m_arguments({ move(constructor_argument) }) + , m_is_synthetic(IsPartOfSyntheticConstructor::Yes) { + VERIFY(is_part_of_synthetic_constructor == IsPartOfSyntheticConstructor::Yes); } virtual Completion execute(Interpreter&, GlobalObject&) const override; @@ -1503,6 +1519,7 @@ public: private: Vector<CallExpression::Argument> const m_arguments; + IsPartOfSyntheticConstructor const m_is_synthetic; }; enum class AssignmentOp { |