|
@@ -103,18 +103,28 @@ String parse_regex_pattern(StringView pattern, bool unicode)
|
|
return builder.build();
|
|
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)
|
|
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());
|
|
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)
|
|
RegExpObject::RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype)
|
|
: Object(prototype)
|
|
: Object(prototype)
|
|
, m_pattern(move(pattern))
|
|
, m_pattern(move(pattern))
|
|
, m_flags(move(flags))
|
|
, m_flags(move(flags))
|
|
, m_regex(move(regex))
|
|
, m_regex(move(regex))
|
|
{
|
|
{
|
|
- VERIFY(m_regex.parser_result.error == regex::Error::NoError);
|
|
|
|
|
|
+ VERIFY(m_regex->parser_result.error == regex::Error::NoError);
|
|
}
|
|
}
|
|
|
|
|
|
RegExpObject::~RegExpObject()
|
|
RegExpObject::~RegExpObject()
|
|
@@ -128,8 +138,8 @@ void RegExpObject::initialize(GlobalObject& global_object)
|
|
define_direct_property(vm.names.lastIndex, Value(0), Attribute::Writable);
|
|
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();
|
|
auto& vm = global_object.vm();
|
|
|
|
|
|
@@ -169,11 +179,22 @@ RegExpObject* regexp_create(GlobalObject& global_object, Value pattern, Value fl
|
|
return {};
|
|
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())
|
|
if (vm.exception())
|
|
return {};
|
|
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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|