2020-06-03 16:05:49 -07:00
|
|
|
/*
|
2021-04-22 16:53:07 -07:00
|
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
2020-06-03 16:05:49 -07:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-03 16:05:49 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/Error.h>
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
|
|
|
#include <LibJS/Runtime/RegExpConstructor.h>
|
|
|
|
#include <LibJS/Runtime/RegExpObject.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
2020-06-20 15:40:48 +02:00
|
|
|
RegExpConstructor::RegExpConstructor(GlobalObject& global_object)
|
2021-06-28 03:45:49 +03:00
|
|
|
: NativeFunction(vm().names.RegExp.as_string(), *global_object.function_prototype())
|
2020-06-03 16:05:49 -07:00
|
|
|
{
|
2020-06-20 15:40:48 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 17:50:18 +02:00
|
|
|
void RegExpConstructor::initialize(GlobalObject& global_object)
|
2020-06-20 15:40:48 +02:00
|
|
|
{
|
2020-10-13 23:49:19 +02:00
|
|
|
auto& vm = this->vm();
|
2020-07-22 17:50:18 +02:00
|
|
|
NativeFunction::initialize(global_object);
|
2021-06-19 00:38:41 +01:00
|
|
|
|
|
|
|
// 22.2.4.1 RegExp.prototype, https://tc39.es/ecma262/#sec-regexp.prototype
|
2021-07-06 02:15:08 +03:00
|
|
|
define_direct_property(vm.names.prototype, global_object.regexp_prototype(), 0);
|
2021-06-19 00:38:41 +01:00
|
|
|
|
2021-06-25 18:37:14 +01:00
|
|
|
define_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable);
|
2021-07-08 02:49:53 +03:00
|
|
|
|
|
|
|
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);
|
2020-06-03 16:05:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
RegExpConstructor::~RegExpConstructor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:41 +01:00
|
|
|
// 22.2.3.1 RegExp ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp-pattern-flags
|
2020-09-27 17:24:14 +02:00
|
|
|
Value RegExpConstructor::call()
|
2020-06-03 16:05:49 -07:00
|
|
|
{
|
2020-09-27 18:45:21 +02:00
|
|
|
return construct(*this);
|
2020-06-03 16:05:49 -07:00
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:41 +01:00
|
|
|
// 22.2.3.1 RegExp ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp-pattern-flags
|
2021-06-27 21:48:34 +02:00
|
|
|
Value RegExpConstructor::construct(FunctionObject&)
|
2020-06-03 16:05:49 -07:00
|
|
|
{
|
2020-09-27 18:36:49 +02:00
|
|
|
auto& vm = this->vm();
|
2021-07-07 19:15:52 +03:00
|
|
|
// FIXME: This is non-conforming
|
|
|
|
return regexp_create(global_object(), vm.argument(0), vm.argument(1));
|
2020-06-03 16:05:49 -07:00
|
|
|
}
|
|
|
|
|
2021-06-19 00:38:41 +01:00
|
|
|
// 22.2.4.2 get RegExp [ @@species ], https://tc39.es/ecma262/#sec-get-regexp-@@species
|
2021-06-07 19:31:32 +03:00
|
|
|
JS_DEFINE_NATIVE_GETTER(RegExpConstructor::symbol_species_getter)
|
|
|
|
{
|
|
|
|
return vm.this_value(global_object);
|
|
|
|
}
|
|
|
|
|
2020-06-03 16:05:49 -07:00
|
|
|
}
|