2020-03-11 14:55:01 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-03-11 14:55:01 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
2022-03-16 21:26:49 -03:00
|
|
|
#include <AK/StringView.h>
|
2022-02-12 05:48:23 -03:00
|
|
|
#include <LibJS/Forward.h>
|
2021-05-17 14:50:20 -03:00
|
|
|
#include <LibJS/Heap/Cell.h>
|
2021-08-09 10:06:45 -03:00
|
|
|
#include <LibJS/Runtime/Utf16String.h>
|
2022-02-13 10:55:23 -03:00
|
|
|
#include <LibJS/Runtime/Value.h>
|
2020-03-11 14:55:01 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
|
|
class PrimitiveString final : public Cell {
|
2022-08-28 17:11:20 -03:00
|
|
|
JS_CELL(PrimitiveString, Cell);
|
|
|
|
|
|
2020-03-11 14:55:01 -03:00
|
|
|
public:
|
|
|
|
|
virtual ~PrimitiveString();
|
|
|
|
|
|
2021-08-01 20:02:19 -03:00
|
|
|
PrimitiveString(PrimitiveString const&) = delete;
|
|
|
|
|
PrimitiveString& operator=(PrimitiveString const&) = delete;
|
|
|
|
|
|
2022-07-17 16:08:53 -03:00
|
|
|
bool is_empty() const;
|
|
|
|
|
|
2021-08-01 20:02:19 -03:00
|
|
|
String const& string() const;
|
2021-08-09 19:00:38 -03:00
|
|
|
bool has_utf8_string() const { return m_has_utf8_string; }
|
2021-07-20 11:46:53 -03:00
|
|
|
|
2021-08-09 10:06:45 -03:00
|
|
|
Utf16String const& utf16_string() const;
|
2021-07-20 11:46:53 -03:00
|
|
|
Utf16View utf16_string_view() const;
|
2021-08-09 19:00:38 -03:00
|
|
|
bool has_utf16_string() const { return m_has_utf16_string; }
|
2020-03-11 14:55:01 -03:00
|
|
|
|
2022-08-21 16:38:35 -03:00
|
|
|
Optional<Value> get(VM&, PropertyKey const&) const;
|
2022-02-13 10:55:23 -03:00
|
|
|
|
2020-03-11 14:55:01 -03:00
|
|
|
private:
|
2022-08-28 18:51:28 -03:00
|
|
|
explicit PrimitiveString(PrimitiveString&, PrimitiveString&);
|
|
|
|
|
explicit PrimitiveString(String);
|
|
|
|
|
explicit PrimitiveString(Utf16String);
|
|
|
|
|
|
2022-08-05 18:58:47 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2020-03-11 14:55:01 -03:00
|
|
|
|
2022-08-05 18:58:47 -03:00
|
|
|
void resolve_rope_if_needed() const;
|
|
|
|
|
|
|
|
|
|
mutable bool m_is_rope { false };
|
2021-08-01 20:02:19 -03:00
|
|
|
mutable bool m_has_utf8_string { false };
|
2022-08-05 18:58:47 -03:00
|
|
|
mutable bool m_has_utf16_string { false };
|
|
|
|
|
|
2022-08-05 21:06:02 -03:00
|
|
|
mutable PrimitiveString* m_lhs { nullptr };
|
|
|
|
|
mutable PrimitiveString* m_rhs { nullptr };
|
2022-08-05 18:58:47 -03:00
|
|
|
|
|
|
|
|
mutable String m_utf8_string;
|
2021-08-01 20:02:19 -03:00
|
|
|
|
2021-08-09 10:06:45 -03:00
|
|
|
mutable Utf16String m_utf16_string;
|
2020-03-11 14:55:01 -03:00
|
|
|
};
|
|
|
|
|
|
2021-07-20 11:46:53 -03:00
|
|
|
PrimitiveString* js_string(Heap&, Utf16View const&);
|
|
|
|
|
PrimitiveString* js_string(VM&, Utf16View const&);
|
|
|
|
|
|
2021-08-09 10:06:45 -03:00
|
|
|
PrimitiveString* js_string(Heap&, Utf16String);
|
|
|
|
|
PrimitiveString* js_string(VM&, Utf16String);
|
2021-08-01 20:02:19 -03:00
|
|
|
|
2020-03-11 14:55:01 -03:00
|
|
|
PrimitiveString* js_string(Heap&, String);
|
2020-09-27 13:36:49 -03:00
|
|
|
PrimitiveString* js_string(VM&, String);
|
2020-03-11 14:55:01 -03:00
|
|
|
|
2022-08-05 18:58:47 -03:00
|
|
|
PrimitiveString* js_rope_string(VM&, PrimitiveString&, PrimitiveString&);
|
|
|
|
|
|
2020-03-11 14:55:01 -03:00
|
|
|
}
|