diff --git a/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 12327df652..65e3eebe95 100644 --- a/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Matthew Olsson + * Copyright (c) 2020, Linus Groh * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,14 +50,13 @@ void RegExpPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.exec, exec, 1, attr); u8 readable_attr = Attribute::Configurable; - define_native_property(vm.names.dotAll, dot_all, nullptr, readable_attr); define_native_property(vm.names.flags, flags, nullptr, readable_attr); - define_native_property(vm.names.global, global, nullptr, readable_attr); - define_native_property(vm.names.ignoreCase, ignore_case, nullptr, readable_attr); - define_native_property(vm.names.multiline, multiline, nullptr, readable_attr); define_native_property(vm.names.source, source, nullptr, readable_attr); - define_native_property(vm.names.sticky, sticky, nullptr, readable_attr); - define_native_property(vm.names.unicode, unicode, nullptr, readable_attr); + +#define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \ + define_native_property(vm.names.flagName, flag_name, nullptr, readable_attr); + JS_ENUMERATE_REGEXP_FLAGS +#undef __JS_ENUMERATE } RegExpPrototype::~RegExpPrototype() @@ -99,14 +99,17 @@ static String escape_regexp_pattern(const RegExpObject& regexp_object) return pattern; } -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::dot_all) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::SingleLine)); -} +#define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \ + JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flag_name) \ + { \ + auto regexp_object = regexp_object_from(vm, global_object); \ + if (!regexp_object) \ + return {}; \ + \ + return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::ECMAScriptFlagName)); \ + } +JS_ENUMERATE_REGEXP_FLAGS +#undef __JS_ENUMERATE JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flags) { @@ -128,33 +131,6 @@ JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flags) return js_string(vm, builder.to_string()); } -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::global) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::Global)); // Note that this "Global" is actually "Global | Stateful" -} - -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::ignore_case) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::Insensitive)); -} - -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::multiline) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::Multiline)); -} - JS_DEFINE_NATIVE_GETTER(RegExpPrototype::source) { auto this_object = this_object_from(vm, global_object); @@ -173,24 +149,6 @@ JS_DEFINE_NATIVE_GETTER(RegExpPrototype::source) return js_string(vm, escape_regexp_pattern(*regexp_object)); } -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::sticky) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::Sticky)); -} - -JS_DEFINE_NATIVE_GETTER(RegExpPrototype::unicode) -{ - auto regexp_object = regexp_object_from(vm, global_object); - if (!regexp_object) - return {}; - - return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::Unicode)); -} - RegexResult RegExpPrototype::do_match(const Regex& re, const StringView& subject) { auto result = re.match(subject); diff --git a/Libraries/LibJS/Runtime/RegExpPrototype.h b/Libraries/LibJS/Runtime/RegExpPrototype.h index 4358a0b308..69b0708ce1 100644 --- a/Libraries/LibJS/Runtime/RegExpPrototype.h +++ b/Libraries/LibJS/Runtime/RegExpPrototype.h @@ -41,18 +41,17 @@ public: private: static RegexResult do_match(const Regex&, const StringView&); - JS_DECLARE_NATIVE_GETTER(dot_all); JS_DECLARE_NATIVE_GETTER(flags); - JS_DECLARE_NATIVE_GETTER(global); - JS_DECLARE_NATIVE_GETTER(ignore_case); - JS_DECLARE_NATIVE_GETTER(multiline); JS_DECLARE_NATIVE_GETTER(source); - JS_DECLARE_NATIVE_GETTER(sticky); - JS_DECLARE_NATIVE_GETTER(unicode); JS_DECLARE_NATIVE_FUNCTION(exec); JS_DECLARE_NATIVE_FUNCTION(test); JS_DECLARE_NATIVE_FUNCTION(to_string); + +#define __JS_ENUMERATE(_, flag_name, ...) \ + JS_DECLARE_NATIVE_GETTER(flag_name); + JS_ENUMERATE_REGEXP_FLAGS +#undef __JS_ENUMERATE }; }