js: Convert to east const

This commit is contained in:
Linus Groh 2021-07-06 23:58:50 +01:00
parent 37c4fbb6ca
commit 15070b76b3
Notes: sideshowbarker 2024-07-18 10:16:11 +09:00

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_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<JS::Object*>& seen_object
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());
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))
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");
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 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
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<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");
out("\n target: ");
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);
}
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();
print_type("Map");
out(" {{");
@ -301,9 +301,9 @@ static void print_map(const JS::Object& object, HashTable<JS::Object*>& seen_obj
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();
print_type("Set");
out(" {{");
@ -317,9 +317,9 @@ static void print_set(const JS::Object& object, HashTable<JS::Object*>& seen_obj
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");
switch (promise.state()) {
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 byte_length = array_buffer.byte_length();
print_type("ArrayBuffer");
@ -375,9 +375,9 @@ static void print_number(T number) requires IsArithmetic<T>
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 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<JS::Object*>&
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
if (is<JS::ClassName>(object)) { \
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(); \
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<JS::Object*>&
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");
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<JS::Object*>& se
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
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<Line::CompletionSuggestion> {
auto complete = [&interpreter](Line::Editor const& editor) -> Vector<Line::CompletionSuggestion> {
auto line = editor.line(editor.cursor());
JS::Lexer lexer { line };
@ -1015,8 +1015,8 @@ int main(int argc, char** argv)
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) {
for (const auto& descriptor : shape.property_table()) {
Function<void(JS::Shape const&, StringView const&)> 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());