mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
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:
parent
75541c48b5
commit
2f6eec1322
Notes:
sideshowbarker
2024-07-18 09:25:22 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/2f6eec13225 Pull-request: https://github.com/SerenityOS/serenity/pull/8596 Reviewed-by: https://github.com/linusg
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user