diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 7 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Instruction.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.cpp | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/Op.h | 18 |
4 files changed, 40 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index c53f65289a..86c6990f53 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -258,6 +258,13 @@ void StringLiteral::generate_bytecode(Bytecode::Generator& generator) const generator.emit<Bytecode::Op::NewString>(generator.intern_string(m_value)); } +void RegExpLiteral::generate_bytecode(Bytecode::Generator& generator) const +{ + auto source_index = generator.intern_string(m_pattern); + auto flags_index = generator.intern_string(m_flags); + generator.emit<Bytecode::Op::NewRegExp>(source_index, flags_index); +} + void Identifier::generate_bytecode(Bytecode::Generator& generator) const { if (m_argument_index.has_value()) diff --git a/Userland/Libraries/LibJS/Bytecode/Instruction.h b/Userland/Libraries/LibJS/Bytecode/Instruction.h index 5b8f2d06ca..a01ce99238 100644 --- a/Userland/Libraries/LibJS/Bytecode/Instruction.h +++ b/Userland/Libraries/LibJS/Bytecode/Instruction.h @@ -32,6 +32,7 @@ O(IteratorToArray) \ O(NewString) \ O(NewObject) \ + O(NewRegExp) \ O(CopyObjectExcludingProperties) \ O(GetVariable) \ O(SetVariable) \ diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 08c84e577b..d925c54687 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -15,6 +15,7 @@ #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/LexicalEnvironment.h> +#include <LibJS/Runtime/RegExpObject.h> #include <LibJS/Runtime/ScopeObject.h> #include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/Value.h> @@ -169,6 +170,14 @@ void NewObject::execute_impl(Bytecode::Interpreter& interpreter) const interpreter.accumulator() = Object::create(interpreter.global_object(), interpreter.global_object().object_prototype()); } +void NewRegExp::execute_impl(Bytecode::Interpreter& interpreter) const +{ + auto source = interpreter.current_executable().get_string(m_source_index); + auto flags = interpreter.current_executable().get_string(m_flags_index); + + interpreter.accumulator() = RegExpObject::create(interpreter.global_object(), source, flags); +} + void CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpreter) const { auto* from_object = interpreter.reg(m_from_object).to_object(interpreter.global_object()); @@ -498,6 +507,11 @@ String NewObject::to_string_impl(Bytecode::Executable const&) const return "NewObject"; } +String NewRegExp::to_string_impl(Bytecode::Executable const& executable) const +{ + return String::formatted("NewRegExp source:{} (\"{}\") flags:{} (\"{}\")", m_source_index, executable.get_string(m_source_index), m_flags_index, executable.get_string(m_flags_index)); +} + String CopyObjectExcludingProperties::to_string_impl(const Bytecode::Executable&) const { StringBuilder builder; diff --git a/Userland/Libraries/LibJS/Bytecode/Op.h b/Userland/Libraries/LibJS/Bytecode/Op.h index 026f1912f3..177f2f66ed 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.h +++ b/Userland/Libraries/LibJS/Bytecode/Op.h @@ -162,6 +162,24 @@ public: void replace_references_impl(BasicBlock const&, BasicBlock const&) { } }; +class NewRegExp final : public Instruction { +public: + NewRegExp(StringTableIndex source_index, StringTableIndex flags_index) + : Instruction(Type::NewRegExp) + , m_source_index(source_index) + , m_flags_index(flags_index) + { + } + + void execute_impl(Bytecode::Interpreter&) const; + String to_string_impl(Bytecode::Executable const&) const; + void replace_references_impl(BasicBlock const&, BasicBlock const&) { } + +private: + StringTableIndex m_source_index; + StringTableIndex m_flags_index; +}; + // NOTE: This instruction is variable-width depending on the number of excluded names class CopyObjectExcludingProperties final : public Instruction { public: |