mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibJS: Separate RegExpCreate into RegExpAlloc and RegExpInitialize
RegExp.prototype.compile will require invoking RegExpInitialize on an already-existing RegExpObject. Break up RegExpCreate into RegExpAlloc and RegExpInitialize to support this.
This commit is contained in:
parent
8f2ab524fa
commit
7c54b6bd45
2 changed files with 36 additions and 9 deletions
|
@ -103,18 +103,28 @@ String parse_regex_pattern(StringView pattern, bool unicode)
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
RegExpObject* RegExpObject::create(GlobalObject& global_object)
|
||||
{
|
||||
return global_object.heap().allocate<RegExpObject>(global_object, *global_object.regexp_prototype());
|
||||
}
|
||||
|
||||
RegExpObject* RegExpObject::create(GlobalObject& global_object, Regex<ECMA262> regex, String pattern, String flags)
|
||||
{
|
||||
return global_object.heap().allocate<RegExpObject>(global_object, move(regex), move(pattern), move(flags), *global_object.regexp_prototype());
|
||||
}
|
||||
|
||||
RegExpObject::RegExpObject(Object& prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
|
||||
RegExpObject::RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype)
|
||||
: Object(prototype)
|
||||
, m_pattern(move(pattern))
|
||||
, m_flags(move(flags))
|
||||
, m_regex(move(regex))
|
||||
{
|
||||
VERIFY(m_regex.parser_result.error == regex::Error::NoError);
|
||||
VERIFY(m_regex->parser_result.error == regex::Error::NoError);
|
||||
}
|
||||
|
||||
RegExpObject::~RegExpObject()
|
||||
|
@ -128,8 +138,8 @@ void RegExpObject::initialize(GlobalObject& global_object)
|
|||
define_direct_property(vm.names.lastIndex, Value(0), Attribute::Writable);
|
||||
}
|
||||
|
||||
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
|
||||
RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value flags)
|
||||
// 22.2.3.2.2 RegExpInitialize ( obj, pattern, flags ), https://tc39.es/ecma262/#sec-regexpinitialize
|
||||
RegExpObject* RegExpObject::regexp_initialize(GlobalObject& global_object, Value pattern, Value flags)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
@ -169,11 +179,22 @@ RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value fl
|
|||
return {};
|
||||
}
|
||||
|
||||
auto* object = RegExpObject::create(global_object, move(regex), move(original_pattern), move(f));
|
||||
object->set(vm.names.lastIndex, Value(0), Object::ShouldThrowExceptions::Yes);
|
||||
m_pattern = move(original_pattern);
|
||||
m_flags = move(f);
|
||||
m_regex = move(regex);
|
||||
|
||||
set(vm.names.lastIndex, Value(0), Object::ShouldThrowExceptions::Yes);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
return object;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// 22.2.3.2.4 RegExpCreate ( P, F ), https://tc39.es/ecma262/#sec-regexpcreate
|
||||
RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value flags)
|
||||
{
|
||||
auto* regexp_object = RegExpObject::create(global_object);
|
||||
return regexp_object->regexp_initialize(global_object, pattern, flags);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue