mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:02:43 +00:00 
			
		
		
		
	LibJS: Use string::formatted() in to_string() functions
This commit is contained in:
		
							parent
							
								
									bc701658f8
								
							
						
					
					
						commit
						2e2571743b
					
				
					 8 changed files with 11 additions and 12 deletions
				
			
		|  | @ -38,7 +38,7 @@ public: | ||||||
|     virtual ~BigInt(); |     virtual ~BigInt(); | ||||||
| 
 | 
 | ||||||
|     const Crypto::SignedBigInteger& big_integer() const { return m_big_integer; } |     const Crypto::SignedBigInteger& big_integer() const { return m_big_integer; } | ||||||
|     const String to_string() const { return String::format("%sn", m_big_integer.to_base10().characters()); } |     const String to_string() const { return String::formatted("{}n", m_big_integer.to_base10()); } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual const char* class_name() const override { return "BigInt"; } |     virtual const char* class_name() const override { return "BigInt"; } | ||||||
|  |  | ||||||
|  | @ -123,7 +123,7 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) | ||||||
|         return js_string(vm, message); |         return js_string(vm, message); | ||||||
|     if (message.length() == 0) |     if (message.length() == 0) | ||||||
|         return js_string(vm, name); |         return js_string(vm, name); | ||||||
|     return js_string(vm, String::format("%s: %s", name.characters(), message.characters())); |     return js_string(vm, String::formatted("{}: {}", name, message)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ | #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ | ||||||
|  |  | ||||||
|  | @ -148,7 +148,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) | ||||||
|     String function_body; |     String function_body; | ||||||
| 
 | 
 | ||||||
|     if (this_object->is_native_function() || this_object->is_bound_function()) { |     if (this_object->is_native_function() || this_object->is_bound_function()) { | ||||||
|         function_body = String::format("  [%s]", this_object->class_name()); |         function_body = String::formatted("  [{}]", this_object->class_name()); | ||||||
|     } else { |     } else { | ||||||
|         StringBuilder parameters_builder; |         StringBuilder parameters_builder; | ||||||
|         auto first = true; |         auto first = true; | ||||||
|  | @ -169,10 +169,9 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) | ||||||
|         function_body = "  ???"; |         function_body = "  ???"; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     auto function_source = String::format("function %s(%s) {\n%s\n}", |     auto function_source = String::formatted( | ||||||
|         function_name.is_null() ? "" : function_name.characters(), |         "function {}({}) {{\n{}\n}}", | ||||||
|         function_parameters.characters(), |         function_name.is_null() ? "" : function_name, function_parameters, function_body); | ||||||
|         function_body.characters()); |  | ||||||
|     return js_string(vm, function_source); |     return js_string(vm, function_source); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -850,7 +850,7 @@ Value Object::to_string() const | ||||||
|             return {}; |             return {}; | ||||||
|         return string; |         return string; | ||||||
|     } |     } | ||||||
|     return js_string(heap(), String::format("[object %s]", class_name())); |     return js_string(heap(), String::formatted("[object {}]", class_name())); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Value Object::invoke(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments) | Value Object::invoke(const StringOrSymbol& property_name, Optional<MarkedValueList> arguments) | ||||||
|  |  | ||||||
|  | @ -103,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_string) | ||||||
|         tag = "Object"; |         tag = "Object"; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return js_string(vm, String::format("[object %s]", tag.characters())); |     return js_string(vm, String::formatted("[object {}]", tag)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) | JS_DEFINE_NATIVE_FUNCTION(ObjectPrototype::to_locale_string) | ||||||
|  |  | ||||||
|  | @ -51,7 +51,7 @@ RegExpObject::~RegExpObject() | ||||||
| 
 | 
 | ||||||
| Value RegExpObject::to_string() const | Value RegExpObject::to_string() const | ||||||
| { | { | ||||||
|     return js_string(heap(), String::format("/%s/%s", content().characters(), flags().characters())); |     return js_string(heap(), String::formatted("/{}/{}", content(), flags())); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -41,7 +41,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     const String& description() const { return m_description; } |     const String& description() const { return m_description; } | ||||||
|     bool is_global() const { return m_is_global; } |     bool is_global() const { return m_is_global; } | ||||||
|     String to_string() const { return String::format("Symbol(%s)", description().characters()); } |     String to_string() const { return String::formatted("Symbol({})", description()); } | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     virtual const char* class_name() const override { return "Symbol"; } |     virtual const char* class_name() const override { return "Symbol"; } | ||||||
|  |  | ||||||
|  | @ -123,7 +123,7 @@ String Value::to_string_without_side_effects() const | ||||||
|     case Type::BigInt: |     case Type::BigInt: | ||||||
|         return m_value.as_bigint->to_string(); |         return m_value.as_bigint->to_string(); | ||||||
|     case Type::Object: |     case Type::Object: | ||||||
|         return String::format("[object %s]", as_object().class_name()); |         return String::formatted("[object {}]", as_object().class_name()); | ||||||
|     case Type::Accessor: |     case Type::Accessor: | ||||||
|         return "<accessor>"; |         return "<accessor>"; | ||||||
|     case Type::NativeProperty: |     case Type::NativeProperty: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh