summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Runtime/PrimitiveString.h
blob: dd15cb4d49c512f24c5f6b8fbc737d5e0553622d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/String.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/Utf16String.h>

namespace JS {

class PrimitiveString final : public Cell {
public:
    explicit PrimitiveString(String);
    explicit PrimitiveString(Utf16String);
    virtual ~PrimitiveString();

    PrimitiveString(PrimitiveString const&) = delete;
    PrimitiveString& operator=(PrimitiveString const&) = delete;

    String const& string() const;
    bool has_utf8_string() const { return m_has_utf8_string; }

    Utf16String const& utf16_string() const;
    Utf16View utf16_string_view() const;
    bool has_utf16_string() const { return m_has_utf16_string; }

private:
    virtual const char* class_name() const override { return "PrimitiveString"; }

    mutable String m_utf8_string;
    mutable bool m_has_utf8_string { false };

    mutable Utf16String m_utf16_string;
    mutable bool m_has_utf16_string { false };
};

PrimitiveString* js_string(Heap&, Utf16View const&);
PrimitiveString* js_string(VM&, Utf16View const&);

PrimitiveString* js_string(Heap&, Utf16String);
PrimitiveString* js_string(VM&, Utf16String);

PrimitiveString* js_string(Heap&, String);
PrimitiveString* js_string(VM&, String);

}