/* * Copyright (c) 2020, Andreas Kling * Copyright (c) 2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace JS { class PrimitiveString final : public Cell { JS_CELL(PrimitiveString, Cell); public: [[nodiscard]] static NonnullGCPtr create(VM&, Utf16String); [[nodiscard]] static NonnullGCPtr create(VM&, String); [[nodiscard]] static NonnullGCPtr create(VM&, FlyString const&); [[nodiscard]] static NonnullGCPtr create(VM&, DeprecatedString); [[nodiscard]] static NonnullGCPtr create(VM&, DeprecatedFlyString const&); [[nodiscard]] static NonnullGCPtr create(VM&, PrimitiveString&, PrimitiveString&); static ThrowCompletionOr> create(VM&, StringView); virtual ~PrimitiveString(); PrimitiveString(PrimitiveString const&) = delete; PrimitiveString& operator=(PrimitiveString const&) = delete; bool is_empty() const; ThrowCompletionOr utf8_string() const; ThrowCompletionOr utf8_string_view() const; bool has_utf8_string() const { return m_utf8_string.has_value(); } ThrowCompletionOr deprecated_string() const; bool has_deprecated_string() const { return m_deprecated_string.has_value(); } ThrowCompletionOr utf16_string() const; ThrowCompletionOr utf16_string_view() const; bool has_utf16_string() const { return m_utf16_string.has_value(); } ThrowCompletionOr> get(VM&, PropertyKey const&) const; private: explicit PrimitiveString(PrimitiveString&, PrimitiveString&); explicit PrimitiveString(String); explicit PrimitiveString(DeprecatedString); explicit PrimitiveString(Utf16String); virtual void visit_edges(Cell::Visitor&) override; ThrowCompletionOr resolve_rope_if_needed() const; mutable bool m_is_rope { false }; mutable GCPtr m_lhs; mutable GCPtr m_rhs; mutable Optional m_utf8_string; mutable Optional m_deprecated_string; mutable Optional m_utf16_string; }; }