mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:37:45 +00:00
LibJS: Add initial support for creating PrimitiveStrings with AK::String
This will temporarily bloat the size of PrimitiveString as LibJS is transitioned to use String throughout, but will make doing so piecemeal much easier.
This commit is contained in:
parent
0b58748156
commit
8f5bdce8e7
4 changed files with 74 additions and 4 deletions
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
|
@ -23,6 +24,7 @@ class PrimitiveString final : public Cell {
|
|||
|
||||
public:
|
||||
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, Utf16String);
|
||||
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, String);
|
||||
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, DeprecatedString);
|
||||
[[nodiscard]] static NonnullGCPtr<PrimitiveString> create(VM&, PrimitiveString&, PrimitiveString&);
|
||||
|
||||
|
@ -34,6 +36,9 @@ public:
|
|||
bool is_empty() const;
|
||||
u32 hash() const;
|
||||
|
||||
ThrowCompletionOr<String> utf8_string() const;
|
||||
bool has_utf8_string() const { return m_utf8_string.has_value(); }
|
||||
|
||||
ThrowCompletionOr<DeprecatedString> deprecated_string() const;
|
||||
bool has_deprecated_string() const { return m_deprecated_string.has_value(); }
|
||||
|
||||
|
@ -45,6 +50,7 @@ public:
|
|||
|
||||
private:
|
||||
explicit PrimitiveString(PrimitiveString&, PrimitiveString&);
|
||||
explicit PrimitiveString(String);
|
||||
explicit PrimitiveString(DeprecatedString);
|
||||
explicit PrimitiveString(Utf16String);
|
||||
|
||||
|
@ -57,6 +63,7 @@ private:
|
|||
mutable PrimitiveString* m_lhs { nullptr };
|
||||
mutable PrimitiveString* m_rhs { nullptr };
|
||||
|
||||
mutable Optional<String> m_utf8_string;
|
||||
mutable Optional<DeprecatedString> m_deprecated_string;
|
||||
mutable Optional<Utf16String> m_utf16_string;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue