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

LibJS/Bytecode: Create global variables before setting them

This allows them to be accessed before assignment, and also prevents
throwing in strict mode as we are trying to set a non-existent
variable.
This commit is contained in:
Luke Wilde 2022-07-17 19:06:44 +01:00 committed by Linus Groh
parent 12e3abc9e7
commit c55a4c7f30
3 changed files with 25 additions and 13 deletions

View file

@ -317,11 +317,12 @@ public:
class CreateVariable final : public Instruction {
public:
explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable)
explicit CreateVariable(IdentifierTableIndex identifier, EnvironmentMode mode, bool is_immutable, bool is_global = false)
: Instruction(Type::CreateVariable)
, m_identifier(identifier)
, m_mode(mode)
, m_is_immutable(is_immutable)
, m_is_global(is_global)
{
}
@ -332,7 +333,8 @@ public:
private:
IdentifierTableIndex m_identifier;
EnvironmentMode m_mode;
bool m_is_immutable { false };
bool m_is_immutable : 4 { false };
bool m_is_global : 4 { false };
};
class SetVariable final : public Instruction {