From 93674e4383f7ae664442d454a9317113f8fe578d Mon Sep 17 00:00:00 2001 From: Evan Smal Date: Thu, 26 Jan 2023 08:33:18 -0500 Subject: [PATCH] LibJS: Remove DeprecatedString usage from SourceCode This change also requires updates to some users of the SourceCode interface since it no longer use DeprecatedString. --- Userland/Libraries/LibJS/AST.cpp | 4 ++-- Userland/Libraries/LibJS/Parser.cpp | 2 +- Userland/Libraries/LibJS/Runtime/Error.cpp | 4 ++-- Userland/Libraries/LibJS/SourceCode.cpp | 12 ++++++------ Userland/Libraries/LibJS/SourceCode.h | 14 +++++++------- Userland/Libraries/LibJS/SourceRange.h | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index f11092b499..370b675bcf 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -4962,9 +4962,9 @@ ModuleRequest::ModuleRequest(DeprecatedFlyString module_specifier_, Vectorfilename(); + return code->filename().to_deprecated_string(); } NonnullRefPtr CallExpression::create(SourceRange source_range, NonnullRefPtr callee, Span arguments) diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 426b996793..494514d6ec 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -409,7 +409,7 @@ Parser::ParserState::ParserState(Lexer l, Program::Type program_type) } Parser::Parser(Lexer lexer, Program::Type program_type, Optional initial_state_for_eval) - : m_source_code(SourceCode::create(lexer.filename(), lexer.source())) + : m_source_code(SourceCode::create(String::from_deprecated_string(lexer.filename()).release_value_but_fixme_should_propagate_errors(), String::from_deprecated_string(lexer.source()).release_value_but_fixme_should_propagate_errors())) , m_state(move(lexer), program_type) , m_program_type(program_type) { diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index ea377a5565..ffde022808 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -54,7 +54,7 @@ ThrowCompletionOr Error::install_error_cause(Value options) void Error::populate_stack() { - static auto dummy_source_range = SourceRange { .code = SourceCode::create("", ""), .start = {}, .end = {} }; + static auto dummy_source_range = SourceRange { .code = SourceCode::create(String {}, String {}), .start = {}, .end = {} }; auto& vm = this->vm(); m_traceback.ensure_capacity(vm.execution_context_stack().size()); @@ -84,7 +84,7 @@ DeprecatedString Error::stack_string() const auto const& frame = m_traceback[i]; auto function_name = frame.function_name; // Note: Since we don't know whether we have a valid SourceRange here we just check for some default values. - if (!frame.source_range.filename().is_null() || frame.source_range.start.offset != 0 || frame.source_range.end.offset != 0) { + if (!frame.source_range.filename().is_empty() || frame.source_range.start.offset != 0 || frame.source_range.end.offset != 0) { if (function_name == ""sv) stack_string_builder.appendff(" at {}:{}:{}\n", frame.source_range.filename(), frame.source_range.start.line, frame.source_range.start.column); diff --git a/Userland/Libraries/LibJS/SourceCode.cpp b/Userland/Libraries/LibJS/SourceCode.cpp index 26bc90e360..3df5758ab9 100644 --- a/Userland/Libraries/LibJS/SourceCode.cpp +++ b/Userland/Libraries/LibJS/SourceCode.cpp @@ -12,23 +12,23 @@ namespace JS { -NonnullRefPtr SourceCode::create(DeprecatedString filename, DeprecatedString code) +NonnullRefPtr SourceCode::create(String filename, String code) { return adopt_ref(*new SourceCode(move(filename), move(code))); } -SourceCode::SourceCode(DeprecatedString filename, DeprecatedString code) +SourceCode::SourceCode(String filename, String code) : m_filename(move(filename)) , m_code(move(code)) { } -DeprecatedString const& SourceCode::filename() const +String const& SourceCode::filename() const { return m_filename; } -DeprecatedString const& SourceCode::code() const +String const& SourceCode::code() const { return m_code; } @@ -41,7 +41,7 @@ void SourceCode::compute_line_break_offsets() const return; bool previous_code_point_was_carriage_return = false; - Utf8View view(m_code.view()); + Utf8View view(m_code); for (auto it = view.begin(); it != view.end(); ++it) { u32 code_point = *it; bool is_line_terminator = code_point == '\r' || (code_point == '\n' && !previous_code_point_was_carriage_return) || code_point == LINE_SEPARATOR || code_point == PARAGRAPH_SEPARATOR; @@ -78,7 +78,7 @@ SourceRange SourceCode::range_from_offsets(u32 start_offset, u32 end_offset) con bool previous_code_point_was_carriage_return = false; - Utf8View view(m_code.view()); + Utf8View view(m_code); for (auto it = view.iterator_at_byte_offset_without_validation(nearest_preceding_line_break_offset); it != view.end(); ++it) { // If we're on or after the start offset, this is the start position. diff --git a/Userland/Libraries/LibJS/SourceCode.h b/Userland/Libraries/LibJS/SourceCode.h index a900ebea71..1550c50c89 100644 --- a/Userland/Libraries/LibJS/SourceCode.h +++ b/Userland/Libraries/LibJS/SourceCode.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -14,20 +14,20 @@ namespace JS { class SourceCode : public RefCounted { public: - static NonnullRefPtr create(DeprecatedString filename, DeprecatedString code); + static NonnullRefPtr create(String filename, String code); - DeprecatedString const& filename() const; - DeprecatedString const& code() const; + String const& filename() const; + String const& code() const; SourceRange range_from_offsets(u32 start_offset, u32 end_offset) const; private: - SourceCode(DeprecatedString filename, DeprecatedString code); + SourceCode(String filename, String code); void compute_line_break_offsets() const; - DeprecatedString m_filename; - DeprecatedString m_code; + String m_filename; + String m_code; Optional> mutable m_line_break_offsets; }; diff --git a/Userland/Libraries/LibJS/SourceRange.h b/Userland/Libraries/LibJS/SourceRange.h index 7620a8ef57..71f3d2ba52 100644 --- a/Userland/Libraries/LibJS/SourceRange.h +++ b/Userland/Libraries/LibJS/SourceRange.h @@ -25,7 +25,7 @@ struct SourceRange { Position start; Position end; - DeprecatedString const& filename() const; + DeprecatedString filename() const; }; }