LibJS: Implement RegExp.prototype.<flag name> according to the spec

The flag getters (e.g. RegExp.prototype.unicode) must specially handle
when "this" object is the RegExp.prototype object.
This commit is contained in:
Timothy Flynn 2021-07-09 14:57:39 -04:00 committed by Linus Groh
parent 75541c48b5
commit 2f6eec1322
Notes: sideshowbarker 2024-07-18 09:25:22 +09:00

View File

@ -233,11 +233,19 @@ static Value regexp_exec(GlobalObject& global_object, Object& regexp_object, Str
#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); \
auto* regexp_object = this_object_from(vm, global_object); \
if (!regexp_object) \
return {}; \
\
return Value(regexp_object->declared_options().has_flag_set(ECMAScriptFlags::ECMAScriptFlagName)); \
if (!is<RegExpObject>(regexp_object)) { \
if (same_value(regexp_object, global_object.regexp_prototype())) \
return js_undefined(); \
vm.throw_exception<TypeError>(global_object, ErrorType::NotA, "RegExp"); \
return {}; \
} \
\
auto flags = static_cast<RegExpObject*>(regexp_object)->declared_options(); \
return Value(flags.has_flag_set(ECMAScriptFlags::ECMAScriptFlagName)); \
}
JS_ENUMERATE_REGEXP_FLAGS
#undef __JS_ENUMERATE