summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r--Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/ErrorTypes.h1
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp31
-rw-r--r--Userland/Libraries/LibJS/Runtime/RegExpPrototype.h1
4 files changed, 34 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
index 1b9f254ef1..49a9f5ea43 100644
--- a/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
+++ b/Userland/Libraries/LibJS/Runtime/CommonPropertyNames.h
@@ -94,6 +94,7 @@ namespace JS {
P(clz32) \
P(codePointAt) \
P(compareExchange) \
+ P(compile) \
P(concat) \
P(configurable) \
P(console) \
diff --git a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
index 3debebd25e..834035742c 100644
--- a/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
+++ b/Userland/Libraries/LibJS/Runtime/ErrorTypes.h
@@ -61,6 +61,7 @@
M(NotASymbol, "{} is not a symbol") \
M(NotIterable, "{} is not iterable") \
M(NotObjectCoercible, "{} cannot be converted to an object") \
+ M(NotUndefined, "{} is not undefined") \
M(ObjectDefineOwnPropertyReturnedFalse, "Object's [[DefineOwnProperty]] method returned false") \
M(ObjectDeleteReturnedFalse, "Object's [[Delete]] method returned false") \
M(ObjectFreezeFailed, "Could not freeze object") \
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
index 7a185f1446..65c85ad6d5 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp
@@ -35,6 +35,7 @@ void RegExpPrototype::initialize(GlobalObject& global_object)
define_native_function(vm.names.toString, to_string, 0, attr);
define_native_function(vm.names.test, test, 1, attr);
define_native_function(vm.names.exec, exec, 1, attr);
+ define_native_function(vm.names.compile, compile, 2, attr);
define_native_function(*vm.well_known_symbol_match(), symbol_match, 1, attr);
define_native_function(*vm.well_known_symbol_match_all(), symbol_match_all, 1, attr);
@@ -920,4 +921,34 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split)
return array;
}
+// B.2.4.1 RegExp.prototype.compile ( pattern, flags ), https://tc39.es/ecma262/#sec-regexp.prototype.compile
+JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::compile)
+{
+ auto* regexp_object = regexp_object_from(vm, global_object);
+ if (!regexp_object)
+ return {};
+
+ auto pattern = vm.argument(0);
+ auto flags = vm.argument(1);
+
+ Value pattern_value;
+ Value flags_value;
+
+ if (pattern.is_object() && is<RegExpObject>(pattern.as_object())) {
+ if (!flags.is_undefined()) {
+ vm.throw_exception<TypeError>(global_object, ErrorType::NotUndefined, flags.to_string_without_side_effects());
+ return {};
+ }
+
+ auto& regexp_pattern = static_cast<RegExpObject&>(pattern.as_object());
+ pattern_value = js_string(vm, regexp_pattern.pattern());
+ flags_value = js_string(vm, regexp_pattern.flags());
+ } else {
+ pattern_value = pattern;
+ flags_value = flags;
+ }
+
+ return regexp_object->regexp_initialize(global_object, pattern_value, flags_value);
+}
+
}
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.h b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.h
index 4b5e0128da..bdc5c635bd 100644
--- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.h
+++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.h
@@ -34,6 +34,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(symbol_replace);
JS_DECLARE_NATIVE_FUNCTION(symbol_search);
JS_DECLARE_NATIVE_FUNCTION(symbol_split);
+ JS_DECLARE_NATIVE_FUNCTION(compile);
#define __JS_ENUMERATE(_, flag_name, ...) \
JS_DECLARE_NATIVE_GETTER(flag_name);