| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |  * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  | #include <AK/DeprecatedString.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  | #include <AK/Optional.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-16 18:26:49 -06:00
										 |  |  | #include <AK/StringView.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-12 00:48:23 -08:00
										 |  |  | #include <LibJS/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-17 19:50:20 +02:00
										 |  |  | #include <LibJS/Heap/Cell.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  | #include <LibJS/Runtime/Completion.h>
 | 
					
						
							| 
									
										
										
										
											2021-08-09 09:06:45 -04:00
										 |  |  | #include <LibJS/Runtime/Utf16String.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-13 14:55:23 +01:00
										 |  |  | #include <LibJS/Runtime/Value.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PrimitiveString final : public Cell { | 
					
						
							| 
									
										
										
										
											2022-08-28 22:11:20 +02:00
										 |  |  |     JS_CELL(PrimitiveString, Cell); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |     [[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, Utf16String); | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  |     [[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, String); | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |     [[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, DeprecatedString); | 
					
						
							| 
									
										
										
										
											2023-02-09 09:00:14 -05:00
										 |  |  |     [[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, DeprecatedFlyString const&); | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  |     [[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, PrimitiveString&, PrimitiveString&); | 
					
						
							| 
									
										
										
										
											2023-02-09 09:00:14 -05:00
										 |  |  |     static ThrowCompletionOr<NonnullGCPtr<PrimitiveString>> create(VM&, StringView); | 
					
						
							| 
									
										
										
										
											2022-12-06 22:17:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  |     virtual ~PrimitiveString(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-01 19:02:19 -04:00
										 |  |  |     PrimitiveString(PrimitiveString const&) = delete; | 
					
						
							|  |  |  |     PrimitiveString& operator=(PrimitiveString const&) = delete; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-17 21:08:53 +02:00
										 |  |  |     bool is_empty() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  |     ThrowCompletionOr<String> utf8_string() const; | 
					
						
							| 
									
										
										
										
											2023-01-15 09:37:32 -05:00
										 |  |  |     ThrowCompletionOr<StringView> utf8_string_view() const; | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  |     bool has_utf8_string() const { return m_utf8_string.has_value(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-13 15:33:31 -05:00
										 |  |  |     ThrowCompletionOr<DeprecatedString> deprecated_string() const; | 
					
						
							| 
									
										
										
										
											2023-01-13 09:36:12 -05:00
										 |  |  |     bool has_deprecated_string() const { return m_deprecated_string.has_value(); } | 
					
						
							| 
									
										
										
										
											2021-07-20 10:46:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-13 15:33:31 -05:00
										 |  |  |     ThrowCompletionOr<Utf16String> utf16_string() const; | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  |     ThrowCompletionOr<Utf16View> utf16_string_view() const; | 
					
						
							|  |  |  |     bool has_utf16_string() const { return m_utf16_string.has_value(); } | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  |     ThrowCompletionOr<Optional<Value>> get(VM&, PropertyKey const&) const; | 
					
						
							| 
									
										
										
										
											2022-02-13 14:55:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-08-28 23:51:28 +02:00
										 |  |  |     explicit PrimitiveString(PrimitiveString&, PrimitiveString&); | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  |     explicit PrimitiveString(String); | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     explicit PrimitiveString(DeprecatedString); | 
					
						
							| 
									
										
										
										
											2022-08-28 23:51:28 +02:00
										 |  |  |     explicit PrimitiveString(Utf16String); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-05 23:58:47 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  |     ThrowCompletionOr<void> resolve_rope_if_needed() const; | 
					
						
							| 
									
										
										
										
											2022-08-05 23:58:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     mutable bool m_is_rope { false }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-26 16:09:02 -07:00
										 |  |  |     mutable GCPtr<PrimitiveString> m_lhs; | 
					
						
							|  |  |  |     mutable GCPtr<PrimitiveString> m_rhs; | 
					
						
							| 
									
										
										
										
											2022-08-05 23:58:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-13 12:24:02 -05:00
										 |  |  |     mutable Optional<String> m_utf8_string; | 
					
						
							| 
									
										
										
										
											2023-01-13 09:36:12 -05:00
										 |  |  |     mutable Optional<DeprecatedString> m_deprecated_string; | 
					
						
							| 
									
										
										
										
											2023-01-07 12:24:05 -05:00
										 |  |  |     mutable Optional<Utf16String> m_utf16_string; | 
					
						
							| 
									
										
										
										
											2020-03-11 18:55:01 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |