|
@@ -36,6 +36,25 @@ RegExpConstructor::~RegExpConstructor()
|
|
|
// 22.2.3.1 RegExp ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp-pattern-flags
|
|
|
Value RegExpConstructor::call()
|
|
|
{
|
|
|
+ auto& vm = this->vm();
|
|
|
+ auto& global_object = this->global_object();
|
|
|
+
|
|
|
+ auto pattern = vm.argument(0);
|
|
|
+ auto flags = vm.argument(1);
|
|
|
+
|
|
|
+ bool pattern_is_regexp = pattern.is_regexp(global_object);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ if (pattern_is_regexp && flags.is_undefined()) {
|
|
|
+ auto pattern_constructor = pattern.as_object().get(vm.names.constructor);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ if (same_value(this, pattern_constructor))
|
|
|
+ return pattern;
|
|
|
+ }
|
|
|
+
|
|
|
return construct(*this);
|
|
|
}
|
|
|
|
|
@@ -43,8 +62,44 @@ Value RegExpConstructor::call()
|
|
|
Value RegExpConstructor::construct(FunctionObject&)
|
|
|
{
|
|
|
auto& vm = this->vm();
|
|
|
- // FIXME: This is non-conforming
|
|
|
- return regexp_create(global_object(), vm.argument(0), vm.argument(1));
|
|
|
+ auto& global_object = this->global_object();
|
|
|
+
|
|
|
+ auto pattern = vm.argument(0);
|
|
|
+ auto flags = vm.argument(1);
|
|
|
+
|
|
|
+ bool pattern_is_regexp = pattern.is_regexp(global_object);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ Value pattern_value;
|
|
|
+ Value flags_value;
|
|
|
+
|
|
|
+ if (pattern.is_object() && is<RegExpObject>(pattern.as_object())) {
|
|
|
+ auto& regexp_pattern = static_cast<RegExpObject&>(pattern.as_object());
|
|
|
+ pattern_value = js_string(vm, regexp_pattern.pattern());
|
|
|
+
|
|
|
+ if (flags.is_undefined())
|
|
|
+ flags_value = js_string(vm, regexp_pattern.flags());
|
|
|
+ else
|
|
|
+ flags_value = flags;
|
|
|
+ } else if (pattern_is_regexp) {
|
|
|
+ pattern_value = pattern.as_object().get(vm.names.source);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ if (flags.is_undefined()) {
|
|
|
+ flags_value = pattern.as_object().get(vm.names.flags);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+ } else {
|
|
|
+ flags_value = flags;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ pattern_value = pattern;
|
|
|
+ flags_value = flags;
|
|
|
+ }
|
|
|
+
|
|
|
+ return regexp_create(global_object, pattern_value, flags_value);
|
|
|
}
|
|
|
|
|
|
// 22.2.4.2 get RegExp [ @@species ], https://tc39.es/ecma262/#sec-get-regexp-@@species
|