1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:48:11 +00:00

LibJS: Add bytecode support for regexp literals

This commit is contained in:
Matthew Olsson 2021-06-19 17:17:40 -07:00 committed by Andreas Kling
parent 3ccf4dc7ad
commit df65ff8a1e
5 changed files with 41 additions and 0 deletions

View file

@ -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;