mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00: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
1 changed files with 16 additions and 8 deletions
|
@ -230,14 +230,22 @@ static Value regexp_exec(GlobalObject& global_object, Object& regexp_object, Str
|
||||||
// 22.2.5.9 get RegExp.prototype.multiline, https://tc39.es/ecma262/#sec-get-regexp.prototype.multiline
|
// 22.2.5.9 get RegExp.prototype.multiline, https://tc39.es/ecma262/#sec-get-regexp.prototype.multiline
|
||||||
// 22.2.5.14 get RegExp.prototype.sticky, https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
|
// 22.2.5.14 get RegExp.prototype.sticky, https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
|
||||||
// 22.2.5.17 get RegExp.prototype.unicode, https://tc39.es/ecma262/#sec-get-regexp.prototype.unicode
|
// 22.2.5.17 get RegExp.prototype.unicode, https://tc39.es/ecma262/#sec-get-regexp.prototype.unicode
|
||||||
#define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \
|
#define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \
|
||||||
JS_DEFINE_NATIVE_GETTER(RegExpPrototype::flag_name) \
|
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) \
|
if (!regexp_object) \
|
||||||
return {}; \
|
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
|
JS_ENUMERATE_REGEXP_FLAGS
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue