js: Fix pretty-printing of RegExp objects

Regressed in b7e5f08.

Use the newly available RegExpObject::escape_regexp_pattern() instead of
attempting to call the RegExp.prototype.source accessor getter directly.
This commit is contained in:
Linus Groh 2021-10-05 18:35:34 +01:00
parent 78fd8c1ca2
commit fe802f5ff5

View file

@ -287,10 +287,8 @@ static void print_error(JS::Object const& object, HashTable<JS::Object*>& seen_o
static void print_regexp_object(JS::Object const& object, HashTable<JS::Object*>&)
{
auto& regexp_object = static_cast<JS::RegExpObject const&>(object);
// Use RegExp.prototype.source rather than RegExpObject::pattern() so we get proper escaping
auto source = regexp_object.get_without_side_effects("source").to_primitive_string(object.global_object())->string();
print_type("RegExp");
out(" \033[34;1m/{}/{}\033[0m", source, regexp_object.flags());
out(" \033[34;1m/{}/{}\033[0m", regexp_object.escape_regexp_pattern(), regexp_object.flags());
}
static void print_proxy_object(JS::Object const& object, HashTable<JS::Object*>& seen_objects)