mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
AK: Make String::number() infallible
This API will always succeed in creating a String representing the provided number in base-10.
This commit is contained in:
parent
03569fc509
commit
dd419b5a8d
Notes:
github-actions[bot]
2024-10-14 18:49:07 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/dd419b5a8df Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1796
46 changed files with 77 additions and 81 deletions
|
@ -170,9 +170,9 @@ public:
|
|||
[[nodiscard]] u32 ascii_case_insensitive_hash() const;
|
||||
|
||||
template<Arithmetic T>
|
||||
static ErrorOr<String> number(T value)
|
||||
[[nodiscard]] static String number(T value)
|
||||
{
|
||||
return formatted("{}", value);
|
||||
return MUST(formatted("{}", value));
|
||||
}
|
||||
|
||||
template<Arithmetic T>
|
||||
|
|
|
@ -71,8 +71,8 @@ void generate_table(SourceGenerator generator, StringView name, LookupTable& tab
|
|||
{
|
||||
generator.set("name", name);
|
||||
generator.set("value_type", table.max_code_point > NumericLimits<u16>::max() ? "u32" : "u16");
|
||||
generator.set("first_pointer", MUST(String::number(table.first_pointer)));
|
||||
generator.set("size", MUST(String::number(table.code_points.size())));
|
||||
generator.set("first_pointer", String::number(table.first_pointer));
|
||||
generator.set("size", String::number(table.code_points.size()));
|
||||
|
||||
if (table.first_pointer > 0) {
|
||||
generator.appendln("static constexpr u32 s_@name@_index_first_pointer = @first_pointer@;");
|
||||
|
@ -96,7 +96,7 @@ ErrorOr<void> generate_header_file(LookupTables& tables, Core::File& file)
|
|||
StringBuilder builder;
|
||||
SourceGenerator generator { builder };
|
||||
|
||||
generator.set("gb18030_ranges_size", MUST(String::number(tables.gb18030_ranges.size())));
|
||||
generator.set("gb18030_ranges_size", String::number(tables.gb18030_ranges.size()));
|
||||
|
||||
generator.append(R"~~~(
|
||||
#pragma once
|
||||
|
@ -133,8 +133,8 @@ static constexpr Array<Gb18030RangeEntry, @gb18030_ranges_size@> s_gb18030_range
|
|||
void generate_table_accessor(SourceGenerator generator, StringView name, LookupTable& table)
|
||||
{
|
||||
generator.set("name", name);
|
||||
generator.set("first_pointer", MUST(String::number(table.first_pointer)));
|
||||
generator.set("size", MUST(String::number(table.code_points.size())));
|
||||
generator.set("first_pointer", String::number(table.first_pointer));
|
||||
generator.set("size", String::number(table.code_points.size()));
|
||||
|
||||
if (table.first_pointer > 0) {
|
||||
generator.append(R"~~~(
|
||||
|
@ -166,8 +166,8 @@ Optional<u32> index_@name@_code_point(u32 pointer)
|
|||
void generate_inverse_table_accessor(SourceGenerator generator, StringView name, LookupTable& table)
|
||||
{
|
||||
generator.set("name", name);
|
||||
generator.set("first_pointer", MUST(String::number(table.first_pointer)));
|
||||
generator.set("size", MUST(String::number(table.code_points.size())));
|
||||
generator.set("first_pointer", String::number(table.first_pointer));
|
||||
generator.set("size", String::number(table.code_points.size()));
|
||||
|
||||
// FIXME - Doing a linear search here is really slow, should be generating
|
||||
// some kind of reverse lookup table.
|
||||
|
|
|
@ -3762,7 +3762,7 @@ JS_DEFINE_NATIVE_FUNCTION(@class_name@::@attribute.setter_callback@)
|
|||
)~~~");
|
||||
} else if (attribute.type->is_integer() && !attribute.type->is_nullable()) {
|
||||
attribute_generator.append(R"~~~(
|
||||
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, MUST(String::number(cpp_value))));
|
||||
MUST(impl->set_attribute(HTML::AttributeNames::@attribute.reflect_name@, String::number(cpp_value)));
|
||||
)~~~");
|
||||
} else if (attribute.type->is_nullable()) {
|
||||
attribute_generator.append(R"~~~(
|
||||
|
|
|
@ -103,7 +103,7 @@ void generate_hash_table_member(SourceGenerator& generator, StringView member_na
|
|||
member_generator.set("member_name"sv, member_name);
|
||||
member_generator.set("hash_table_name"sv, hash_table_name);
|
||||
member_generator.set("enum_class"sv, enum_class);
|
||||
member_generator.set("hash_table_size"sv, MUST(String::number(values.size())));
|
||||
member_generator.set("hash_table_size"sv, String::number(values.size()));
|
||||
|
||||
if (values.size() == 0) {
|
||||
member_generator.append(R"~~~(
|
||||
|
|
|
@ -188,8 +188,8 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
|
|||
if (parameter.get_bool("required"sv) == true)
|
||||
min_argument_count++;
|
||||
});
|
||||
function_generator.set("min_argument_count", MUST(String::number(min_argument_count)));
|
||||
function_generator.set("max_argument_count", MUST(String::number(max_argument_count)));
|
||||
function_generator.set("min_argument_count", String::number(min_argument_count));
|
||||
function_generator.set("max_argument_count", String::number(max_argument_count));
|
||||
|
||||
function_generator.append(R"~~~(
|
||||
if (arguments.size() < @min_argument_count@ || arguments.size() > @max_argument_count@) {
|
||||
|
@ -209,7 +209,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
|
|||
|
||||
auto parameter_generator = function_generator.fork();
|
||||
parameter_generator.set("parameter_name", parameter.get_byte_string("name"sv).value());
|
||||
parameter_generator.set("parameter_index", MUST(String::number(parameter_index)));
|
||||
parameter_generator.set("parameter_index", String::number(parameter_index));
|
||||
|
||||
bool parameter_is_calculation;
|
||||
if (parameter_type_string == "<rounding-strategy>") {
|
||||
|
@ -319,7 +319,7 @@ OwnPtr<CalculationNode> Parser::parse_math_function(PropertyID property_id, Func
|
|||
auto parameter_type_string = parameter.get_byte_string("type"sv).value();
|
||||
|
||||
auto parameter_generator = function_generator.fork();
|
||||
parameter_generator.set("parameter_index"sv, MUST(String::number(parameter_index)));
|
||||
parameter_generator.set("parameter_index"sv, String::number(parameter_index));
|
||||
|
||||
if (parameter_type_string == "<rounding-strategy>"sv) {
|
||||
parameter_generator.set("release_value"sv, ""_string);
|
||||
|
|
|
@ -134,11 +134,11 @@ TEST_CASE(json_64_bit_value_coerced_to_32_bit)
|
|||
auto min = NumericLimits<i64>::min();
|
||||
auto max = NumericLimits<i64>::max();
|
||||
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(min))));
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(String::number(min)));
|
||||
EXPECT_EQ(json.get_integer<i64>(), min);
|
||||
EXPECT(!json.is_integer<i32>());
|
||||
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(max))));
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(String::number(max)));
|
||||
EXPECT_EQ(json.get_integer<i64>(), max);
|
||||
EXPECT(!json.is_integer<i32>());
|
||||
}
|
||||
|
@ -146,11 +146,11 @@ TEST_CASE(json_64_bit_value_coerced_to_32_bit)
|
|||
auto min = NumericLimits<u64>::min();
|
||||
auto max = NumericLimits<u64>::max();
|
||||
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(min))));
|
||||
auto json = TRY_OR_FAIL(JsonValue::from_string(String::number(min)));
|
||||
EXPECT_EQ(json.get_integer<u64>(), min);
|
||||
EXPECT_EQ(json.get_integer<u32>(), min);
|
||||
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(MUST(String::number(max))));
|
||||
json = TRY_OR_FAIL(JsonValue::from_string(String::number(max)));
|
||||
EXPECT_EQ(json.get_integer<u64>(), max);
|
||||
EXPECT(!json.is_integer<u32>());
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ public:
|
|||
BasicBlock& make_block(String name = {})
|
||||
{
|
||||
if (name.is_empty())
|
||||
name = MUST(String::number(m_next_block++));
|
||||
name = String::number(m_next_block++);
|
||||
auto block = BasicBlock::create(m_root_basic_blocks.size(), name);
|
||||
if (auto const* context = m_current_unwind_context) {
|
||||
if (context->handler().has_value())
|
||||
|
|
|
@ -1720,7 +1720,7 @@ inline ThrowCompletionOr<Object*> get_object_property_iterator(VM& vm, Value val
|
|||
result_object->define_direct_property(vm.names.done, JS::Value(false), default_attributes);
|
||||
|
||||
if (key.is_number())
|
||||
result_object->define_direct_property(vm.names.value, PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, String::number(key.as_number()))), default_attributes);
|
||||
result_object->define_direct_property(vm.names.value, PrimitiveString::create(vm, String::number(key.as_number())), default_attributes);
|
||||
else if (key.is_string())
|
||||
result_object->define_direct_property(vm.names.value, PrimitiveString::create(vm, key.as_string()), default_attributes);
|
||||
else
|
||||
|
|
|
@ -113,7 +113,7 @@ ErrorOr<void> MarkupGenerator::object_to_html(Object const& object, StringBuilde
|
|||
if (!first)
|
||||
TRY(html_output.try_append(TRY(wrap_string_in_style(", "sv, StyleType::Punctuation))));
|
||||
first = false;
|
||||
TRY(html_output.try_append(TRY(wrap_string_in_style(TRY(String::number(entry.index())), StyleType::Number))));
|
||||
TRY(html_output.try_append(TRY(wrap_string_in_style(String::number(entry.index()), StyleType::Number))));
|
||||
TRY(html_output.try_append(TRY(wrap_string_in_style(": "sv, StyleType::Punctuation))));
|
||||
// FIXME: Exception check
|
||||
TRY(value_to_html(object.get(entry.index()).release_value(), html_output, seen_objects));
|
||||
|
|
|
@ -152,14 +152,14 @@ ThrowCompletionOr<MarkedVector<Value>> StringObject::internal_own_property_keys(
|
|||
// 5. For each integer i starting with 0 such that i < len, in ascending order, do
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
// a. Add ! ToString(𝔽(i)) as the last element of keys.
|
||||
keys.append(PrimitiveString::create(vm, MUST(String::number(i))));
|
||||
keys.append(PrimitiveString::create(vm, String::number(i)));
|
||||
}
|
||||
|
||||
// 6. For each own property key P of O such that P is an array index and ! ToIntegerOrInfinity(P) ≥ len, in ascending numeric index order, do
|
||||
for (auto& entry : indexed_properties()) {
|
||||
if (entry.index() >= length) {
|
||||
// a. Add P as the last element of keys.
|
||||
keys.append(PrimitiveString::create(vm, MUST(String::number(entry.index()))));
|
||||
keys.append(PrimitiveString::create(vm, String::number(entry.index())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -425,7 +425,7 @@ public:
|
|||
// b. For each integer i such that 0 ≤ i < length, in ascending order, do
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
// i. Append ! ToString(𝔽(i)) to keys.
|
||||
keys.append(PrimitiveString::create(vm, MUST(String::number(i))));
|
||||
keys.append(PrimitiveString::create(vm, String::number(i)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ String Value::to_string_without_side_effects() const
|
|||
case BOOLEAN_TAG:
|
||||
return as_bool() ? "true"_string : "false"_string;
|
||||
case INT32_TAG:
|
||||
return String::number(as_i32()).release_value();
|
||||
return String::number(as_i32());
|
||||
case STRING_TAG:
|
||||
return as_string().utf8_string();
|
||||
case SYMBOL_TAG:
|
||||
|
@ -418,7 +418,7 @@ ThrowCompletionOr<String> Value::to_string(VM& vm) const
|
|||
return as_bool() ? "true"_string : "false"_string;
|
||||
// 7. If argument is a Number, return Number::toString(argument, 10).
|
||||
case INT32_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, String::number(as_i32()));
|
||||
return String::number(as_i32());
|
||||
// 8. If argument is a BigInt, return BigInt::toString(argument, 10).
|
||||
case BIGINT_TAG:
|
||||
return TRY_OR_THROW_OOM(vm, as_bigint().big_integer().to_base(10));
|
||||
|
|
|
@ -405,7 +405,7 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> PlatformObject::internal_own_
|
|||
if (m_legacy_platform_object_flags->supports_indexed_properties) {
|
||||
for (u64 index = 0; index <= NumericLimits<u32>::max(); ++index) {
|
||||
if (is_supported_property_index(index))
|
||||
keys.append(JS::PrimitiveString::create(vm, MUST(String::number(index))));
|
||||
keys.append(JS::PrimitiveString::create(vm, String::number(index)));
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ String MediaFeatureValue::to_string() const
|
|||
[](Length const& length) { return length.to_string(); },
|
||||
[](Ratio const& ratio) { return ratio.to_string(); },
|
||||
[](Resolution const& resolution) { return resolution.to_string(); },
|
||||
[](float number) { return MUST(String::number(number)); });
|
||||
[](float number) { return String::number(number); });
|
||||
}
|
||||
|
||||
bool MediaFeatureValue::is_same_type(MediaFeatureValue const& other) const
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
{
|
||||
if (m_type == Type::IntegerWithExplicitSign)
|
||||
return MUST(String::formatted("{:+}", m_value));
|
||||
return MUST(String::number(m_value));
|
||||
return String::number(m_value);
|
||||
}
|
||||
|
||||
bool operator==(Number const& other) const
|
||||
|
|
|
@ -43,7 +43,7 @@ String Token::to_string() const
|
|||
case Type::Delim:
|
||||
return String { m_value };
|
||||
case Type::Number:
|
||||
return MUST(String::number(m_number_value.value()));
|
||||
return String::number(m_number_value.value());
|
||||
case Type::Percentage:
|
||||
return MUST(String::formatted("{}%", m_number_value.value()));
|
||||
case Type::Dimension:
|
||||
|
|
|
@ -102,7 +102,7 @@ public:
|
|||
{
|
||||
// 1. If A is zero, return the serialization of B.
|
||||
if (step_size == 0) {
|
||||
return MUST(String::number(offset));
|
||||
return String::number(offset);
|
||||
}
|
||||
|
||||
// 2. Otherwise, let result initially be an empty string.
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Web::CSS {
|
|||
|
||||
String IntegerStyleValue::to_string() const
|
||||
{
|
||||
return MUST(String::number(m_value));
|
||||
return String::number(m_value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Web::CSS {
|
|||
|
||||
String NumberStyleValue::to_string() const
|
||||
{
|
||||
return MUST(String::number(m_value));
|
||||
return String::number(m_value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ String TransformationStyleValue::to_string() const
|
|||
|| m_properties.transform_function == CSS::TransformFunction::ScaleY
|
||||
|| m_properties.transform_function == CSS::TransformFunction::ScaleZ)
|
||||
&& value->is_percentage()) {
|
||||
builder.append(MUST(String::number(value->as_percentage().percentage().as_fraction())));
|
||||
builder.append(String::number(value->as_percentage().percentage().as_fraction()));
|
||||
} else {
|
||||
builder.append(value->to_string());
|
||||
}
|
||||
|
|
|
@ -1208,7 +1208,7 @@ i32 Element::tab_index() const
|
|||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
|
||||
void Element::set_tab_index(i32 tab_index)
|
||||
{
|
||||
MUST(set_attribute(HTML::AttributeNames::tabindex, MUST(String::number(tab_index))));
|
||||
MUST(set_attribute(HTML::AttributeNames::tabindex, String::number(tab_index)));
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#potentially-scrollable
|
||||
|
|
|
@ -836,7 +836,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r
|
|||
auto full_length = blob->size();
|
||||
|
||||
// 6. Let serializedFullLength be fullLength, serialized and isomorphic encoded.
|
||||
auto serialized_full_length = TRY_OR_THROW_OOM(vm, String::number(full_length));
|
||||
auto serialized_full_length = String::number(full_length);
|
||||
|
||||
// 7. Let type be blob’s type.
|
||||
auto const& type = blob->type();
|
||||
|
@ -1627,7 +1627,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
|
|||
// 8. If contentLength is non-null, then set contentLengthHeaderValue to contentLength, serialized and
|
||||
// isomorphic encoded.
|
||||
if (content_length.has_value())
|
||||
content_length_header_value = MUST(ByteBuffer::copy(TRY_OR_THROW_OOM(vm, String::number(*content_length)).bytes()));
|
||||
content_length_header_value = MUST(ByteBuffer::copy(String::number(*content_length).bytes()));
|
||||
|
||||
// 9. If contentLengthHeaderValue is non-null, then append (`Content-Length`, contentLengthHeaderValue) to
|
||||
// httpRequest’s header list.
|
||||
|
|
|
@ -272,14 +272,14 @@ void Request::add_range_header(u64 first, Optional<u64> const& last)
|
|||
auto range_value = MUST(ByteBuffer::copy("bytes"sv.bytes()));
|
||||
|
||||
// 3. Serialize and isomorphic encode first, and append the result to rangeValue.
|
||||
range_value.append(MUST(String::number(first)).bytes());
|
||||
range_value.append(String::number(first).bytes());
|
||||
|
||||
// 4. Append 0x2D (-) to rangeValue.
|
||||
range_value.append('-');
|
||||
|
||||
// 5. If last is given, then serialize and isomorphic encode it, and append the result to rangeValue.
|
||||
if (last.has_value())
|
||||
range_value.append(MUST(String::number(*last)).bytes());
|
||||
range_value.append(String::number(*last).bytes());
|
||||
|
||||
// 6. Append (`Range`, rangeValue) to request’s header list.
|
||||
auto header = Header {
|
||||
|
|
|
@ -57,7 +57,7 @@ void AudioTrack::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(AudioTrack);
|
||||
|
||||
auto id = s_audio_track_id_allocator.allocate();
|
||||
m_id = MUST(String::number(id));
|
||||
m_id = String::number(id);
|
||||
}
|
||||
|
||||
void AudioTrack::play(Badge<HTMLAudioElement>)
|
||||
|
|
|
@ -121,10 +121,10 @@ WebIDL::ExceptionOr<Optional<Vector<XHR::FormDataEntry>>> construct_entry_list(J
|
|||
auto [x, y] = input_element->selected_coordinate();
|
||||
|
||||
// 6. Create an entry with namex and x, and append it to entry list.
|
||||
entry_list.append(XHR::FormDataEntry { .name = move(name_x), .value = MUST(String::number(x)) });
|
||||
entry_list.append(XHR::FormDataEntry { .name = move(name_x), .value = String::number(x) });
|
||||
|
||||
// 7. Create an entry with namey and y, and append it to entry list.
|
||||
entry_list.append(XHR::FormDataEntry { .name = move(name_y), .value = MUST(String::number(y)) });
|
||||
entry_list.append(XHR::FormDataEntry { .name = move(name_y), .value = String::number(y) });
|
||||
|
||||
// 8. Continue.
|
||||
continue;
|
||||
|
|
|
@ -114,7 +114,7 @@ void HTMLCanvasElement::reset_context_to_default_state()
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLCanvasElement::set_width(unsigned value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::width, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::width, String::number(value)));
|
||||
m_bitmap = nullptr;
|
||||
reset_context_to_default_state();
|
||||
return {};
|
||||
|
@ -122,7 +122,7 @@ WebIDL::ExceptionOr<void> HTMLCanvasElement::set_width(unsigned value)
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLCanvasElement::set_height(unsigned value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::height, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::height, String::number(value)));
|
||||
m_bitmap = nullptr;
|
||||
reset_context_to_default_state();
|
||||
return {};
|
||||
|
|
|
@ -244,7 +244,7 @@ String HTMLHyperlinkElementUtils::port() const
|
|||
return String {};
|
||||
|
||||
// 4. Return url's port, serialized.
|
||||
return MUST(String::number(url->port().value()));
|
||||
return String::number(url->port().value());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-port
|
||||
|
|
|
@ -191,7 +191,7 @@ unsigned HTMLImageElement::width() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLImageElement::set_width(unsigned width)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::width, MUST(String::number(width)));
|
||||
return set_attribute(HTML::AttributeNames::width, String::number(width));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-height
|
||||
|
@ -220,7 +220,7 @@ unsigned HTMLImageElement::height() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLImageElement::set_height(unsigned height)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::height, MUST(String::number(height)));
|
||||
return set_attribute(HTML::AttributeNames::height, String::number(height));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-naturalwidth
|
||||
|
|
|
@ -1866,7 +1866,7 @@ unsigned HTMLInputElement::size() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLInputElement::set_size(unsigned value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::size, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::size, String::number(value));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#concept-input-value-string-number
|
||||
|
@ -1889,11 +1889,11 @@ String HTMLInputElement::convert_number_to_string(double input) const
|
|||
{
|
||||
// https://html.spec.whatwg.org/multipage/input.html#number-state-(type=number):concept-input-value-number-string
|
||||
if (type_state() == TypeAttributeState::Number)
|
||||
return MUST(String::number(input));
|
||||
return String::number(input);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#range-state-(type=range):concept-input-value-number-string
|
||||
if (type_state() == TypeAttributeState::Range)
|
||||
return MUST(String::number(input));
|
||||
return String::number(input);
|
||||
|
||||
dbgln("HTMLInputElement::convert_number_to_string() not implemented for input type {}", type());
|
||||
return {};
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
i32 value() { return get_attribute(AttributeNames::value).value_or("0"_string).to_number<i32>().value_or(0); }
|
||||
void set_value(i32 value)
|
||||
{
|
||||
set_attribute(AttributeNames::value, MUST(String::number(value))).release_value_but_fixme_should_propagate_errors();
|
||||
set_attribute(AttributeNames::value, String::number(value)).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -76,7 +76,7 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_amount()
|
|||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrollamount
|
||||
WebIDL::ExceptionOr<void> HTMLMarqueeElement::set_scroll_amount(WebIDL::UnsignedLong value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::scrollamount, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::scrollamount, String::number(value));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrolldelay
|
||||
|
@ -93,7 +93,7 @@ WebIDL::UnsignedLong HTMLMarqueeElement::scroll_delay()
|
|||
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-marquee-scrolldelay
|
||||
WebIDL::ExceptionOr<void> HTMLMarqueeElement::set_scroll_delay(WebIDL::UnsignedLong value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::scrolldelay, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::scrolldelay, String::number(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ double HTMLMeterElement::value() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_value(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::value, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::value, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ double HTMLMeterElement::min() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_min(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::min, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::min, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ double HTMLMeterElement::max() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_max(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::max, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::max, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ double HTMLMeterElement::low() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_low(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::low, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::low, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ double HTMLMeterElement::high() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_high(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::high, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::high, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ double HTMLMeterElement::optimum() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLMeterElement::set_optimum(double value)
|
||||
{
|
||||
TRY(set_attribute(HTML::AttributeNames::optimum, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::optimum, String::number(value)));
|
||||
update_meter_value_element();
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
i32 start() { return get_attribute(AttributeNames::start).value_or("1"_string).to_number<i32>().value_or(1); }
|
||||
void set_start(i32 start)
|
||||
{
|
||||
set_attribute(AttributeNames::start, MUST(String::number(start))).release_value_but_fixme_should_propagate_errors();
|
||||
set_attribute(AttributeNames::start, String::number(start)).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -54,7 +54,7 @@ WebIDL::ExceptionOr<void> HTMLProgressElement::set_value(double value)
|
|||
if (value < 0)
|
||||
value = 0;
|
||||
|
||||
TRY(set_attribute(HTML::AttributeNames::value, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::value, String::number(value)));
|
||||
update_progress_value_element();
|
||||
return {};
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ WebIDL::ExceptionOr<void> HTMLProgressElement::set_max(double value)
|
|||
if (value <= 0)
|
||||
value = 1;
|
||||
|
||||
TRY(set_attribute(HTML::AttributeNames::max, MUST(String::number(value))));
|
||||
TRY(set_attribute(HTML::AttributeNames::max, String::number(value)));
|
||||
update_progress_value_element();
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ WebIDL::UnsignedLong HTMLSelectElement::size() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLSelectElement::set_size(WebIDL::UnsignedLong size)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::size, MUST(String::number(size)));
|
||||
return set_attribute(HTML::AttributeNames::size, String::number(size));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options
|
||||
|
|
|
@ -129,7 +129,7 @@ unsigned int HTMLTableCellElement::col_span() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_col_span(unsigned int value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::colspan, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::colspan, String::number(value));
|
||||
}
|
||||
|
||||
// This implements step 9 in the spec here:
|
||||
|
@ -149,7 +149,7 @@ unsigned int HTMLTableCellElement::row_span() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLTableCellElement::set_row_span(unsigned int value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::rowspan, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::rowspan, String::number(value));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/tables.html#dom-tdth-cellindex
|
||||
|
|
|
@ -41,7 +41,7 @@ unsigned int HTMLTableColElement::span() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLTableColElement::set_span(unsigned int value)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::span, MUST(String::number(value)));
|
||||
return set_attribute(HTML::AttributeNames::span, String::number(value));
|
||||
}
|
||||
|
||||
void HTMLTableColElement::apply_presentational_hints(CSS::StyleProperties& style) const
|
||||
|
|
|
@ -299,7 +299,7 @@ unsigned HTMLTextAreaElement::cols() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_cols(unsigned cols)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::cols, MUST(String::number(cols)));
|
||||
return set_attribute(HTML::AttributeNames::cols, String::number(cols));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-rows
|
||||
|
@ -315,7 +315,7 @@ unsigned HTMLTextAreaElement::rows() const
|
|||
|
||||
WebIDL::ExceptionOr<void> HTMLTextAreaElement::set_rows(unsigned rows)
|
||||
{
|
||||
return set_attribute(HTML::AttributeNames::rows, MUST(String::number(rows)));
|
||||
return set_attribute(HTML::AttributeNames::rows, String::number(rows));
|
||||
}
|
||||
|
||||
WebIDL::UnsignedLong HTMLTextAreaElement::selection_start_binding() const
|
||||
|
|
|
@ -251,8 +251,6 @@ WebIDL::ExceptionOr<void> Location::set_hostname(String const&)
|
|||
// https://html.spec.whatwg.org/multipage/history.html#dom-location-port
|
||||
WebIDL::ExceptionOr<String> Location::port() const
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// 1. If this's relevant Document is non-null and its origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException.
|
||||
auto const relevant_document = this->relevant_document();
|
||||
if (relevant_document && !relevant_document->origin().is_same_origin_domain(entry_settings_object().origin()))
|
||||
|
@ -265,7 +263,7 @@ WebIDL::ExceptionOr<String> Location::port() const
|
|||
return String {};
|
||||
|
||||
// 3. Return this's url's port, serialized.
|
||||
return TRY_OR_THROW_OOM(vm, String::number(*url.port()));
|
||||
return String::number(*url.port());
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> Location::set_port(String const&)
|
||||
|
|
|
@ -167,7 +167,7 @@ JS::GCPtr<Navigable> Navigable::navigable_with_active_document(JS::NonnullGCPtr<
|
|||
ErrorOr<void> Navigable::initialize_navigable(JS::NonnullGCPtr<DocumentState> document_state, JS::GCPtr<Navigable> parent)
|
||||
{
|
||||
static int next_id = 0;
|
||||
m_id = TRY(String::number(next_id++));
|
||||
m_id = String::number(next_id++);
|
||||
|
||||
// 1. Assert: documentState's document is non-null.
|
||||
VERIFY(document_state->document());
|
||||
|
|
|
@ -129,7 +129,7 @@ WebIDL::ExceptionOr<String> convert_non_negative_integer_to_string(JS::Realm& re
|
|||
{
|
||||
if (value < 0)
|
||||
return WebIDL::IndexSizeError::create(realm, "The attribute is limited to only non-negative numbers"_string);
|
||||
return MUST(String::number(value));
|
||||
return String::number(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, URL::URL const& creation
|
|||
// settings object's target browsing context to null,
|
||||
// and settings object's active service worker to null.
|
||||
static i64 next_id = 1;
|
||||
settings_object->id = MUST(String::number(next_id++));
|
||||
settings_object->id = String::number(next_id++);
|
||||
settings_object->target_browsing_context = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ void VideoTrack::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(VideoTrack);
|
||||
|
||||
auto id = s_video_track_id_allocator.allocate();
|
||||
m_id = MUST(String::number(id));
|
||||
m_id = String::number(id);
|
||||
}
|
||||
|
||||
void VideoTrack::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
|
@ -78,8 +78,6 @@ WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
|
|||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-port
|
||||
WebIDL::ExceptionOr<String> WorkerLocation::port() const
|
||||
{
|
||||
auto& vm = realm().vm();
|
||||
|
||||
// The port getter steps are:
|
||||
// 1. Let port be this's WorkerGlobalScope object's url's port.
|
||||
auto const& port = m_global_scope->url().port();
|
||||
|
@ -88,7 +86,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::port() const
|
|||
if (!port.has_value())
|
||||
return String {};
|
||||
// 3. Return port, serialized.
|
||||
return TRY_OR_THROW_OOM(vm, String::number(port.value()));
|
||||
return String::number(port.value());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-pathname
|
||||
|
|
|
@ -40,7 +40,7 @@ static String style_sheet_identifier_to_json(Web::CSS::StyleSheetIdentifier cons
|
|||
{
|
||||
return MUST(String::formatted("{{ type: '{}', domNodeId: {}, url: '{}' }}"sv,
|
||||
Web::CSS::style_sheet_identifier_type_to_string(identifier.type),
|
||||
identifier.dom_element_unique_id.map([](auto& it) { return MUST(String::number(it)); }).value_or("undefined"_string),
|
||||
identifier.dom_element_unique_id.map([](auto& it) { return String::number(it); }).value_or("undefined"_string),
|
||||
identifier.url.value_or("undefined"_string)));
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ String ProcessManager::generate_html()
|
|||
builder.appendff(" - {}", escape_html_entities(*process_handle.title()));
|
||||
builder.append("</td>"sv);
|
||||
builder.append("<td>"sv);
|
||||
builder.append(MUST(String::number(process.pid)));
|
||||
builder.append(String::number(process.pid));
|
||||
builder.append("</td>"sv);
|
||||
builder.append("<td>"sv);
|
||||
builder.append(human_readable_size(process.memory_usage_bytes));
|
||||
|
|
Loading…
Reference in a new issue