1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:37:43 +00:00

LibJS: Remove DeprecatedString usage from SourceCode

This change also requires updates to some users of the SourceCode
interface since it no longer use DeprecatedString.
This commit is contained in:
Evan Smal 2023-01-26 08:33:18 -05:00 committed by Linus Groh
parent 82a152b696
commit 93674e4383
6 changed files with 19 additions and 19 deletions

View file

@ -4962,9 +4962,9 @@ ModuleRequest::ModuleRequest(DeprecatedFlyString module_specifier_, Vector<Asser
});
}
DeprecatedString const& SourceRange::filename() const
DeprecatedString SourceRange::filename() const
{
return code->filename();
return code->filename().to_deprecated_string();
}
NonnullRefPtr<CallExpression> CallExpression::create(SourceRange source_range, NonnullRefPtr<Expression> callee, Span<Argument const> arguments)

View file

@ -409,7 +409,7 @@ Parser::ParserState::ParserState(Lexer l, Program::Type program_type)
}
Parser::Parser(Lexer lexer, Program::Type program_type, Optional<EvalInitialState> 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)
{

View file

@ -54,7 +54,7 @@ ThrowCompletionOr<void> 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 == "<unknown>"sv)
stack_string_builder.appendff(" at {}:{}:{}\n", frame.source_range.filename(), frame.source_range.start.line, frame.source_range.start.column);

View file

@ -12,23 +12,23 @@
namespace JS {
NonnullRefPtr<SourceCode> SourceCode::create(DeprecatedString filename, DeprecatedString code)
NonnullRefPtr<SourceCode> 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.

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibJS/Forward.h>
@ -14,20 +14,20 @@ namespace JS {
class SourceCode : public RefCounted<SourceCode> {
public:
static NonnullRefPtr<SourceCode> create(DeprecatedString filename, DeprecatedString code);
static NonnullRefPtr<SourceCode> 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<Vector<size_t>> mutable m_line_break_offsets;
};

View file

@ -25,7 +25,7 @@ struct SourceRange {
Position start;
Position end;
DeprecatedString const& filename() const;
DeprecatedString filename() const;
};
}