1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 09:27:34 +00:00

js: Convert to east const

This commit is contained in:
Linus Groh 2021-07-06 23:58:50 +01:00
parent 37c4fbb6ca
commit 15070b76b3

View file

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