mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibJS+LibWeb: Let WrapperGenerator deal with legacy_null_to_empty_string
This concept is not present in ECMAScript, and it bothers me every time I see it. It's only used by WrapperGenerator, and even there only relevant in two places, so let's fully remove it from LibJS and use a simple ternary expression instead: cpp_name = js_name.is_null() && legacy_null_to_empty_string ? String::empty() : js_name.to_string(global_object);
This commit is contained in:
parent
8ea79c05db
commit
44e70d1bc0
Notes:
sideshowbarker
2024-07-18 02:48:43 +09:00
Author: https://github.com/linusg
Commit: 44e70d1bc0
Pull-request: https://github.com/SerenityOS/serenity/pull/10445
Reviewed-by: https://github.com/Lubrsi ✅
3 changed files with 10 additions and 6 deletions
|
@ -906,7 +906,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
if (!optional) {
|
if (!optional) {
|
||||||
if (!parameter.type.nullable) {
|
if (!parameter.type.nullable) {
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
auto @cpp_name@ = @js_name@@js_suffix@.to_string(global_object, @legacy_null_to_empty_string@);
|
auto @cpp_name@ = @js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@
|
||||||
|
? String::empty()
|
||||||
|
: @js_name@@js_suffix@.to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
@return_statement@
|
@return_statement@
|
||||||
)~~~");
|
)~~~");
|
||||||
|
@ -914,7 +916,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
String @cpp_name@;
|
String @cpp_name@;
|
||||||
if (!@js_name@@js_suffix@.is_nullish()) {
|
if (!@js_name@@js_suffix@.is_nullish()) {
|
||||||
@cpp_name@ = @js_name@@js_suffix@.to_string(global_object, @legacy_null_to_empty_string@);
|
@cpp_name@ = @js_name@@js_suffix@.to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
@return_statement@
|
@return_statement@
|
||||||
}
|
}
|
||||||
|
@ -924,7 +926,9 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
|
||||||
scoped_generator.append(R"~~~(
|
scoped_generator.append(R"~~~(
|
||||||
String @cpp_name@;
|
String @cpp_name@;
|
||||||
if (!@js_name@@js_suffix@.is_undefined()) {
|
if (!@js_name@@js_suffix@.is_undefined()) {
|
||||||
@cpp_name@ = @js_name@@js_suffix@.to_string(global_object, @legacy_null_to_empty_string@);
|
@cpp_name@ = @js_name@@js_suffix@.is_null() && @legacy_null_to_empty_string@
|
||||||
|
? String::empty()
|
||||||
|
: @js_name@@js_suffix@.to_string(global_object);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
@return_statement@
|
@return_statement@
|
||||||
})~~~");
|
})~~~");
|
||||||
|
|
|
@ -333,13 +333,13 @@ PrimitiveString* Value::to_primitive_string(GlobalObject& global_object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7.1.17 ToString ( argument ), https://tc39.es/ecma262/#sec-tostring
|
// 7.1.17 ToString ( argument ), https://tc39.es/ecma262/#sec-tostring
|
||||||
String Value::to_string(GlobalObject& global_object, bool legacy_null_to_empty_string) const
|
String Value::to_string(GlobalObject& global_object) const
|
||||||
{
|
{
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Type::Undefined:
|
case Type::Undefined:
|
||||||
return "undefined";
|
return "undefined";
|
||||||
case Type::Null:
|
case Type::Null:
|
||||||
return !legacy_null_to_empty_string ? "null" : String::empty();
|
return "null";
|
||||||
case Type::Boolean:
|
case Type::Boolean:
|
||||||
return m_value.as_bool ? "true" : "false";
|
return m_value.as_bool ? "true" : "false";
|
||||||
case Type::Int32:
|
case Type::Int32:
|
||||||
|
|
|
@ -303,7 +303,7 @@ public:
|
||||||
|
|
||||||
u64 encoded() const { return m_value.encoded; }
|
u64 encoded() const { return m_value.encoded; }
|
||||||
|
|
||||||
String to_string(GlobalObject&, bool legacy_null_to_empty_string = false) const;
|
String to_string(GlobalObject&) const;
|
||||||
Utf16String to_utf16_string(GlobalObject&) const;
|
Utf16String to_utf16_string(GlobalObject&) const;
|
||||||
PrimitiveString* to_primitive_string(GlobalObject&);
|
PrimitiveString* to_primitive_string(GlobalObject&);
|
||||||
Value to_primitive(GlobalObject&, PreferredType preferred_type = PreferredType::Default) const;
|
Value to_primitive(GlobalObject&, PreferredType preferred_type = PreferredType::Default) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue