diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 90749d5bbb7..1611b2d85f6 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -175,7 +175,7 @@ static String read_next_piece() static void print_value(JS::Value value, HashTable& seen_objects); -static void print_type(const FlyString& name) +static void print_type(FlyString const& name) { out("[\033[36;1m{}\033[0m]", name); } @@ -234,22 +234,22 @@ static void print_object(JS::Object& object, HashTable& seen_object out("}}"); } -static void print_function(const JS::Object& object, HashTable&) +static void print_function(JS::Object const& object, HashTable&) { print_type(object.class_name()); if (is(object)) - out(" {}", static_cast(object).name()); + out(" {}", static_cast(object).name()); else if (is(object)) - out(" {}", static_cast(object).name()); + out(" {}", static_cast(object).name()); } -static void print_date(const JS::Object& object, HashTable&) +static void print_date(JS::Object const& object, HashTable&) { print_type("Date"); - out(" \033[34;1m{}\033[0m", static_cast(object).string()); + out(" \033[34;1m{}\033[0m", static_cast(object).string()); } -static void print_error(const JS::Object& object, HashTable& seen_objects) +static void print_error(JS::Object const& object, HashTable& seen_objects) { auto name = object.get_without_side_effects(vm->names.name).value_or(JS::js_undefined()); auto message = object.get_without_side_effects(vm->names.message).value_or(JS::js_undefined()); @@ -264,18 +264,18 @@ static void print_error(const JS::Object& object, HashTable& seen_o } } -static void print_regexp_object(const JS::Object& object, HashTable&) +static void print_regexp_object(JS::Object const& object, HashTable&) { - auto& regexp_object = static_cast(object); + auto& regexp_object = static_cast(object); // Use RegExp.prototype.source rather than RegExpObject::pattern() so we get proper escaping auto source = regexp_object.get("source").to_primitive_string(object.global_object())->string(); print_type("RegExp"); out(" \033[34;1m/{}/{}\033[0m", source, regexp_object.flags()); } -static void print_proxy_object(const JS::Object& object, HashTable& seen_objects) +static void print_proxy_object(JS::Object const& object, HashTable& seen_objects) { - auto& proxy_object = static_cast(object); + auto& proxy_object = static_cast(object); print_type("Proxy"); out("\n target: "); print_value(&proxy_object.target(), seen_objects); @@ -283,9 +283,9 @@ static void print_proxy_object(const JS::Object& object, HashTable& print_value(&proxy_object.handler(), seen_objects); } -static void print_map(const JS::Object& object, HashTable& seen_objects) +static void print_map(JS::Object const& object, HashTable& seen_objects) { - auto& map = static_cast(object); + auto& map = static_cast(object); auto& entries = map.entries(); print_type("Map"); out(" {{"); @@ -301,9 +301,9 @@ static void print_map(const JS::Object& object, HashTable& seen_obj out("}}"); } -static void print_set(const JS::Object& object, HashTable& seen_objects) +static void print_set(JS::Object const& object, HashTable& seen_objects) { - auto& set = static_cast(object); + auto& set = static_cast(object); auto& values = set.values(); print_type("Set"); out(" {{"); @@ -317,9 +317,9 @@ static void print_set(const JS::Object& object, HashTable& seen_obj out("}}"); } -static void print_promise(const JS::Object& object, HashTable& seen_objects) +static void print_promise(JS::Object const& object, HashTable& seen_objects) { - auto& promise = static_cast(object); + auto& promise = static_cast(object); print_type("Promise"); switch (promise.state()) { case JS::Promise::State::Pending: @@ -343,9 +343,9 @@ static void print_promise(const JS::Object& object, HashTable& seen } } -static void print_array_buffer(const JS::Object& object, HashTable& seen_objects) +static void print_array_buffer(JS::Object const& object, HashTable& seen_objects) { - auto& array_buffer = static_cast(object); + auto& array_buffer = static_cast(object); auto& buffer = array_buffer.buffer(); auto byte_length = array_buffer.byte_length(); print_type("ArrayBuffer"); @@ -375,9 +375,9 @@ static void print_number(T number) requires IsArithmetic out("\033[0m"); } -static void print_typed_array(const JS::Object& object, HashTable& seen_objects) +static void print_typed_array(JS::Object const& object, HashTable& seen_objects) { - auto& typed_array_base = static_cast(object); + auto& typed_array_base = static_cast(object); auto& array_buffer = *typed_array_base.viewed_array_buffer(); auto length = typed_array_base.array_length(); print_type(object.class_name()); @@ -397,7 +397,7 @@ static void print_typed_array(const JS::Object& object, HashTable& #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ if (is(object)) { \ out("[ "); \ - auto& typed_array = static_cast(typed_array_base); \ + auto& typed_array = static_cast(typed_array_base); \ auto data = typed_array.data(); \ for (size_t i = 0; i < length; ++i) { \ if (i > 0) \ @@ -412,9 +412,9 @@ static void print_typed_array(const JS::Object& object, HashTable& VERIFY_NOT_REACHED(); } -static void print_data_view(const JS::Object& object, HashTable& seen_objects) +static void print_data_view(JS::Object const& object, HashTable& seen_objects) { - auto& data_view = static_cast(object); + auto& data_view = static_cast(object); print_type("DataView"); out("\n byteLength: "); print_value(JS::Value(data_view.byte_length()), seen_objects); @@ -425,7 +425,7 @@ static void print_data_view(const JS::Object& object, HashTable& se out(" @ {:p}", data_view.viewed_array_buffer()); } -static void print_primitive_wrapper_object(const FlyString& name, const JS::Object& object, HashTable& seen_objects) +static void print_primitive_wrapper_object(FlyString const& name, JS::Object const& object, HashTable& seen_objects) { // BooleanObject, NumberObject, StringObject print_type(name); @@ -512,7 +512,7 @@ static void print(JS::Value value) outln(); } -static bool write_to_file(const String& path) +static bool write_to_file(String const& path) { int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666); for (size_t i = 0; i < repl_statements.size(); i++) { @@ -538,7 +538,7 @@ static bool write_to_file(const String& path) return true; } -static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source) +static bool parse_and_run(JS::Interpreter& interpreter, StringView const& source) { auto parser = JS::Parser(JS::Lexer(source)); auto program = parser.parse_program(); @@ -944,7 +944,7 @@ int main(int argc, char** argv) editor.set_prompt(prompt_for_level(open_indents)); }; - auto complete = [&interpreter](const Line::Editor& editor) -> Vector { + auto complete = [&interpreter](Line::Editor const& editor) -> Vector { auto line = editor.line(editor.cursor()); JS::Lexer lexer { line }; @@ -1015,8 +1015,8 @@ int main(int argc, char** argv) Vector results; - Function list_all_properties = [&results, &list_all_properties](const JS::Shape& shape, auto& property_pattern) { - for (const auto& descriptor : shape.property_table()) { + Function list_all_properties = [&results, &list_all_properties](JS::Shape const& shape, auto& property_pattern) { + for (auto const& descriptor : shape.property_table()) { if (!descriptor.key.is_string()) continue; auto key = descriptor.key.as_string(); @@ -1027,7 +1027,7 @@ int main(int argc, char** argv) } } } - if (const auto* prototype = shape.prototype()) { + if (auto const* prototype = shape.prototype()) { list_all_properties(prototype->shape(), property_pattern); } }; @@ -1045,15 +1045,15 @@ int main(int argc, char** argv) if (!variable.is_object()) break; - const auto* object = variable.to_object(interpreter->global_object()); - const auto& shape = object->shape(); + auto const* object = variable.to_object(interpreter->global_object()); + auto const& shape = object->shape(); list_all_properties(shape, property_name); if (results.size()) editor.suggest(property_name.length()); break; } case CompleteVariable: { - const auto& variable = interpreter->global_object(); + auto const& variable = interpreter->global_object(); list_all_properties(variable.shape(), variable_name); if (results.size()) editor.suggest(variable_name.length());