mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:52:44 +00:00 
			
		
		
		
	LibWeb: Use StringView literals for all WebIDL::SimpleExceptions
				
					
				
			This commit is contained in:
		
							parent
							
								
									14d4f227f2
								
							
						
					
					
						commit
						6ce08d3f75
					
				
					 6 changed files with 22 additions and 22 deletions
				
			
		|  | @ -53,22 +53,22 @@ WebIDL::ExceptionOr<void> MutationObserver::observe(Node& target, MutationObserv | ||||||
| 
 | 
 | ||||||
|     // 3. If none of options["childList"], options["attributes"], and options["characterData"] is true, then throw a TypeError.
 |     // 3. If none of options["childList"], options["attributes"], and options["characterData"] is true, then throw a TypeError.
 | ||||||
|     if (!options.child_list && (!options.attributes.has_value() || !options.attributes.value()) && (!options.character_data.has_value() || !options.character_data.value())) |     if (!options.child_list && (!options.attributes.has_value() || !options.attributes.value()) && (!options.character_data.has_value() || !options.character_data.value())) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Options must have one of childList, attributes or characterData set to true." }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Options must have one of childList, attributes or characterData set to true."sv }; | ||||||
| 
 | 
 | ||||||
|     // 4. If options["attributeOldValue"] is true and options["attributes"] is false, then throw a TypeError.
 |     // 4. If options["attributeOldValue"] is true and options["attributes"] is false, then throw a TypeError.
 | ||||||
|     // NOTE: If attributeOldValue is present, attributes will be present because of step 1.
 |     // NOTE: If attributeOldValue is present, attributes will be present because of step 1.
 | ||||||
|     if (options.attribute_old_value.has_value() && options.attribute_old_value.value() && !options.attributes.value()) |     if (options.attribute_old_value.has_value() && options.attribute_old_value.value() && !options.attributes.value()) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeOldValue is true." }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeOldValue is true."sv }; | ||||||
| 
 | 
 | ||||||
|     // 5. If options["attributeFilter"] is present and options["attributes"] is false, then throw a TypeError.
 |     // 5. If options["attributeFilter"] is present and options["attributes"] is false, then throw a TypeError.
 | ||||||
|     // NOTE: If attributeFilter is present, attributes will be present because of step 1.
 |     // NOTE: If attributeFilter is present, attributes will be present because of step 1.
 | ||||||
|     if (options.attribute_filter.has_value() && !options.attributes.value()) |     if (options.attribute_filter.has_value() && !options.attributes.value()) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeFilter is present." }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "attributes must be true if attributeFilter is present."sv }; | ||||||
| 
 | 
 | ||||||
|     // 6. If options["characterDataOldValue"] is true and options["characterData"] is false, then throw a TypeError.
 |     // 6. If options["characterDataOldValue"] is true and options["characterData"] is false, then throw a TypeError.
 | ||||||
|     // NOTE: If characterDataOldValue is present, characterData will be present because of step 2.
 |     // NOTE: If characterDataOldValue is present, characterData will be present because of step 2.
 | ||||||
|     if (options.character_data_old_value.has_value() && options.character_data_old_value.value() && !options.character_data.value()) |     if (options.character_data_old_value.has_value() && options.character_data_old_value.value() && !options.character_data.value()) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "characterData must be true if characterDataOldValue is true." }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "characterData must be true if characterDataOldValue is true."sv }; | ||||||
| 
 | 
 | ||||||
|     // 7. For each registered of target’s registered observer list, if registered’s observer is this:
 |     // 7. For each registered of target’s registered observer list, if registered’s observer is this:
 | ||||||
|     bool updated_existing_observer = false; |     bool updated_existing_observer = false; | ||||||
|  |  | ||||||
|  | @ -212,7 +212,7 @@ WebIDL::ExceptionOr<String> serialize_node_to_xml_string_impl(JS::NonnullGCPtr<D | ||||||
| 
 | 
 | ||||||
|     // -> Anything else
 |     // -> Anything else
 | ||||||
|     //    Throw a TypeError. Only Nodes and Attr objects can be serialized by this algorithm.
 |     //    Throw a TypeError. Only Nodes and Attr objects can be serialized by this algorithm.
 | ||||||
|     return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Can only serialize Nodes or Attributes." }; |     return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Can only serialize Nodes or Attributes."sv }; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // https://w3c.github.io/DOM-Parsing/#dfn-recording-the-namespace-information
 | // https://w3c.github.io/DOM-Parsing/#dfn-recording-the-namespace-information
 | ||||||
|  |  | ||||||
|  | @ -74,11 +74,11 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm, | ||||||
|         [&](JS::Handle<Streams::ReadableStream> const& stream) -> WebIDL::ExceptionOr<void> { |         [&](JS::Handle<Streams::ReadableStream> const& stream) -> WebIDL::ExceptionOr<void> { | ||||||
|             // If keepalive is true, then throw a TypeError.
 |             // If keepalive is true, then throw a TypeError.
 | ||||||
|             if (keepalive) |             if (keepalive) | ||||||
|                 return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot extract body from stream when keepalive is set" }; |                 return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot extract body from stream when keepalive is set"sv }; | ||||||
| 
 | 
 | ||||||
|             // If object is disturbed or locked, then throw a TypeError.
 |             // If object is disturbed or locked, then throw a TypeError.
 | ||||||
|             if (stream->is_disturbed() || stream->is_locked()) |             if (stream->is_disturbed() || stream->is_locked()) | ||||||
|                 return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot extract body from disturbed or locked stream" }; |                 return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Cannot extract body from disturbed or locked stream"sv }; | ||||||
| 
 | 
 | ||||||
|             return {}; |             return {}; | ||||||
|         })); |         })); | ||||||
|  |  | ||||||
|  | @ -55,11 +55,11 @@ WebIDL::ExceptionOr<void> Headers::delete_(String const& name_string) | ||||||
| 
 | 
 | ||||||
|     // 1. If name is not a header name, then throw a TypeError.
 |     // 1. If name is not a header name, then throw a TypeError.
 | ||||||
|     if (!Infrastructure::is_header_name(name)) |     if (!Infrastructure::is_header_name(name)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; | ||||||
| 
 | 
 | ||||||
|     // 2. If this’s guard is "immutable", then throw a TypeError.
 |     // 2. If this’s guard is "immutable", then throw a TypeError.
 | ||||||
|     if (m_guard == Guard::Immutable) |     if (m_guard == Guard::Immutable) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable"sv }; | ||||||
| 
 | 
 | ||||||
|     // 3. Otherwise, if this’s guard is "request" and name is a forbidden header name, return.
 |     // 3. Otherwise, if this’s guard is "request" and name is a forbidden header name, return.
 | ||||||
|     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) |     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) | ||||||
|  | @ -95,7 +95,7 @@ WebIDL::ExceptionOr<String> Headers::get(String const& name_string) | ||||||
| 
 | 
 | ||||||
|     // 1. If name is not a header name, then throw a TypeError.
 |     // 1. If name is not a header name, then throw a TypeError.
 | ||||||
|     if (!Infrastructure::is_header_name(name)) |     if (!Infrastructure::is_header_name(name)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; | ||||||
| 
 | 
 | ||||||
|     // 2. Return the result of getting name from this’s header list.
 |     // 2. Return the result of getting name from this’s header list.
 | ||||||
|     auto byte_buffer = TRY_OR_RETURN_OOM(realm(), m_header_list->get(name)); |     auto byte_buffer = TRY_OR_RETURN_OOM(realm(), m_header_list->get(name)); | ||||||
|  | @ -111,7 +111,7 @@ WebIDL::ExceptionOr<bool> Headers::has(String const& name_string) | ||||||
| 
 | 
 | ||||||
|     // 1. If name is not a header name, then throw a TypeError.
 |     // 1. If name is not a header name, then throw a TypeError.
 | ||||||
|     if (!Infrastructure::is_header_name(name)) |     if (!Infrastructure::is_header_name(name)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; | ||||||
| 
 | 
 | ||||||
|     // 2. Return true if this’s header list contains name; otherwise false.
 |     // 2. Return true if this’s header list contains name; otherwise false.
 | ||||||
|     return m_header_list->contains(name); |     return m_header_list->contains(name); | ||||||
|  | @ -134,13 +134,13 @@ WebIDL::ExceptionOr<void> Headers::set(String const& name_string, String const& | ||||||
| 
 | 
 | ||||||
|     // 2. If name is not a header name or value is not a header value, then throw a TypeError.
 |     // 2. If name is not a header name or value is not a header value, then throw a TypeError.
 | ||||||
|     if (!Infrastructure::is_header_name(name)) |     if (!Infrastructure::is_header_name(name)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; | ||||||
|     if (!Infrastructure::is_header_value(value)) |     if (!Infrastructure::is_header_value(value)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header value" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header value"sv }; | ||||||
| 
 | 
 | ||||||
|     // 3. If this’s guard is "immutable", then throw a TypeError.
 |     // 3. If this’s guard is "immutable", then throw a TypeError.
 | ||||||
|     if (m_guard == Guard::Immutable) |     if (m_guard == Guard::Immutable) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable"sv }; | ||||||
| 
 | 
 | ||||||
|     // 4. Otherwise, if this’s guard is "request" and name is a forbidden header name, return.
 |     // 4. Otherwise, if this’s guard is "request" and name is a forbidden header name, return.
 | ||||||
|     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) |     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) | ||||||
|  | @ -212,13 +212,13 @@ WebIDL::ExceptionOr<void> Headers::append(Infrastructure::Header header) | ||||||
| 
 | 
 | ||||||
|     // 2. If name is not a header name or value is not a header value, then throw a TypeError.
 |     // 2. If name is not a header name or value is not a header value, then throw a TypeError.
 | ||||||
|     if (!Infrastructure::is_header_name(name)) |     if (!Infrastructure::is_header_name(name)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; | ||||||
|     if (!Infrastructure::is_header_value(value)) |     if (!Infrastructure::is_header_value(value)) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header value" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header value"sv }; | ||||||
| 
 | 
 | ||||||
|     // 3. If headers’s guard is "immutable", then throw a TypeError.
 |     // 3. If headers’s guard is "immutable", then throw a TypeError.
 | ||||||
|     if (m_guard == Guard::Immutable) |     if (m_guard == Guard::Immutable) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Headers object is immutable"sv }; | ||||||
| 
 | 
 | ||||||
|     // 4. Otherwise, if headers’s guard is "request" and name is a forbidden header name, return.
 |     // 4. Otherwise, if headers’s guard is "request" and name is a forbidden header name, return.
 | ||||||
|     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) |     if (m_guard == Guard::Request && Infrastructure::is_forbidden_header_name(name)) | ||||||
|  | @ -274,7 +274,7 @@ WebIDL::ExceptionOr<void> Headers::fill(HeadersInit const& object) | ||||||
|             for (auto const& entry : object) { |             for (auto const& entry : object) { | ||||||
|                 // 1. If header does not contain exactly two items, then throw a TypeError.
 |                 // 1. If header does not contain exactly two items, then throw a TypeError.
 | ||||||
|                 if (entry.size() != 2) |                 if (entry.size() != 2) | ||||||
|                     return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Array must contain header key/value pair" }; |                     return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Array must contain header key/value pair"sv }; | ||||||
| 
 | 
 | ||||||
|                 // 2. Append (header’s first item, header’s second item) to headers.
 |                 // 2. Append (header’s first item, header’s second item) to headers.
 | ||||||
|                 auto header = TRY_OR_RETURN_OOM(realm(), Infrastructure::Header::from_string_pair(entry[0], entry[1].bytes())); |                 auto header = TRY_OR_RETURN_OOM(realm(), Infrastructure::Header::from_string_pair(entry[0], entry[1].bytes())); | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, | ||||||
|         parsed_base = base; |         parsed_base = base; | ||||||
|         // 2. If parsedBase is failure, then throw a TypeError.
 |         // 2. If parsedBase is failure, then throw a TypeError.
 | ||||||
|         if (!parsed_base->is_valid()) |         if (!parsed_base->is_valid()) | ||||||
|             return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid base URL" }; |             return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid base URL"sv }; | ||||||
|     } |     } | ||||||
|     // 3. Let parsedURL be the result of running the basic URL parser on url with parsedBase.
 |     // 3. Let parsedURL be the result of running the basic URL parser on url with parsedBase.
 | ||||||
