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

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -69,7 +69,7 @@ TESTJS_GLOBAL_FUNCTION(mark_as_garbage, markAsGarbage)
auto value = TRY(reference.get_value(vm));
if (!can_be_held_weakly(value))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::CannotBeHeldWeakly, String::formatted("Variable with name {}", variable_name.string()));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::CannotBeHeldWeakly, DeprecatedString::formatted("Variable with name {}", variable_name.string()));
vm.heap().uproot_cell(&value.as_cell());
TRY(reference.delete_(vm));
@ -88,7 +88,7 @@ TESTJS_GLOBAL_FUNCTION(detach_array_buffer, detachArrayBuffer)
return JS::js_null();
}
TESTJS_RUN_FILE_FUNCTION(String const& test_file, JS::Interpreter& interpreter, JS::ExecutionContext&)
TESTJS_RUN_FILE_FUNCTION(DeprecatedString const& test_file, JS::Interpreter& interpreter, JS::ExecutionContext&)
{
if (!test262_parser_tests)
return Test::JS::RunFileHookResult::RunAsNormal;
@ -123,8 +123,8 @@ TESTJS_RUN_FILE_FUNCTION(String const& test_file, JS::Interpreter& interpreter,
parse_succeeded = !Test::JS::parse_script(test_file, interpreter.realm()).is_error();
bool test_passed = true;
String message;
String expectation_string;
DeprecatedString message;
DeprecatedString expectation_string;
switch (expectation) {
case Early:

View file

@ -4,13 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/JsonParser.h>
#include <AK/LexicalPath.h>
#include <AK/QuickSort.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
@ -147,7 +147,7 @@ public:
{
}
bool write_lines(Span<String> lines)
bool write_lines(Span<DeprecatedString> lines)
{
// It's possible the process dies before we can write all the tests
// to the stdin. So make sure that we don't crash but just stop writing.
@ -160,8 +160,8 @@ public:
return false;
}
for (String const& line : lines) {
if (!m_output->write_or_error(String::formatted("{}\n", line).bytes()))
for (DeprecatedString const& line : lines) {
if (!m_output->write_or_error(DeprecatedString::formatted("{}\n", line).bytes()))
break;
}
@ -175,14 +175,14 @@ public:
return true;
}
String read_all()
DeprecatedString read_all()
{
auto all_output_or_error = m_input->read_all();
if (all_output_or_error.is_error()) {
warnln("Got error: {} while reading runner output", all_output_or_error.error());
return ""sv;
}
return String(all_output_or_error.value().bytes(), Chomp);
return DeprecatedString(all_output_or_error.value().bytes(), Chomp);
}
enum class ProcessResult {
@ -222,7 +222,7 @@ public:
NonnullOwnPtr<Core::Stream::File> m_output;
};
static HashMap<size_t, TestResult> run_test_files(Span<String> files, size_t offset, StringView command, char const* const arguments[])
static HashMap<size_t, TestResult> run_test_files(Span<DeprecatedString> files, size_t offset, StringView command, char const* const arguments[])
{
HashMap<size_t, TestResult> results {};
results.ensure_capacity(files.size());
@ -246,7 +246,7 @@ static HashMap<size_t, TestResult> run_test_files(Span<String> files, size_t off
return results;
}
String output = runner_process->read_all();
DeprecatedString output = runner_process->read_all();
auto status_or_error = runner_process->status();
bool failed = false;
if (!status_or_error.is_error()) {
@ -297,7 +297,7 @@ static HashMap<size_t, TestResult> run_test_files(Span<String> files, size_t off
return results;
}
void write_per_file(HashMap<size_t, TestResult> const& result_map, Vector<String> const& paths, StringView per_file_name, double time_taken_in_ms);
void write_per_file(HashMap<size_t, TestResult> const& result_map, Vector<DeprecatedString> const& paths, StringView per_file_name, double time_taken_in_ms);
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
@ -320,12 +320,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
args_parser.parse(arguments);
// Normalize the path to ensure filenames are consistent
Vector<String> paths;
Vector<DeprecatedString> paths;
if (!Core::File::is_directory(test_directory)) {
paths.append(test_directory);
} else {
Test::iterate_directory_recursively(LexicalPath::canonicalized_path(test_directory), [&](String const& file_path) {
Test::iterate_directory_recursively(LexicalPath::canonicalized_path(test_directory), [&](DeprecatedString const& file_path) {
if (file_path.contains("_FIXTURE"sv))
return;
// FIXME: Add ignored file set
@ -337,7 +337,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
outln("Found {} tests", paths.size());
auto parameters = pass_through_parameters.split_view(' ');
Vector<String> args;
Vector<DeprecatedString> args;
args.ensure_capacity(parameters.size() + 2);
args.append(runner_command);
if (!dont_disable_core_dump)
@ -408,7 +408,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return 0;
}
void write_per_file(HashMap<size_t, TestResult> const& result_map, Vector<String> const& paths, StringView per_file_name, double time_taken_in_ms)
void write_per_file(HashMap<size_t, TestResult> const& result_map, Vector<DeprecatedString> const& paths, StringView per_file_name, double time_taken_in_ms)
{
auto file_or_error = Core::Stream::File::open(per_file_name, Core::Stream::OpenMode::Write);

View file

@ -5,11 +5,11 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/DeprecatedString.h>
#include <AK/Format.h>
#include <AK/JsonObject.h>
#include <AK/Result.h>
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/Stream.h>
@ -31,11 +31,11 @@
# include <sys/prctl.h>
#endif
static String s_current_test = "";
static DeprecatedString s_current_test = "";
static bool s_use_bytecode = false;
static bool s_enable_bytecode_optimizations = false;
static bool s_parse_only = false;
static String s_harness_file_directory;
static DeprecatedString s_harness_file_directory;
static bool s_automatic_harness_detection_mode = false;
enum class NegativePhase {
@ -47,9 +47,9 @@ enum class NegativePhase {
struct TestError {
NegativePhase phase { NegativePhase::ParseOrEarly };
String type;
String details;
String harness_file;
DeprecatedString type;
DeprecatedString details;
DeprecatedString harness_file;
};
using ScriptOrModuleProgram = Variant<JS::NonnullGCPtr<JS::Script>, JS::NonnullGCPtr<JS::SourceTextModule>>;
@ -93,7 +93,7 @@ static Result<void, TestError> run_program(InterpreterT& interpreter, ScriptOrMo
auto unit_result = JS::Bytecode::Generator::generate(program_node);
if (unit_result.is_error()) {
result = JS::throw_completion(JS::InternalError::create(interpreter.realm(), String::formatted("TODO({})", unit_result.error().to_string())));
result = JS::throw_completion(JS::InternalError::create(interpreter.realm(), DeprecatedString::formatted("TODO({})", unit_result.error().to_string())));
} else {
auto unit = unit_result.release_value();
auto optimization_level = s_enable_bytecode_optimizations ? JS::Bytecode::Interpreter::OptimizationLevel::Optimize : JS::Bytecode::Interpreter::OptimizationLevel::Default;
@ -133,18 +133,18 @@ static Result<void, TestError> run_program(InterpreterT& interpreter, ScriptOrMo
return {};
}
static HashMap<String, String> s_cached_harness_files;
static HashMap<DeprecatedString, DeprecatedString> s_cached_harness_files;
static Result<StringView, TestError> read_harness_file(StringView harness_file)
{
auto cache = s_cached_harness_files.find(harness_file);
if (cache == s_cached_harness_files.end()) {
auto file_or_error = Core::Stream::File::open(String::formatted("{}{}", s_harness_file_directory, harness_file), Core::Stream::OpenMode::Read);
auto file_or_error = Core::Stream::File::open(DeprecatedString::formatted("{}{}", s_harness_file_directory, harness_file), Core::Stream::OpenMode::Read);
if (file_or_error.is_error()) {
return TestError {
NegativePhase::Harness,
"filesystem",
String::formatted("Could not open file: {}", harness_file),
DeprecatedString::formatted("Could not open file: {}", harness_file),
harness_file
};
}
@ -154,7 +154,7 @@ static Result<StringView, TestError> read_harness_file(StringView harness_file)
return TestError {
NegativePhase::Harness,
"filesystem",
String::formatted("Could not read file: {}", harness_file),
DeprecatedString::formatted("Could not read file: {}", harness_file),
harness_file
};
}
@ -264,14 +264,14 @@ static Result<void, TestError> run_test(StringView source, StringView filepath,
return run_with_interpreter(program_or_error.value());
}
static Result<TestMetadata, String> extract_metadata(StringView source)
static Result<TestMetadata, DeprecatedString> extract_metadata(StringView source)
{
auto lines = source.lines();
TestMetadata metadata;
bool parsing_negative = false;
String failed_message;
DeprecatedString failed_message;
auto parse_list = [&](StringView line) {
auto start = line.find('[');
@ -282,7 +282,7 @@ static Result<TestMetadata, String> extract_metadata(StringView source)
auto end = line.find_last(']');
if (!end.has_value() || end.value() <= start.value()) {
failed_message = String::formatted("Can't parse list in '{}'", line);
failed_message = DeprecatedString::formatted("Can't parse list in '{}'", line);
return items;
}
@ -295,7 +295,7 @@ static Result<TestMetadata, String> extract_metadata(StringView source)
auto second_word = [&](StringView line) {
auto separator = line.find(' ');
if (!separator.has_value() || separator.value() >= (line.length() - 1u)) {
failed_message = String::formatted("Can't parse value after space in '{}'", line);
failed_message = DeprecatedString::formatted("Can't parse value after space in '{}'", line);
return ""sv;
}
return line.substring_view(separator.value() + 1);
@ -349,7 +349,7 @@ static Result<TestMetadata, String> extract_metadata(StringView source)
metadata.phase = NegativePhase::Runtime;
} else {
has_phase = false;
failed_message = String::formatted("Unknown negative phase: {}", phase);
failed_message = DeprecatedString::formatted("Unknown negative phase: {}", phase);
break;
}
} else if (line.starts_with("type:"sv)) {
@ -372,7 +372,7 @@ static Result<TestMetadata, String> extract_metadata(StringView source)
auto flags = parse_list(line);
if (flags.is_empty()) {
failed_message = String::formatted("Failed to find flags in '{}'", line);
failed_message = DeprecatedString::formatted("Failed to find flags in '{}'", line);
break;
}
@ -408,7 +408,7 @@ static Result<TestMetadata, String> extract_metadata(StringView source)
}
if (failed_message.is_empty())
failed_message = String::formatted("Never reached end of comment '---*/'");
failed_message = DeprecatedString::formatted("Never reached end of comment '---*/'");
return failed_message;
}
@ -522,7 +522,7 @@ static bool verify_test(Result<void, TestError>& result, TestMetadata const& met
return error.phase == metadata.phase && error.type == metadata.type;
}
static bool extract_harness_directory(String const& test_file_path)
static bool extract_harness_directory(DeprecatedString const& test_file_path)
{
auto test_directory_index = test_file_path.find("test/"sv);
if (!test_directory_index.has_value()) {
@ -530,7 +530,7 @@ static bool extract_harness_directory(String const& test_file_path)
return false;
}
s_harness_file_directory = String::formatted("{}harness/", test_file_path.substring_view(0, test_directory_index.value()));
s_harness_file_directory = DeprecatedString::formatted("{}harness/", test_file_path.substring_view(0, test_directory_index.value()));
return true;
}
@ -568,7 +568,7 @@ extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertio
extern "C" __attribute__((__noreturn__)) void __assert_fail(char const* assertion, char const* file, unsigned int line, char const* function)
# endif
{
auto full_message = String::formatted("{}:{}: {}: Assertion `{}' failed.", file, line, function, assertion);
auto full_message = DeprecatedString::formatted("{}:{}: {}: Assertion `{}' failed.", file, line, function, assertion);
handle_failed_assert(full_message.characters());
}
#endif
@ -605,7 +605,7 @@ int main(int argc, char** argv)
if (s_harness_file_directory.is_empty()) {
s_automatic_harness_detection_mode = true;
} else if (!s_harness_file_directory.ends_with('/')) {
s_harness_file_directory = String::formatted("{}/", s_harness_file_directory);
s_harness_file_directory = DeprecatedString::formatted("{}/", s_harness_file_directory);
}
if (timeout <= 0) {
@ -658,10 +658,10 @@ int main(int argc, char** argv)
auto collect_output = [&] {
fflush(stdout);
auto nread = read(stdout_pipe[0], buffer, BUFFER_SIZE);
String value;
DeprecatedString value;
if (nread > 0) {
value = String { buffer, static_cast<size_t>(nread) };
value = DeprecatedString { buffer, static_cast<size_t>(nread) };
while (nread > 0) {
nread = read(stdout_pipe[0], buffer, BUFFER_SIZE);
}
@ -714,7 +714,7 @@ int main(int argc, char** argv)
count++;
String source_with_strict;
DeprecatedString source_with_strict;
static StringView use_strict = "'use strict';\n"sv;
static size_t strict_length = use_strict.length();
@ -761,7 +761,7 @@ int main(int argc, char** argv)
auto result = run_test(original_contents, path, metadata);
DISARM_TIMER();
String first_output = collect_output();
DeprecatedString first_output = collect_output();
if (!first_output.is_null())
result_object.set("output", first_output);
@ -784,7 +784,7 @@ int main(int argc, char** argv)
auto result = run_test(with_strict, path, metadata);
DISARM_TIMER();
String first_output = collect_output();
DeprecatedString first_output = collect_output();
if (!first_output.is_null())
result_object.set("strict_output", first_output);