chromium/v8/src/objects/string-inl.h

// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_OBJECTS_STRING_INL_H_
#define V8_OBJECTS_STRING_INL_H_

#include <optional>

#include "src/common/assert-scope.h"
#include "src/common/globals.h"
#include "src/execution/isolate-utils.h"
#include "src/handles/handles-inl.h"
#include "src/heap/factory.h"
#include "src/numbers/hash-seed-inl.h"
#include "src/objects/instance-type-inl.h"
#include "src/objects/name-inl.h"
#include "src/objects/objects-body-descriptors.h"
#include "src/objects/smi-inl.h"
#include "src/objects/string-table-inl.h"
#include "src/objects/string.h"
#include "src/sandbox/external-pointer-inl.h"
#include "src/sandbox/external-pointer.h"
#include "src/strings/string-hasher-inl.h"
#include "src/strings/unicode-inl.h"
#include "src/torque/runtime-macro-shims.h"
#include "src/torque/runtime-support.h"
#include "src/utils/utils.h"

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8::internal {

class V8_NODISCARD SharedStringAccessGuardIfNeeded {};

int32_t String::length() const {}

int32_t String::length(AcquireLoadTag) const {}

void String::set_length(int32_t value) {}

void String::set_length(int32_t value, ReleaseStoreTag) {}

static_assert;

StringShape::StringShape(const Tagged<String> str)
    :{}

StringShape::StringShape(const Tagged<String> str, PtrComprCageBase cage_base)
    :{}

StringShape::StringShape(Tagged<Map> map) :{}

StringShape::StringShape(InstanceType t) :{}

bool StringShape::IsInternalized() const {}

bool StringShape::IsCons() const {}

bool StringShape::IsThin() const {}

bool StringShape::IsSliced() const {}

bool StringShape::IsIndirect() const {}

bool StringShape::IsDirect() const {}

bool StringShape::IsExternal() const {}

bool StringShape::IsSequential() const {}

bool StringShape::IsUncachedExternal() const {}

bool StringShape::IsShared() const {}

StringRepresentationTag StringShape::representation_tag() const {}

uint32_t StringShape::encoding_tag() const {}

uint32_t StringShape::representation_and_encoding_tag() const {}

uint32_t StringShape::representation_encoding_and_shared_tag() const {}

static_assert;

static_assert;

bool StringShape::IsSequentialOneByte() const {}

bool StringShape::IsSequentialTwoByte() const {}

bool StringShape::IsExternalOneByte() const {}

static_assert;

static_assert;

bool StringShape::IsExternalTwoByte() const {}

static_assert;

static_assert;

template <typename TDispatcher, typename TResult, typename... TArgs>
inline TResult StringShape::DispatchToSpecificTypeWithoutCast(TArgs&&... args) {}

// All concrete subclasses of String (leaves of the inheritance tree).
#define STRING_CLASS_TYPES(V)

template <typename TDispatcher, typename TResult, typename... TArgs>
inline TResult StringShape::DispatchToSpecificType(Tagged<String> str,
                                                   TArgs&&... args) {}

bool String::IsOneByteRepresentation() const {}

bool String::IsTwoByteRepresentation() const {}

// static
bool String::IsOneByteRepresentationUnderneath(Tagged<String> string) {}

base::uc32 FlatStringReader::Get(int index) const {}

template <typename Char>
Char FlatStringReader::Get(int index) const {}

template <typename Char>
class SequentialStringKey final : public StringTableKey {};

OneByteStringKey;
TwoByteStringKey;

template <typename SeqString>
class SeqSubStringKey final : public StringTableKey {};

SeqOneByteSubStringKey;
SeqTwoByteSubStringKey;

bool String::Equals(Tagged<String> other) const {}

// static
bool String::Equals(Isolate* isolate, Handle<String> one, Handle<String> two) {}

template <String::EqualityType kEqType, typename Char>
bool String::IsEqualTo(base::Vector<const Char> str, Isolate* isolate) const {}

template <String::EqualityType kEqType, typename Char>
bool String::IsEqualTo(base::Vector<const Char> str) const {}

template <String::EqualityType kEqType, typename Char>
bool String::IsEqualTo(base::Vector<const Char> str,
                       LocalIsolate* isolate) const {}

template <String::EqualityType kEqType, typename Char>
bool String::IsEqualToImpl(
    base::Vector<const Char> str,
    const SharedStringAccessGuardIfNeeded& access_guard) const {}

// static
template <typename Char>
bool String::IsConsStringEqualToImpl(
    Tagged<ConsString> string, base::Vector<const Char> str,
    const SharedStringAccessGuardIfNeeded& access_guard) {}

bool String::IsOneByteEqualTo(base::Vector<const char> str) {}

template <typename Char>
const Char* String::GetDirectStringChars(
    const DisallowGarbageCollection& no_gc) const {}

template <typename Char>
const Char* String::GetDirectStringChars(
    const DisallowGarbageCollection& no_gc,
    const SharedStringAccessGuardIfNeeded& access_guard) const {}

// static
Handle<String> String::Flatten(Isolate* isolate, Handle<String> string,
                               AllocationType allocation) {}

// static
Handle<String> String::Flatten(LocalIsolate* isolate, Handle<String> string,
                               AllocationType allocation) {}

// static
std::optional<String::FlatContent> String::TryGetFlatContentFromDirectString(
    const DisallowGarbageCollection& no_gc, Tagged<String> string, int offset,
    int length, const SharedStringAccessGuardIfNeeded& access_guard) {}

String::FlatContent String::GetFlatContent(
    const DisallowGarbageCollection& no_gc) {}

String::FlatContent::FlatContent(const uint8_t* start, int length,
                                 const DisallowGarbageCollection& no_gc)
    :{}

String::FlatContent::FlatContent(const base::uc16* start, int length,
                                 const DisallowGarbageCollection& no_gc)
    :{}

String::FlatContent::~FlatContent() {}

#ifdef ENABLE_SLOW_DCHECKS
uint32_t String::FlatContent::ComputeChecksum() const {
  constexpr uint64_t hashseed = 1;
  uint32_t hash;
  if (state_ == ONE_BYTE) {
    hash = StringHasher::HashSequentialString(onebyte_start, length_, hashseed);
  } else {
    DCHECK_EQ(TWO_BYTE, state_);
    hash = StringHasher::HashSequentialString(twobyte_start, length_, hashseed);
  }
  DCHECK_NE(kChecksumVerificationDisabled, hash);
  return hash;
}
#endif

String::FlatContent String::GetFlatContent(
    const DisallowGarbageCollection& no_gc,
    const SharedStringAccessGuardIfNeeded& access_guard) {}

Handle<String> String::Share(Isolate* isolate, Handle<String> string) {}

uint16_t String::Get(int index) const {}

uint16_t String::Get(int index, Isolate* isolate) const {}

uint16_t String::Get(int index, LocalIsolate* local_isolate) const {}

uint16_t String::Get(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

uint16_t String::GetImpl(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

void String::Set(int index, uint16_t value) {}

bool String::IsFlat() const {}

bool String::IsShared() const {}

Tagged<String> String::GetUnderlying() const {}

template <class Visitor>
Tagged<ConsString> String::VisitFlat(Visitor* visitor, Tagged<String> string,
                                     const int offset) {}

template <class Visitor>
Tagged<ConsString> String::VisitFlat(
    Visitor* visitor, Tagged<String> string, const int offset,
    const SharedStringAccessGuardIfNeeded& access_guard) {}

bool String::IsWellFormedUnicode(Isolate* isolate, Handle<String> string) {}

template <>
inline base::Vector<const uint8_t> String::GetCharVector(
    const DisallowGarbageCollection& no_gc) {}

template <>
inline base::Vector<const base::uc16> String::GetCharVector(
    const DisallowGarbageCollection& no_gc) {}

uint8_t SeqOneByteString::Get(int index) const {}

uint8_t SeqOneByteString::Get(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

void SeqOneByteString::SeqOneByteStringSet(int index, uint16_t value) {}

void SeqOneByteString::SeqOneByteStringSetChars(int index,
                                                const uint8_t* string,
                                                int string_length) {}

Address SeqOneByteString::GetCharsAddress() const {}

uint8_t* SeqOneByteString::GetChars(const DisallowGarbageCollection& no_gc) {}

uint8_t* SeqOneByteString::GetChars(
    const DisallowGarbageCollection& no_gc,
    const SharedStringAccessGuardIfNeeded& access_guard) {}

Address SeqTwoByteString::GetCharsAddress() const {}

base::uc16* SeqTwoByteString::GetChars(const DisallowGarbageCollection& no_gc) {}

base::uc16* SeqTwoByteString::GetChars(
    const DisallowGarbageCollection& no_gc,
    const SharedStringAccessGuardIfNeeded& access_guard) {}

uint16_t SeqTwoByteString::Get(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) {}

// static
V8_INLINE constexpr int32_t SeqOneByteString::DataSizeFor(int32_t length) {}

// static
V8_INLINE constexpr int32_t SeqTwoByteString::DataSizeFor(int32_t length) {}

// static
V8_INLINE constexpr int32_t SeqOneByteString::SizeFor(int32_t length) {}

// static
V8_INLINE constexpr int32_t SeqTwoByteString::SizeFor(int32_t length) {}

// Due to ThinString rewriting, concurrent visitors need to read the length with
// acquire semantics.
inline int SeqOneByteString::AllocatedSize() const {}
inline int SeqTwoByteString::AllocatedSize() const {}

// static
bool SeqOneByteString::IsCompatibleMap(Tagged<Map> map, ReadOnlyRoots roots) {}

// static
bool SeqTwoByteString::IsCompatibleMap(Tagged<Map> map, ReadOnlyRoots roots) {}

inline Tagged<String> SlicedString::parent() const {}

void SlicedString::set_parent(Tagged<String> parent, WriteBarrierMode mode) {}

inline int32_t SlicedString::offset() const {}

void SlicedString::set_offset(int32_t value) {}

inline Tagged<String> ConsString::first() const {}
inline void ConsString::set_first(Tagged<String> value, WriteBarrierMode mode) {}

inline Tagged<String> ConsString::second() const {}
inline void ConsString::set_second(Tagged<String> value,
                                   WriteBarrierMode mode) {}

Tagged<Object> ConsString::unchecked_first() const {}

Tagged<Object> ConsString::unchecked_second() const {}

bool ConsString::IsFlat() const {}

inline Tagged<String> ThinString::actual() const {}
inline void ThinString::set_actual(Tagged<String> value,
                                   WriteBarrierMode mode) {}

Tagged<HeapObject> ThinString::unchecked_actual() const {}

bool ExternalString::is_uncached() const {}

void ExternalString::InitExternalPointerFields(Isolate* isolate) {}

void ExternalString::VisitExternalPointers(ObjectVisitor* visitor) {}

Address ExternalString::resource_as_address() const {}

void ExternalString::set_address_as_resource(Isolate* isolate, Address value) {}

uint32_t ExternalString::GetResourceRefForDeserialization() {}

void ExternalString::SetResourceRefForSerialization(uint32_t ref) {}

void ExternalString::DisposeResource(Isolate* isolate) {}

const ExternalOneByteString::Resource* ExternalOneByteString::resource() const {}

ExternalOneByteString::Resource* ExternalOneByteString::mutable_resource() {}

void ExternalOneByteString::update_data_cache(Isolate* isolate) {}

void ExternalOneByteString::SetResource(
    Isolate* isolate, const ExternalOneByteString::Resource* resource) {}

void ExternalOneByteString::set_resource(
    Isolate* isolate, const ExternalOneByteString::Resource* resource) {}

const uint8_t* ExternalOneByteString::GetChars() const {}

uint8_t ExternalOneByteString::Get(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() const {}

ExternalTwoByteString::Resource* ExternalTwoByteString::mutable_resource() {}

void ExternalTwoByteString::update_data_cache(Isolate* isolate) {}

void ExternalTwoByteString::SetResource(
    Isolate* isolate, const ExternalTwoByteString::Resource* resource) {}

void ExternalTwoByteString::set_resource(
    Isolate* isolate, const ExternalTwoByteString::Resource* resource) {}

const uint16_t* ExternalTwoByteString::GetChars() const {}

uint16_t ExternalTwoByteString::Get(
    int index, const SharedStringAccessGuardIfNeeded& access_guard) const {}

const uint16_t* ExternalTwoByteString::ExternalTwoByteStringGetData(
    unsigned start) {}

int ConsStringIterator::OffsetForDepth(int depth) {}

void ConsStringIterator::PushLeft(Tagged<ConsString> string) {}

void ConsStringIterator::PushRight(Tagged<ConsString> string) {}

void ConsStringIterator::AdjustMaximumDepth() {}

void ConsStringIterator::Pop() {}

class StringCharacterStream {};

uint16_t StringCharacterStream::GetNext() {}

// TODO(solanes, v8:7790, chromium:1166095): Assess if we need to use
// Isolate/LocalIsolate and pipe them through, instead of using the slow
// version of the SharedStringAccessGuardIfNeeded.
StringCharacterStream::StringCharacterStream(Tagged<String> string, int offset)
    :{}

void StringCharacterStream::Reset(Tagged<String> string, int offset) {}

bool StringCharacterStream::HasMore() {}

void StringCharacterStream::VisitOneByteString(const uint8_t* chars,
                                               int length) {}

void StringCharacterStream::VisitTwoByteString(const uint16_t* chars,
                                               int length) {}

bool String::AsArrayIndex(uint32_t* index) {}

bool String::AsIntegerIndex(size_t* index) {}

SubStringRange::SubStringRange(Tagged<String> string,
                               const DisallowGarbageCollection& no_gc,
                               int first, int length)
    :{}

class SubStringRange::iterator final {};

SubStringRange::iterator SubStringRange::begin() {}

SubStringRange::iterator SubStringRange::end() {}

void SeqOneByteString::clear_padding_destructively(int length) {}

void SeqTwoByteString::clear_padding_destructively(int length) {}

// static
bool String::IsInPlaceInternalizable(Tagged<String> string) {}

// static
bool String::IsInPlaceInternalizable(InstanceType instance_type) {}

// static
bool String::IsInPlaceInternalizableExcludingExternal(
    InstanceType instance_type) {}

class SeqOneByteString::BodyDescriptor final : public DataOnlyBodyDescriptor {};

class SeqTwoByteString::BodyDescriptor final : public DataOnlyBodyDescriptor {};

}  // namespace v8::internal

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_STRING_INL_H_