|     AK::URL parsed_url; |     AK::URL parsed_url; | ||||||
|  | @ -36,7 +36,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<URL>> URL::construct_impl(JS::Realm& realm, | ||||||
|         parsed_url = url; |         parsed_url = url; | ||||||
|     // 4. If parsedURL is failure, then throw a TypeError.
 |     // 4. If parsedURL is failure, then throw a TypeError.
 | ||||||
|     if (!parsed_url.is_valid()) |     if (!parsed_url.is_valid()) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL"sv }; | ||||||
|     // 5. Let query be parsedURL’s query, if that is non-null, and the empty string otherwise.
 |     // 5. Let query be parsedURL’s query, if that is non-null, and the empty string otherwise.
 | ||||||
|     auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query(); |     auto& query = parsed_url.query().is_null() ? String::empty() : parsed_url.query(); | ||||||
|     // 6. Set this’s URL to parsedURL.
 |     // 6. Set this’s URL to parsedURL.
 | ||||||
|  | @ -84,7 +84,7 @@ WebIDL::ExceptionOr<void> URL::set_href(String const& href) | ||||||
|     AK::URL parsed_url = href; |     AK::URL parsed_url = href; | ||||||
|     // 2. If parsedURL is failure, then throw a TypeError.
 |     // 2. If parsedURL is failure, then throw a TypeError.
 | ||||||
|     if (!parsed_url.is_valid()) |     if (!parsed_url.is_valid()) | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid URL"sv }; | ||||||
|     // 3. Set this’s URL to parsedURL.
 |     // 3. Set this’s URL to parsedURL.
 | ||||||
|     m_url = move(parsed_url); |     m_url = move(parsed_url); | ||||||
|     // 4. Empty this’s query object’s list.
 |     // 4. Empty this’s query object’s list.
 | ||||||
|  |  | ||||||
|  | @ -163,7 +163,7 @@ WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response() | ||||||
|     // 7. Otherwise, if this’s response type is "document", set a document response for this.
 |     // 7. Otherwise, if this’s response type is "document", set a document response for this.
 | ||||||
|     else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) { |     else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) { | ||||||
|         // FIXME: Implement this.
 |         // FIXME: Implement this.
 | ||||||
|         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "XHR Document type not implemented" }; |         return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "XHR Document type not implemented"sv }; | ||||||
|     } |     } | ||||||
|     // 8. Otherwise:
 |     // 8. Otherwise:
 | ||||||
|     else { |     else { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh