V8 Project
v8::internal::String Class Reference

#include <objects.h>

+ Inheritance diagram for v8::internal::String:
+ Collaboration diagram for v8::internal::String:

Classes

class  ArrayIndexLengthBits
 
class  ArrayIndexValueBits
 
class  FlatContent
 

Public Types

enum  Encoding { ONE_BYTE_ENCODING , TWO_BYTE_ENCODING }
 
- Public Types inherited from v8::internal::Object
enum  StoreFromKeyed { MAY_BE_STORE_FROM_KEYED , CERTAINLY_NOT_STORE_FROM_KEYED }
 
enum  StorePropertyMode { NORMAL_PROPERTY , SUPER_PROPERTY }
 

Public Member Functions

 STATIC_ASSERT ((kArrayIndexLengthBits > 0))
 
 STATIC_ASSERT (IS_POWER_OF_TWO(kMaxCachedArrayIndexLength+1))
 
int length () const
 
void set_length (int value)
 
int synchronized_length () const
 
void synchronized_set_length (int value)
 
bool IsOneByteRepresentation () const
 
bool IsTwoByteRepresentation () const
 
bool IsOneByteRepresentationUnderneath ()
 
bool IsTwoByteRepresentationUnderneath ()
 
bool HasOnlyOneByteChars ()
 
void Set (int index, uint16_t value)
 
 INLINE (uint16_t Get(int index))
 
FlatContent GetFlatContent ()
 
StringGetUnderlying ()
 
bool MarkAsUndetectable ()
 
bool Equals (String *other)
 
bool IsUtf8EqualTo (Vector< const char > str, bool allow_prefix_match=false)
 
bool IsOneByteEqualTo (Vector< const uint8_t > str)
 
bool IsTwoByteEqualTo (Vector< const uc16 > str)
 
SmartArrayPointer< char > ToCString (AllowNullsFlag allow_nulls, RobustnessFlag robustness_flag, int offset, int length, int *length_output=0)
 
SmartArrayPointer< char > ToCString (AllowNullsFlag allow_nulls=DISALLOW_NULLS, RobustnessFlag robustness_flag=FAST_STRING_TRAVERSAL, int *length_output=0)
 
SmartArrayPointer< uc16ToWideCString (RobustnessFlag robustness_flag=FAST_STRING_TRAVERSAL)
 
bool ComputeArrayIndex (uint32_t *index)
 
bool MakeExternal (v8::String::ExternalStringResource *resource)
 
bool MakeExternal (v8::String::ExternalOneByteStringResource *resource)
 
bool AsArrayIndex (uint32_t *index)
 
void PrintOn (FILE *out)
 
bool LooksValid ()
 
void StringShortPrint (StringStream *accumulator)
 
void PrintUC16 (OStream &os, int start=0, int end=-1)
 
bool IsFlat ()
 
 STATIC_ASSERT (kMaxArrayIndexSize<(1<< kArrayIndexLengthBits))
 
const uc16GetTwoByteData (unsigned start)
 
void SetForwardedInternalizedString (String *string)
 
StringGetForwardedInternalizedString ()
 
- Public Member Functions inherited from v8::internal::Name
uint32_t hash_field ()
 
void set_hash_field (uint32_t value)
 
bool HasHashCode ()
 
uint32_t Hash ()
 
bool Equals (Name *other)
 
bool AsArrayIndex (uint32_t *index)
 
bool IsOwn ()
 
 STATIC_ASSERT ((kArrayIndexLengthBits > 0))
 
 STATIC_ASSERT (IS_POWER_OF_TWO(kMaxCachedArrayIndexLength+1))
 
- Public Member Functions inherited from v8::internal::HeapObject
Mapmap () const
 
void set_map (Map *value)
 
void set_map_no_write_barrier (Map *value)
 
Mapsynchronized_map ()
 
MapWord synchronized_map_word () const
 
void synchronized_set_map (Map *value)
 
void synchronized_set_map_no_write_barrier (Map *value)
 
void synchronized_set_map_word (MapWord map_word)
 
MapWord map_word () const
 
void set_map_word (MapWord map_word)
 
HeapGetHeap () const
 
IsolateGetIsolate () const
 
Address address ()
 
void Iterate (ObjectVisitor *v)
 
void IterateBody (InstanceType type, int object_size, ObjectVisitor *v)
 
int Size ()
 
bool MayContainRawValues ()
 
int SizeFromMap (Map *map)
 
WriteBarrierMode GetWriteBarrierMode (const DisallowHeapAllocation &promise)
 
void HeapObjectShortPrint (OStream &os)
 
 STATIC_ASSERT (kMapOffset==Internals::kHeapObjectMapOffset)
 
- Public Member Functions inherited from v8::internal::Object
bool IsObject () const
 
 INLINE (bool IsFixedArrayBase() const)
 
 INLINE (bool IsExternal() const)
 
 INLINE (bool IsAccessorInfo() const)
 
 INLINE (bool IsStruct() const)
 
 INLINE (bool IsSpecObject()) const
 
 INLINE (bool IsSpecFunction()) const
 
 INLINE (bool IsTemplateInfo()) const
 
 INLINE (bool IsNameDictionary() const)
 
 INLINE (bool IsSeededNumberDictionary() const)
 
 INLINE (bool IsUnseededNumberDictionary() const)
 
 INLINE (bool IsOrderedHashSet() const)
 
 INLINE (bool IsOrderedHashMap() const)
 
bool IsCallable () const
 
 INLINE (bool IsUndefined() const)
 
 INLINE (bool IsNull() const)
 
 INLINE (bool IsTheHole() const)
 
 INLINE (bool IsException() const)
 
 INLINE (bool IsUninitialized() const)
 
 INLINE (bool IsTrue() const)
 
 INLINE (bool IsFalse() const)
 
 INLINE (bool IsArgumentsMarker() const)
 
 INLINE (bool IsFiller() const)
 
double Number ()
 
 INLINE (bool IsNaN() const)
 
 INLINE (bool IsMinusZero() const)
 
bool ToInt32 (int32_t *value)
 
bool ToUint32 (uint32_t *value)
 
Representation OptimalRepresentation ()
 
bool FitsRepresentation (Representation representation)
 
Handle< HeapTypeOptimalType (Isolate *isolate, Representation representation)
 
bool HasValidElements ()
 
bool HasSpecificClassOf (String *name)
 
bool BooleanValue ()
 
ObjectGetHash ()
 
bool SameValue (Object *other)
 
bool SameValueZero (Object *other)
 
bool ToArrayIndex (uint32_t *index)
 
bool IsStringObjectWithCharacterAt (uint32_t index)
 
void VerifyApiCallResultType ()
 
void ShortPrint (FILE *out=stdout)
 
void ShortPrint (StringStream *accumulator)
 

Static Public Member Functions

static Handle< StringFlatten (Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
 
static bool Equals (Handle< String > one, Handle< String > two)
 
template<typename sinkchar >
static void WriteToFlat (String *source, sinkchar *sink, int from, int to)
 
static int NonAsciiStart (const char *chars, int length)
 
static bool IsAscii (const char *chars, int length)
 
static bool IsAscii (const uint8_t *chars, int length)
 
static int NonOneByteStart (const uc16 *chars, int length)
 
static bool IsOneByte (const uc16 *chars, int length)
 
template<class Visitor >
static ConsStringVisitFlat (Visitor *visitor, String *string, int offset=0)
 
static Handle< FixedArrayCalculateLineEnds (Handle< String > string, bool include_ending_line)
 
- Static Public Member Functions inherited from v8::internal::Name
static bool Equals (Handle< Name > one, Handle< Name > two)
 
- Static Public Member Functions inherited from v8::internal::HeapObject
static HeapObjectFromAddress (Address address)
 
static Object ** RawField (HeapObject *obj, int offset)
 
static void UpdateMapCodeCache (Handle< HeapObject > object, Handle< Name > name, Handle< Code > code)
 
- Static Public Member Functions inherited from v8::internal::Object
static Handle< ObjectNewStorageFor (Isolate *isolate, Handle< Object > object, Representation representation)
 
static Handle< ObjectWrapForRead (Isolate *isolate, Handle< Object > object, Representation representation)
 
static MaybeHandle< JSReceiverToObject (Isolate *isolate, Handle< Object > object)
 
static MaybeHandle< JSReceiverToObject (Isolate *isolate, Handle< Object > object, Handle< Context > context)
 
static MUST_USE_RESULT MaybeHandle< SmiToSmi (Isolate *isolate, Handle< Object > object)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetProperty (LookupIterator *it)
 
static MUST_USE_RESULT MaybeHandle< ObjectSetProperty (Handle< Object > object, Handle< Name > key, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode=MAY_BE_STORE_FROM_KEYED)
 
static MUST_USE_RESULT MaybeHandle< ObjectSetProperty (LookupIterator *it, Handle< Object > value, StrictMode strict_mode, StoreFromKeyed store_mode, StorePropertyMode data_store_mode=NORMAL_PROPERTY)
 
static MUST_USE_RESULT MaybeHandle< ObjectWriteToReadOnlyProperty (LookupIterator *it, Handle< Object > value, StrictMode strict_mode)
 
static Handle< ObjectSetDataProperty (LookupIterator *it, Handle< Object > value)
 
static MUST_USE_RESULT MaybeHandle< ObjectAddDataProperty (LookupIterator *it, Handle< Object > value, PropertyAttributes attributes, StrictMode strict_mode, StoreFromKeyed store_mode)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetPropertyOrElement (Handle< Object > object, Handle< Name > key)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetProperty (Isolate *isolate, Handle< Object > object, const char *key)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetProperty (Handle< Object > object, Handle< Name > key)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetPropertyWithAccessor (Handle< Object > receiver, Handle< Name > name, Handle< JSObject > holder, Handle< Object > structure)
 
static MUST_USE_RESULT MaybeHandle< ObjectSetPropertyWithAccessor (Handle< Object > receiver, Handle< Name > name, Handle< Object > value, Handle< JSObject > holder, Handle< Object > structure, StrictMode strict_mode)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetPropertyWithDefinedGetter (Handle< Object > receiver, Handle< JSReceiver > getter)
 
static MUST_USE_RESULT MaybeHandle< ObjectSetPropertyWithDefinedSetter (Handle< Object > receiver, Handle< JSReceiver > setter, Handle< Object > value)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetElement (Isolate *isolate, Handle< Object > object, uint32_t index)
 
static MUST_USE_RESULT MaybeHandle< ObjectGetElementWithReceiver (Isolate *isolate, Handle< Object > object, Handle< Object > receiver, uint32_t index)
 
static Handle< SmiGetOrCreateHash (Isolate *isolate, Handle< Object > object)
 

Static Public Attributes

static const int kMaxCachedArrayIndexLength = 7
 
static const int kArrayIndexValueBits = 24
 
static const int kArrayIndexLengthBits
 
static const unsigned int kContainsCachedArrayIndexMask
 
static const int kLengthOffset = Name::kSize
 
static const int kSize = kLengthOffset + kPointerSize
 
static const int kMaxArrayIndexSize = 10
 
static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar
 
static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar
 
static const int kMaxUtf16CodeUnit = 0xffff
 
static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit
 
static const int kEmptyStringHash = kIsNotArrayIndexMask
 
static const int kMaxLength = (1 << 28) - 16
 
static const int kMaxHashCalcLength = 16383
 
static const int kMaxShortPrintLength = 1024
 
- Static Public Attributes inherited from v8::internal::Name
static const int kHashFieldOffset = HeapObject::kHeaderSize
 
static const int kSize = kHashFieldOffset + kPointerSize
 
static const int kHashNotComputedMask = 1
 
static const int kIsNotArrayIndexMask = 1 << 1
 
static const int kNofHashBitFields = 2
 
static const int kHashShift = kNofHashBitFields
 
static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift
 
static const int kMaxCachedArrayIndexLength = 7
 
static const int kArrayIndexValueBits = 24
 
static const int kArrayIndexLengthBits
 
static const unsigned int kContainsCachedArrayIndexMask
 
static const int kEmptyHashField
 
- Static Public Attributes inherited from v8::internal::HeapObject
static const int kMapOffset = Object::kHeaderSize
 
static const int kHeaderSize = kMapOffset + kPointerSize
 
- Static Public Attributes inherited from v8::internal::Object
static const int kHeaderSize = 0
 

Private Member Functions

bool SlowEquals (String *other)
 
bool SlowAsArrayIndex (uint32_t *index)
 
uint32_t ComputeAndSetHash ()
 
 DISALLOW_IMPLICIT_CONSTRUCTORS (String)
 

Static Private Member Functions

static Handle< StringSlowFlatten (Handle< ConsString > cons, PretenureFlag tenure)
 
static bool SlowEquals (Handle< String > one, Handle< String > two)
 

Friends

class Name
 
class StringTableInsertionKey
 

Additional Inherited Members

- Protected Member Functions inherited from v8::internal::HeapObject
void IteratePointers (ObjectVisitor *v, int start, int end)
 
void IteratePointer (ObjectVisitor *v, int offset)
 
void IterateNextCodeLink (ObjectVisitor *v, int offset)
 
- Static Protected Member Functions inherited from v8::internal::Name
static bool IsHashFieldComputed (uint32_t field)
 

Detailed Description

Definition at line 8591 of file objects.h.

Member Enumeration Documentation

◆ Encoding

Enumerator
ONE_BYTE_ENCODING 
TWO_BYTE_ENCODING 

Definition at line 8593 of file objects.h.

Member Function Documentation

◆ AsArrayIndex()

bool v8::internal::String::AsArrayIndex ( uint32_t index)
inline

Definition at line 6606 of file objects-inl.h.

6606  {
6607  uint32_t field = hash_field();
6608  if (IsHashFieldComputed(field) && (field & kIsNotArrayIndexMask)) {
6609  return false;
6610  }
6611  return SlowAsArrayIndex(index);
6612 }
static const int kIsNotArrayIndexMask
Definition: objects.h:8495
static bool IsHashFieldComputed(uint32_t field)
Definition: objects-inl.h:6455
uint32_t hash_field()
Definition: objects-inl.h:3296
bool SlowAsArrayIndex(uint32_t *index)
Definition: objects.cc:8869

References v8::internal::Name::hash_field(), v8::internal::Name::IsHashFieldComputed(), v8::internal::Name::kIsNotArrayIndexMask, and SlowAsArrayIndex().

+ Here is the call graph for this function:

◆ CalculateLineEnds()

Handle< FixedArray > v8::internal::String::CalculateLineEnds ( Handle< String string,
bool  include_ending_line 
)
static

Definition at line 8483 of file objects.cc.

8484  {
8485  src = Flatten(src);
8486  // Rough estimate of line count based on a roughly estimated average
8487  // length of (unpacked) code.
8488  int line_count_estimate = src->length() >> 4;
8489  List<int> line_ends(line_count_estimate);
8490  Isolate* isolate = src->GetIsolate();
8491  { DisallowHeapAllocation no_allocation; // ensure vectors stay valid.
8492  // Dispatch on type of strings.
8493  String::FlatContent content = src->GetFlatContent();
8494  DCHECK(content.IsFlat());
8495  if (content.IsOneByte()) {
8496  CalculateLineEndsImpl(isolate,
8497  &line_ends,
8498  content.ToOneByteVector(),
8499  include_ending_line);
8500  } else {
8501  CalculateLineEndsImpl(isolate,
8502  &line_ends,
8503  content.ToUC16Vector(),
8504  include_ending_line);
8505  }
8506  }
8507  int line_count = line_ends.length();
8508  Handle<FixedArray> array = isolate->factory()->NewFixedArray(line_count);
8509  for (int i = 0; i < line_count; i++) {
8510  array->set(i, Smi::FromInt(line_ends[i]));
8511  }
8512  return array;
8513 }
static Smi * FromInt(int value)
Definition: objects-inl.h:1321
static Handle< String > Flatten(Handle< String > string, PretenureFlag pretenure=NOT_TENURED)
Definition: objects-inl.h:3354
#define DCHECK(condition)
Definition: logging.h:205
PerThreadAssertScopeDebugOnly< HEAP_ALLOCATION_ASSERT, false > DisallowHeapAllocation
Definition: assert-scope.h:110
static void CalculateLineEndsImpl(Isolate *isolate, List< int > *line_ends, Vector< const SourceChar > src, bool include_ending_line)
Definition: objects.cc:8460

References v8::internal::CalculateLineEndsImpl(), DCHECK, v8::internal::Isolate::factory(), Flatten(), v8::internal::Smi::FromInt(), v8::internal::String::FlatContent::IsFlat(), v8::internal::String::FlatContent::IsOneByte(), v8::internal::String::FlatContent::ToOneByteVector(), and v8::internal::String::FlatContent::ToUC16Vector().

Referenced by v8::internal::Script::InitLineEnds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ComputeAndSetHash()

uint32_t v8::internal::String::ComputeAndSetHash ( )
private

Definition at line 8844 of file objects.cc.

8844  {
8845  // Should only be called if hash code has not yet been computed.
8846  DCHECK(!HasHashCode());
8847 
8848  // Store the hash code in the object.
8849  uint32_t field = IteratingStringHasher::Hash(this, GetHeap()->HashSeed());
8850  set_hash_field(field);
8851 
8852  // Check the hash code is there.
8853  DCHECK(HasHashCode());
8854  uint32_t result = field >> kHashShift;
8855  DCHECK(result != 0); // Ensure that the hash value of 0 is never computed.
8856  return result;
8857 }
Heap * GetHeap() const
Definition: objects-inl.h:1379
static uint32_t Hash(String *string, uint32_t seed)
Definition: objects-inl.h:6572
static const int kHashShift
Definition: objects.h:8499
void set_hash_field(uint32_t value)
Definition: objects-inl.h:3301

References DCHECK, v8::internal::HeapObject::GetHeap(), v8::internal::IteratingStringHasher::Hash(), v8::internal::Name::HasHashCode(), v8::internal::Name::kHashShift, and v8::internal::Name::set_hash_field().

+ Here is the call graph for this function:

◆ ComputeArrayIndex()

bool v8::internal::String::ComputeArrayIndex ( uint32_t index)

Definition at line 8860 of file objects.cc.

8860  {
8861  int length = this->length();
8862  if (length == 0 || length > kMaxArrayIndexSize) return false;
8863  ConsStringIteratorOp op;
8864  StringCharacterStream stream(this, &op);
8865  return StringToArrayIndex(&stream, index);
8866 }
static const int kMaxArrayIndexSize
Definition: objects.h:8807
bool StringToArrayIndex(Stream *stream, uint32_t *index)
Definition: utils.h:1431

References kMaxArrayIndexSize, length(), and v8::internal::StringToArrayIndex().

Referenced by SlowAsArrayIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISALLOW_IMPLICIT_CONSTRUCTORS()

v8::internal::String::DISALLOW_IMPLICIT_CONSTRUCTORS ( String  )
private

◆ Equals() [1/2]

bool v8::internal::String::Equals ( Handle< String one,
Handle< String two 
)
inlinestatic

Definition at line 3345 of file objects-inl.h.

3345  {
3346  if (one.is_identical_to(two)) return true;
3347  if (one->IsInternalizedString() && two->IsInternalizedString()) {
3348  return false;
3349  }
3350  return SlowEquals(one, two);
3351 }
bool SlowEquals(String *other)
Definition: objects.cc:8671

◆ Equals() [2/2]

bool v8::internal::String::Equals ( String other)
inline

◆ Flatten()

Handle< String > v8::internal::String::Flatten ( Handle< String string,
PretenureFlag  pretenure = NOT_TENURED 
)
inlinestatic

Definition at line 3354 of file objects-inl.h.

3354  {
3355  if (!string->IsConsString()) return string;
3356  Handle<ConsString> cons = Handle<ConsString>::cast(string);
3357  if (cons->IsFlat()) return handle(cons->first());
3358  return SlowFlatten(cons, pretenure);
3359 }
static Handle< T > cast(Handle< S > that)
Definition: handles.h:116
static Handle< String > SlowFlatten(Handle< ConsString > cons, PretenureFlag tenure)
Definition: objects.cc:959
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146

References v8::internal::Handle< T >::cast(), and v8::internal::handle().

Referenced by v8::internal::RegExpImpl::AtomExecRaw(), CalculateLineEnds(), v8::internal::LiveEdit::CompareStrings(), v8::internal::RegExpImpl::Compile(), v8::internal::RegExpEngine::Compile(), v8::internal::RegExpImpl::CompileIrregexp(), v8::internal::ConvertCase(), v8::internal::JSObject::DefineAccessor(), v8::internal::Runtime::DefineObjectProperty(), v8::internal::Runtime::DeleteObjectProperty(), v8::internal::GetCharAt(), v8::internal::MessageHandler::GetMessage(), v8::internal::RegExpImpl::IrregexpPrepare(), v8::internal::BASE_EMBEDDED< Visitor >::JsonParser(), v8::JSON::Parse(), v8::internal::Parser::ParseLazy(), v8::internal::Parser::ParseProgram(), v8::internal::RUNTIME_FUNCTION(), v8::internal::JSObject::SetAccessor(), v8::internal::Runtime::SetObjectProperty(), SlowEquals(), v8::internal::Runtime::StringMatch(), v8::WriteHelper(), and v8::String::WriteUtf8().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetFlatContent()

String::FlatContent v8::internal::String::GetFlatContent ( )

Definition at line 7961 of file objects.cc.

7961  {
7962  DCHECK(!AllowHeapAllocation::IsAllowed());
7963  int length = this->length();
7964  StringShape shape(this);
7965  String* string = this;
7966  int offset = 0;
7967  if (shape.representation_tag() == kConsStringTag) {
7968  ConsString* cons = ConsString::cast(string);
7969  if (cons->second()->length() != 0) {
7970  return FlatContent();
7971  }
7972  string = cons->first();
7973  shape = StringShape(string);
7974  }
7975  if (shape.representation_tag() == kSlicedStringTag) {
7976  SlicedString* slice = SlicedString::cast(string);
7977  offset = slice->offset();
7978  string = slice->parent();
7979  shape = StringShape(string);
7980  DCHECK(shape.representation_tag() != kConsStringTag &&
7981  shape.representation_tag() != kSlicedStringTag);
7982  }
7983  if (shape.encoding_tag() == kOneByteStringTag) {
7984  const uint8_t* start;
7985  if (shape.representation_tag() == kSeqStringTag) {
7986  start = SeqOneByteString::cast(string)->GetChars();
7987  } else {
7988  start = ExternalOneByteString::cast(string)->GetChars();
7989  }
7990  return FlatContent(start + offset, length);
7991  } else {
7992  DCHECK(shape.encoding_tag() == kTwoByteStringTag);
7993  const uc16* start;
7994  if (shape.representation_tag() == kSeqStringTag) {
7995  start = SeqTwoByteString::cast(string)->GetChars();
7996  } else {
7997  start = ExternalTwoByteString::cast(string)->GetChars();
7998  }
7999  return FlatContent(start + offset, length);
8000  }
8001 }
@ kSeqStringTag
Definition: objects.h:563
@ kConsStringTag
Definition: objects.h:564
@ kSlicedStringTag
Definition: objects.h:566
const uint32_t kTwoByteStringTag
Definition: objects.h:556
const uint32_t kOneByteStringTag
Definition: objects.h:557
uint16_t uc16
Definition: globals.h:184

References DCHECK, v8::internal::ConsString::first(), v8::internal::kConsStringTag, v8::internal::kOneByteStringTag, v8::internal::kSeqStringTag, v8::internal::kSlicedStringTag, v8::internal::kTwoByteStringTag, length(), v8::internal::SlicedString::offset(), v8::internal::SlicedString::parent(), and v8::internal::ConsString::second().

Referenced by v8::internal::RegExpImpl::AtomExecRaw(), v8::internal::FindStringIndicesDispatch(), IsOneByteEqualTo(), and IsTwoByteEqualTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetForwardedInternalizedString()

String * v8::internal::String::GetForwardedInternalizedString ( )
inline

Definition at line 6630 of file objects-inl.h.

6630  {
6631  DCHECK(IsInternalizedString());
6632  if (HasHashCode()) return this;
6633  String* canonical = String::cast(READ_FIELD(this, kHashFieldOffset));
6634  DCHECK(canonical->IsInternalizedString());
6635  DCHECK(SlowEquals(canonical));
6636  DCHECK(canonical->HasHashCode());
6637  return canonical;
6638 }
static const int kHashFieldOffset
Definition: objects.h:8486
#define READ_FIELD(p, offset)
Definition: objects-inl.h:1179

References DCHECK, v8::internal::Name::HasHashCode(), v8::internal::Name::kHashFieldOffset, READ_FIELD, and SlowEquals().

+ Here is the call graph for this function:

◆ GetTwoByteData()

const uc16 * v8::internal::String::GetTwoByteData ( unsigned  start)

Definition at line 8062 of file objects.cc.

8062  {
8064  switch (StringShape(this).representation_tag()) {
8065  case kSeqStringTag:
8066  return SeqTwoByteString::cast(this)->SeqTwoByteStringGetData(start);
8067  case kExternalStringTag:
8068  return ExternalTwoByteString::cast(this)->
8069  ExternalTwoByteStringGetData(start);
8070  case kSlicedStringTag: {
8071  SlicedString* slice = SlicedString::cast(this);
8072  return slice->parent()->GetTwoByteData(start + slice->offset());
8073  }
8074  case kConsStringTag:
8075  UNREACHABLE();
8076  return NULL;
8077  }
8078  UNREACHABLE();
8079  return NULL;
8080 }
bool IsOneByteRepresentationUnderneath()
Definition: objects-inl.h:349
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define UNREACHABLE()
Definition: logging.h:30
@ kExternalStringTag
Definition: objects.h:565

References DCHECK, GetTwoByteData(), v8::internal::kConsStringTag, v8::internal::kExternalStringTag, v8::internal::kSeqStringTag, v8::internal::kSlicedStringTag, NULL, v8::internal::SlicedString::offset(), v8::internal::SlicedString::parent(), and UNREACHABLE.

Referenced by GetTwoByteData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetUnderlying()

String * v8::internal::String::GetUnderlying ( )
inline

Definition at line 3404 of file objects-inl.h.

3404  {
3405  // Giving direct access to underlying string only makes sense if the
3406  // wrapping string is already flattened.
3407  DCHECK(this->IsFlat());
3408  DCHECK(StringShape(this).IsIndirect());
3410  const int kUnderlyingOffset = SlicedString::kParentOffset;
3411  return String::cast(READ_FIELD(this, kUnderlyingOffset));
3412 }
static const int kFirstOffset
Definition: objects.h:9061
static const int kParentOffset
Definition: objects.h:9104
STATIC_ASSERT(kMaxArrayIndexSize<(1<< kArrayIndexLengthBits))

References DCHECK, v8::internal::ConsString::kFirstOffset, v8::internal::SlicedString::kParentOffset, READ_FIELD, and v8::internal::FixedArray::STATIC_ASSERT().

Referenced by IsOneByteRepresentationUnderneath(), and IsTwoByteRepresentationUnderneath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasOnlyOneByteChars()

bool v8::internal::String::HasOnlyOneByteChars ( )
inline

Definition at line 381 of file objects-inl.h.

381  {
382  uint32_t type = map()->instance_type();
383  return (type & kOneByteDataHintMask) == kOneByteDataHintTag ||
385 }
InstanceType instance_type()
Definition: objects-inl.h:4323
bool IsOneByteRepresentation() const
Definition: objects-inl.h:337
const uint32_t kOneByteDataHintMask
Definition: objects.h:584
const uint32_t kOneByteDataHintTag
Definition: objects.h:585

References v8::internal::Map::instance_type(), IsOneByteRepresentation(), v8::internal::kOneByteDataHintMask, v8::internal::kOneByteDataHintTag, and v8::internal::HeapObject::map().

Referenced by v8::internal::StringBuilderConcatLength().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ INLINE()

v8::internal::String::INLINE ( uint16_t   Getint index)

◆ IsAscii() [1/2]

static bool v8::internal::String::IsAscii ( const char *  chars,
int  length 
)
inlinestatic

Definition at line 8876 of file objects.h.

8876  {
8877  return NonAsciiStart(chars, length) >= length;
8878  }
static int NonAsciiStart(const char *chars, int length)
Definition: objects.h:8843

◆ IsAscii() [2/2]

static bool v8::internal::String::IsAscii ( const uint8_t *  chars,
int  length 
)
inlinestatic

Definition at line 8880 of file objects.h.

8880  {
8881  return
8882  NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length;
8883  }

◆ IsFlat()

bool v8::internal::String::IsFlat ( )
inline

Definition at line 3398 of file objects-inl.h.

3398  {
3399  if (!StringShape(this).IsCons()) return true;
3400  return ConsString::cast(this)->second()->length() == 0;
3401 }

Referenced by v8::internal::RegExpImpl::AtomExecRaw(), IsOneByteRepresentationUnderneath(), and IsTwoByteRepresentationUnderneath().

+ Here is the caller graph for this function:

◆ IsOneByte()

static bool v8::internal::String::IsOneByte ( const uc16 chars,
int  length 
)
inlinestatic

Definition at line 8895 of file objects.h.

8895  {
8896  return NonOneByteStart(chars, length) >= length;
8897  }
static int NonOneByteStart(const uc16 *chars, int length)
Definition: objects.h:8885

Referenced by v8::internal::StringSearchBase::IsOneByteString(), and MakeExternal().

+ Here is the caller graph for this function:

◆ IsOneByteEqualTo()

bool v8::internal::String::IsOneByteEqualTo ( Vector< const uint8_t >  str)

Definition at line 8813 of file objects.cc.

8813  {
8814  int slen = length();
8815  if (str.length() != slen) return false;
8816  DisallowHeapAllocation no_gc;
8817  FlatContent content = GetFlatContent();
8818  if (content.IsOneByte()) {
8819  return CompareChars(content.ToOneByteVector().start(),
8820  str.start(), slen) == 0;
8821  }
8822  for (int i = 0; i < slen; i++) {
8823  if (Get(i) != static_cast<uint16_t>(str[i])) return false;
8824  }
8825  return true;
8826 }
FlatContent GetFlatContent()
Definition: objects.cc:7961
unsigned short uint16_t
Definition: unicode.cc:23
int CompareChars(const lchar *lhs, const rchar *rhs, int chars)
Definition: utils.h:705

References v8::internal::CompareChars(), GetFlatContent(), v8::internal::String::FlatContent::IsOneByte(), length(), v8::internal::Vector< T >::length(), v8::internal::Vector< T >::start(), and v8::internal::String::FlatContent::ToOneByteVector().

+ Here is the call graph for this function:

◆ IsOneByteRepresentation()

bool v8::internal::String::IsOneByteRepresentation ( ) const
inline

Definition at line 337 of file objects-inl.h.

337  {
338  uint32_t type = map()->instance_type();
339  return (type & kStringEncodingMask) == kOneByteStringTag;
340 }
const uint32_t kStringEncodingMask
Definition: objects.h:555

References v8::internal::Map::instance_type(), v8::internal::kOneByteStringTag, v8::internal::kStringEncodingMask, and v8::internal::HeapObject::map().

Referenced by v8::internal::BOOL_ACCESSORS(), HasOnlyOneByteChars(), v8::internal::Heap::IsOneByte(), IsOneByteRepresentationUnderneath(), MakeExternal(), v8::internal::NativeRegExpMacroAssembler::Match(), v8::internal::RUNTIME_FUNCTION(), and v8::internal::NativeRegExpMacroAssembler::StringCharacterPosition().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsOneByteRepresentationUnderneath()

bool v8::internal::String::IsOneByteRepresentationUnderneath ( )
inline

Definition at line 349 of file objects-inl.h.

349  {
350  uint32_t type = map()->instance_type();
353  DCHECK(IsFlat());
354  switch (type & (kIsIndirectStringMask | kStringEncodingMask)) {
355  case kOneByteStringTag:
356  return true;
357  case kTwoByteStringTag:
358  return false;
359  default: // Cons or sliced string. Need to go deeper.
361  }
362 }
String * GetUnderlying()
Definition: objects-inl.h:3404
const uint32_t kIsIndirectStringTag
Definition: objects.h:569
const uint32_t kIsIndirectStringMask
Definition: objects.h:568

References DCHECK, GetUnderlying(), v8::internal::Map::instance_type(), IsFlat(), IsOneByteRepresentation(), v8::internal::kIsIndirectStringMask, v8::internal::kIsIndirectStringTag, v8::internal::kOneByteStringTag, v8::internal::kStringEncodingMask, v8::internal::kTwoByteStringTag, v8::internal::HeapObject::map(), and STATIC_ASSERT().

+ Here is the call graph for this function:

◆ IsTwoByteEqualTo()

bool v8::internal::String::IsTwoByteEqualTo ( Vector< const uc16 str)

Definition at line 8829 of file objects.cc.

8829  {
8830  int slen = length();
8831  if (str.length() != slen) return false;
8832  DisallowHeapAllocation no_gc;
8833  FlatContent content = GetFlatContent();
8834  if (content.IsTwoByte()) {
8835  return CompareChars(content.ToUC16Vector().start(), str.start(), slen) == 0;
8836  }
8837  for (int i = 0; i < slen; i++) {
8838  if (Get(i) != str[i]) return false;
8839  }
8840  return true;
8841 }
T * start() const
Definition: vector.h:47
int length() const
Definition: vector.h:41

References v8::internal::CompareChars(), GetFlatContent(), v8::internal::String::FlatContent::IsTwoByte(), length(), v8::internal::Vector< T >::length(), v8::internal::Vector< T >::start(), and v8::internal::String::FlatContent::ToUC16Vector().

+ Here is the call graph for this function:

◆ IsTwoByteRepresentation()

bool v8::internal::String::IsTwoByteRepresentation ( ) const
inline

Definition at line 343 of file objects-inl.h.

343  {
344  uint32_t type = map()->instance_type();
345  return (type & kStringEncodingMask) == kTwoByteStringTag;
346 }

References v8::internal::Map::instance_type(), v8::internal::kStringEncodingMask, v8::internal::kTwoByteStringTag, and v8::internal::HeapObject::map().

Referenced by v8::internal::BOOL_ACCESSORS(), IsTwoByteRepresentationUnderneath(), and MakeExternal().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsTwoByteRepresentationUnderneath()

bool v8::internal::String::IsTwoByteRepresentationUnderneath ( )
inline

Definition at line 365 of file objects-inl.h.

365  {
366  uint32_t type = map()->instance_type();
369  DCHECK(IsFlat());
370  switch (type & (kIsIndirectStringMask | kStringEncodingMask)) {
371  case kOneByteStringTag:
372  return false;
373  case kTwoByteStringTag:
374  return true;
375  default: // Cons or sliced string. Need to go deeper.
377  }
378 }
bool IsTwoByteRepresentation() const
Definition: objects-inl.h:343

References DCHECK, GetUnderlying(), v8::internal::Map::instance_type(), IsFlat(), IsTwoByteRepresentation(), v8::internal::kIsIndirectStringMask, v8::internal::kIsIndirectStringTag, v8::internal::kOneByteStringTag, v8::internal::kStringEncodingMask, v8::internal::kTwoByteStringTag, v8::internal::HeapObject::map(), and STATIC_ASSERT().

+ Here is the call graph for this function:

◆ IsUtf8EqualTo()

bool v8::internal::String::IsUtf8EqualTo ( Vector< const char >  str,
bool  allow_prefix_match = false 
)

Definition at line 8783 of file objects.cc.

8783  {
8784  int slen = length();
8785  // Can't check exact length equality, but we can check bounds.
8786  int str_len = str.length();
8787  if (!allow_prefix_match &&
8788  (str_len < slen ||
8789  str_len > slen*static_cast<int>(unibrow::Utf8::kMaxEncodedSize))) {
8790  return false;
8791  }
8792  int i;
8793  unsigned remaining_in_str = static_cast<unsigned>(str_len);
8794  const uint8_t* utf8_data = reinterpret_cast<const uint8_t*>(str.start());
8795  for (i = 0; i < slen && remaining_in_str > 0; i++) {
8796  unsigned cursor = 0;
8797  uint32_t r = unibrow::Utf8::ValueOf(utf8_data, remaining_in_str, &cursor);
8798  DCHECK(cursor > 0 && cursor <= remaining_in_str);
8800  if (i > slen - 1) return false;
8801  if (Get(i++) != unibrow::Utf16::LeadSurrogate(r)) return false;
8802  if (Get(i) != unibrow::Utf16::TrailSurrogate(r)) return false;
8803  } else {
8804  if (Get(i) != r) return false;
8805  }
8806  utf8_data += cursor;
8807  remaining_in_str -= cursor;
8808  }
8809  return (allow_prefix_match || i == slen) && remaining_in_str == 0;
8810 }
static uint16_t LeadSurrogate(uint32_t char_code)
Definition: unicode.h:108
static const uchar kMaxNonSurrogateCharCode
Definition: unicode.h:98
static uint16_t TrailSurrogate(uint32_t char_code)
Definition: unicode.h:111
static uchar ValueOf(const byte *str, unsigned length, unsigned *cursor)
Definition: unicode-inl.h:129
static const unsigned kMaxEncodedSize
Definition: unicode.h:140

References DCHECK, unibrow::Utf8::kMaxEncodedSize, unibrow::Utf16::kMaxNonSurrogateCharCode, unibrow::Utf16::LeadSurrogate(), length(), v8::internal::Vector< T >::length(), v8::internal::Vector< T >::start(), unibrow::Utf16::TrailSurrogate(), and unibrow::Utf8::ValueOf().

Referenced by v8::internal::BASE_EMBEDDED< Visitor >::Lookup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ length()

◆ LooksValid()

bool v8::internal::String::LooksValid ( )

Definition at line 7955 of file objects.cc.

7955  {
7956  if (!GetIsolate()->heap()->Contains(this)) return false;
7957  return true;
7958 }
Isolate * GetIsolate() const
Definition: objects-inl.h:1387

References v8::internal::HeapObject::GetIsolate().

Referenced by v8::internal::operator<<(), and StringShortPrint().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MakeExternal() [1/2]

bool v8::internal::String::MakeExternal ( v8::String::ExternalOneByteStringResource resource)

Definition at line 1051 of file objects.cc.

1051  {
1052  // Externalizing twice leaks the external resource, so it's
1053  // prohibited by the API.
1054  DCHECK(!this->IsExternalString());
1055 #ifdef ENABLE_SLOW_DCHECKS
1057  // Assert that the resource and the string are equivalent.
1058  DCHECK(static_cast<size_t>(this->length()) == resource->length());
1059  if (this->IsTwoByteRepresentation()) {
1060  ScopedVector<uint16_t> smart_chars(this->length());
1061  String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1062  DCHECK(String::IsOneByte(smart_chars.start(), this->length()));
1063  }
1064  ScopedVector<char> smart_chars(this->length());
1065  String::WriteToFlat(this, smart_chars.start(), 0, this->length());
1066  DCHECK(memcmp(smart_chars.start(),
1067  resource->data(),
1068  resource->length() * sizeof(smart_chars[0])) == 0);
1069  }
1070 #endif // DEBUG
1071  int size = this->Size(); // Byte size of the original string.
1072  // Abort if size does not allow in-place conversion.
1073  if (size < ExternalString::kShortSize) return false;
1074  Heap* heap = GetHeap();
1075  bool is_internalized = this->IsInternalizedString();
1076 
1077  // Morph the string to an external string by replacing the map and
1078  // reinitializing the fields. This won't work if the space the existing
1079  // string occupies is too small for a regular external string.
1080  // Instead, we resort to a short external string instead, omitting
1081  // the field caching the address of the backing store. When we encounter
1082  // short external strings in generated code, we need to bailout to runtime.
1083  Map* new_map;
1084  if (size < ExternalString::kSize) {
1085  new_map = is_internalized
1086  ? heap->short_external_one_byte_internalized_string_map()
1087  : heap->short_external_one_byte_string_map();
1088  } else {
1089  new_map = is_internalized
1090  ? heap->external_one_byte_internalized_string_map()
1091  : heap->external_one_byte_string_map();
1092  }
1093 
1094  // Byte size of the external String object.
1095  int new_size = this->SizeFromMap(new_map);
1096  heap->CreateFillerObjectAt(this->address() + new_size, size - new_size);
1097 
1098  // We are storing the new map using release store after creating a filler for
1099  // the left-over space to avoid races with the sweeper thread.
1100  this->synchronized_set_map(new_map);
1101 
1102  ExternalOneByteString* self = ExternalOneByteString::cast(this);
1103  self->set_resource(resource);
1104  if (is_internalized) self->Hash(); // Force regeneration of the hash value.
1105 
1106  heap->AdjustLiveBytes(this->address(), new_size - size, Heap::FROM_MUTATOR);
1107  return true;
1108 }
virtual const char * data() const =0
The string data from the underlying buffer.
virtual size_t length() const =0
The number of Latin-1 characters in the string.
static const int kSize
Definition: objects.h:9139
static const int kShortSize
Definition: objects.h:9137
void synchronized_set_map(Map *value)
Definition: objects-inl.h:1419
int SizeFromMap(Map *map)
Definition: objects-inl.h:4259
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
Definition: objects.cc:8370
static bool IsOneByte(const uc16 *chars, int length)
Definition: objects.h:8895
enable harmony numeric enable harmony object literal extensions Optimize object size
const bool FLAG_enable_slow_asserts
Definition: checks.h:31

References v8::internal::HeapObject::address(), v8::internal::Heap::AdjustLiveBytes(), v8::internal::Heap::CreateFillerObjectAt(), v8::String::ExternalOneByteStringResource::data(), DCHECK, v8::internal::FLAG_enable_slow_asserts, v8::internal::Heap::FROM_MUTATOR, v8::internal::HeapObject::GetHeap(), IsOneByte(), IsTwoByteRepresentation(), v8::internal::ExternalString::kShortSize, v8::internal::ExternalString::kSize, length(), v8::String::ExternalOneByteStringResource::length(), size, v8::internal::HeapObject::Size(), v8::internal::HeapObject::SizeFromMap(), v8::internal::Vector< T >::start(), v8::internal::HeapObject::synchronized_set_map(), and WriteToFlat().

+ Here is the call graph for this function:

◆ MakeExternal() [2/2]

bool v8::internal::String::MakeExternal ( v8::String::ExternalStringResource resource)

Definition at line 989 of file objects.cc.

989  {
990  // Externalizing twice leaks the external resource, so it's
991  // prohibited by the API.
992  DCHECK(!this->IsExternalString());
993 #ifdef ENABLE_SLOW_DCHECKS
995  // Assert that the resource and the string are equivalent.
996  DCHECK(static_cast<size_t>(this->length()) == resource->length());
997  ScopedVector<uc16> smart_chars(this->length());
998  String::WriteToFlat(this, smart_chars.start(), 0, this->length());
999  DCHECK(memcmp(smart_chars.start(),
1000  resource->data(),
1001  resource->length() * sizeof(smart_chars[0])) == 0);
1002  }
1003 #endif // DEBUG
1004  int size = this->Size(); // Byte size of the original string.
1005  // Abort if size does not allow in-place conversion.
1006  if (size < ExternalString::kShortSize) return false;
1007  Heap* heap = GetHeap();
1008  bool is_one_byte = this->IsOneByteRepresentation();
1009  bool is_internalized = this->IsInternalizedString();
1010 
1011  // Morph the string to an external string by replacing the map and
1012  // reinitializing the fields. This won't work if the space the existing
1013  // string occupies is too small for a regular external string.
1014  // Instead, we resort to a short external string instead, omitting
1015  // the field caching the address of the backing store. When we encounter
1016  // short external strings in generated code, we need to bailout to runtime.
1017  Map* new_map;
1018  if (size < ExternalString::kSize) {
1019  new_map = is_internalized
1020  ? (is_one_byte
1021  ? heap->short_external_internalized_string_with_one_byte_data_map()
1022  : heap->short_external_internalized_string_map())
1023  : (is_one_byte ? heap->short_external_string_with_one_byte_data_map()
1024  : heap->short_external_string_map());
1025  } else {
1026  new_map = is_internalized
1027  ? (is_one_byte
1028  ? heap->external_internalized_string_with_one_byte_data_map()
1029  : heap->external_internalized_string_map())
1030  : (is_one_byte ? heap->external_string_with_one_byte_data_map()
1031  : heap->external_string_map());
1032  }
1033 
1034  // Byte size of the external String object.
1035  int new_size = this->SizeFromMap(new_map);
1036  heap->CreateFillerObjectAt(this->address() + new_size, size - new_size);
1037 
1038  // We are storing the new map using release store after creating a filler for
1039  // the left-over space to avoid races with the sweeper thread.
1040  this->synchronized_set_map(new_map);
1041 
1042  ExternalTwoByteString* self = ExternalTwoByteString::cast(this);
1043  self->set_resource(resource);
1044  if (is_internalized) self->Hash(); // Force regeneration of the hash value.
1045 
1046  heap->AdjustLiveBytes(this->address(), new_size - size, Heap::FROM_MUTATOR);
1047  return true;
1048 }
virtual const uint16_t * data() const =0
The string data from the underlying buffer.
virtual size_t length() const =0
The length of the string.

References v8::internal::HeapObject::address(), v8::internal::Heap::AdjustLiveBytes(), v8::internal::Heap::CreateFillerObjectAt(), v8::String::ExternalStringResource::data(), DCHECK, v8::internal::FLAG_enable_slow_asserts, v8::internal::Heap::FROM_MUTATOR, v8::internal::HeapObject::GetHeap(), IsOneByteRepresentation(), v8::internal::ExternalString::kShortSize, v8::internal::ExternalString::kSize, length(), v8::String::ExternalStringResource::length(), size, v8::internal::HeapObject::Size(), v8::internal::HeapObject::SizeFromMap(), v8::internal::Vector< T >::start(), v8::internal::HeapObject::synchronized_set_map(), and WriteToFlat().

+ Here is the call graph for this function:

◆ MarkAsUndetectable()

bool v8::internal::String::MarkAsUndetectable ( )

Definition at line 8766 of file objects.cc.

8766  {
8767  if (StringShape(this).IsInternalized()) return false;
8768 
8769  Map* map = this->map();
8770  Heap* heap = GetHeap();
8771  if (map == heap->string_map()) {
8772  this->set_map(heap->undetectable_string_map());
8773  return true;
8774  } else if (map == heap->one_byte_string_map()) {
8775  this->set_map(heap->undetectable_one_byte_string_map());
8776  return true;
8777  }
8778  // Rest cannot be marked as undetectable
8779  return false;
8780 }
void set_map(Map *value)
Definition: objects-inl.h:1404

References v8::internal::HeapObject::GetHeap(), v8::internal::HeapObject::map(), and v8::internal::HeapObject::set_map().

+ Here is the call graph for this function:

◆ NonAsciiStart()

static int v8::internal::String::NonAsciiStart ( const char *  chars,
int  length 
)
inlinestatic

Definition at line 8843 of file objects.h.

8843  {
8844  const char* start = chars;
8845  const char* limit = chars + length;
8846 
8847  if (length >= kIntptrSize) {
8848  // Check unaligned bytes.
8849  while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) {
8850  if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8851  return static_cast<int>(chars - start);
8852  }
8853  ++chars;
8854  }
8855  // Check aligned words.
8857  const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80;
8858  while (chars + sizeof(uintptr_t) <= limit) {
8859  if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) {
8860  return static_cast<int>(chars - start);
8861  }
8862  chars += sizeof(uintptr_t);
8863  }
8864  }
8865  // Check remaining unaligned bytes.
8866  while (chars < limit) {
8867  if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
8868  return static_cast<int>(chars - start);
8869  }
8870  ++chars;
8871  }
8872 
8873  return static_cast<int>(chars - start);
8874  }
static const unsigned kMaxOneByteChar
Definition: unicode.h:141
const uintptr_t kUintptrAllBitsSet
Definition: globals.h:149
const int kIntptrSize
Definition: globals.h:128
bool IsAligned(T value, U alignment)
Definition: utils.h:123

References DCHECK, v8::internal::IsAligned(), v8::internal::kIntptrSize, unibrow::Utf8::kMaxOneByteChar, and v8::internal::kUintptrAllBitsSet.

+ Here is the call graph for this function:

◆ NonOneByteStart()

static int v8::internal::String::NonOneByteStart ( const uc16 chars,
int  length 
)
inlinestatic

Definition at line 8885 of file objects.h.

8885  {
8886  const uc16* limit = chars + length;
8887  const uc16* start = chars;
8888  while (chars < limit) {
8889  if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
8890  ++chars;
8891  }
8892  return static_cast<int>(chars - start);
8893  }
static const uint32_t kMaxOneByteCharCodeU
Definition: objects.h:8812

◆ PrintOn()

void v8::internal::String::PrintOn ( FILE *  out)

Definition at line 9005 of file objects.cc.

9005  {
9006  int length = this->length();
9007  for (int i = 0; i < length; i++) {
9008  PrintF(file, "%c", Get(i));
9009  }
9010 }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes A file to write the raw context snapshot bytes Write V8 startup blob file(mksnapshot only)") DEFINE_BOOL(profile_hydrogen_code_stub_compilation
void PrintF(const char *format,...)
Definition: utils.cc:80

References length(), and v8::internal::PrintF().

Referenced by v8::internal::Map::PrintGeneralization(), and v8::internal::JSObject::PrintInstanceMigration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PrintUC16()

void v8::internal::String::PrintUC16 ( OStream os,
int  start = 0,
int  end = -1 
)

Definition at line 1175 of file objects.cc.

1175  { // NOLINT
1176  if (end < 0) end = length();
1177  ConsStringIteratorOp op;
1178  StringCharacterStream stream(this, &op, start);
1179  for (int i = start; i < end && stream.HasMore(); i++) {
1180  os << AsUC16(stream.GetNext());
1181  }
1182 }

References v8::internal::StringCharacterStream::GetNext(), v8::internal::StringCharacterStream::HasMore(), and length().

Referenced by v8::internal::operator<<().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Set()

void v8::internal::String::Set ( int  index,
uint16_t  value 
)
inline

Definition at line 3388 of file objects-inl.h.

3388  {
3389  DCHECK(index >= 0 && index < length());
3390  DCHECK(StringShape(this).IsSequential());
3391 
3392  return this->IsOneByteRepresentation()
3393  ? SeqOneByteString::cast(this)->SeqOneByteStringSet(index, value)
3394  : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value);
3395 }

References DCHECK, and v8::internal::FixedArrayBase::length().

Referenced by v8::internal::ConvertCaseHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_length()

void v8::internal::String::set_length ( int  value)
inline

Referenced by v8::internal::Heap::AllocateInternalizedStringImpl(), v8::internal::Heap::AllocateOneByteInternalizedString(), and v8::internal::Heap::AllocateTwoByteInternalizedString().

+ Here is the caller graph for this function:

◆ SetForwardedInternalizedString()

void v8::internal::String::SetForwardedInternalizedString ( String string)
inline

Definition at line 6615 of file objects-inl.h.

6615  {
6616  DCHECK(IsInternalizedString());
6617  DCHECK(HasHashCode());
6618  if (canonical == this) return; // No need to forward.
6619  DCHECK(SlowEquals(canonical));
6620  DCHECK(canonical->IsInternalizedString());
6621  DCHECK(canonical->HasHashCode());
6622  WRITE_FIELD(this, kHashFieldOffset, canonical);
6623  // Setting the hash field to a tagged value sets the LSB, causing the hash
6624  // code to be interpreted as uninitialized. We use this fact to recognize
6625  // that we have a forwarded string.
6626  DCHECK(!HasHashCode());
6627 }
#define WRITE_FIELD(p, offset, value)
Definition: objects-inl.h:1190

References DCHECK, v8::internal::Name::HasHashCode(), v8::internal::Name::kHashFieldOffset, SlowEquals(), and WRITE_FIELD.

+ Here is the call graph for this function:

◆ SlowAsArrayIndex()

bool v8::internal::String::SlowAsArrayIndex ( uint32_t index)
private

Definition at line 8869 of file objects.cc.

8869  {
8871  Hash(); // force computation of hash code
8872  uint32_t field = hash_field();
8873  if ((field & kIsNotArrayIndexMask) != 0) return false;
8874  // Isolate the array index form the full hash field.
8875  *index = ArrayIndexValueBits::decode(field);
8876  return true;
8877  } else {
8878  return ComputeArrayIndex(index);
8879  }
8880 }
static T decode(U value)
Definition: utils.h:228
bool ComputeArrayIndex(uint32_t *index)
Definition: objects.cc:8860
static const int kMaxCachedArrayIndexLength
Definition: objects.h:8596

References ComputeArrayIndex(), v8::internal::BitFieldBase< T, shift, size, U >::decode(), v8::internal::Name::Hash(), v8::internal::Name::hash_field(), v8::internal::Name::kIsNotArrayIndexMask, kMaxCachedArrayIndexLength, and length().

Referenced by AsArrayIndex().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SlowEquals() [1/2]

bool v8::internal::String::SlowEquals ( Handle< String one,
Handle< String two 
)
staticprivate

Definition at line 8716 of file objects.cc.

8716  {
8717  // Fast check: negative check with lengths.
8718  int one_length = one->length();
8719  if (one_length != two->length()) return false;
8720  if (one_length == 0) return true;
8721 
8722  // Fast check: if hash code is computed for both strings
8723  // a fast negative check can be performed.
8724  if (one->HasHashCode() && two->HasHashCode()) {
8725 #ifdef ENABLE_SLOW_DCHECKS
8727  if (one->Hash() != two->Hash()) {
8728  bool found_difference = false;
8729  for (int i = 0; i < one_length; i++) {
8730  if (one->Get(i) != two->Get(i)) {
8731  found_difference = true;
8732  break;
8733  }
8734  }
8735  DCHECK(found_difference);
8736  }
8737  }
8738 #endif
8739  if (one->Hash() != two->Hash()) return false;
8740  }
8741 
8742  // We know the strings are both non-empty. Compare the first chars
8743  // before we try to flatten the strings.
8744  if (one->Get(0) != two->Get(0)) return false;
8745 
8746  one = String::Flatten(one);
8747  two = String::Flatten(two);
8748 
8749  DisallowHeapAllocation no_gc;
8750  String::FlatContent flat1 = one->GetFlatContent();
8751  String::FlatContent flat2 = two->GetFlatContent();
8752 
8753  if (flat1.IsOneByte() && flat2.IsOneByte()) {
8754  return CompareRawStringContents(flat1.ToOneByteVector().start(),
8755  flat2.ToOneByteVector().start(),
8756  one_length);
8757  } else {
8758  for (int i = 0; i < one_length; i++) {
8759  if (flat1.Get(i) != flat2.Get(i)) return false;
8760  }
8761  return true;
8762  }
8763 }
static bool CompareRawStringContents(const Char *const a, const Char *const b, int length)
Definition: objects.cc:8519

References v8::internal::CompareRawStringContents(), DCHECK, v8::internal::FLAG_enable_slow_asserts, Flatten(), v8::internal::String::FlatContent::Get(), v8::internal::String::FlatContent::IsOneByte(), and v8::internal::String::FlatContent::ToOneByteVector().

+ Here is the call graph for this function:

◆ SlowEquals() [2/2]

bool v8::internal::String::SlowEquals ( String other)
private

Definition at line 8671 of file objects.cc.

8671  {
8672  DisallowHeapAllocation no_gc;
8673  // Fast check: negative check with lengths.
8674  int len = length();
8675  if (len != other->length()) return false;
8676  if (len == 0) return true;
8677 
8678  // Fast check: if hash code is computed for both strings
8679  // a fast negative check can be performed.
8680  if (HasHashCode() && other->HasHashCode()) {
8681 #ifdef ENABLE_SLOW_DCHECKS
8683  if (Hash() != other->Hash()) {
8684  bool found_difference = false;
8685  for (int i = 0; i < len; i++) {
8686  if (Get(i) != other->Get(i)) {
8687  found_difference = true;
8688  break;
8689  }
8690  }
8691  DCHECK(found_difference);
8692  }
8693  }
8694 #endif
8695  if (Hash() != other->Hash()) return false;
8696  }
8697 
8698  // We know the strings are both non-empty. Compare the first chars
8699  // before we try to flatten the strings.
8700  if (this->Get(0) != other->Get(0)) return false;
8701 
8702  if (IsSeqOneByteString() && other->IsSeqOneByteString()) {
8703  const uint8_t* str1 = SeqOneByteString::cast(this)->GetChars();
8704  const uint8_t* str2 = SeqOneByteString::cast(other)->GetChars();
8705  return CompareRawStringContents(str1, str2, len);
8706  }
8707 
8708  Isolate* isolate = GetIsolate();
8709  StringComparator comparator(isolate->objects_string_compare_iterator_a(),
8710  isolate->objects_string_compare_iterator_b());
8711 
8712  return comparator.Equals(this, other);
8713 }
static int comparator(const HeapObjectInfo *a, const HeapObjectInfo *b)

References v8::internal::anonymous_namespace{heap-snapshot-generator.cc}::comparator(), v8::internal::CompareRawStringContents(), DCHECK, v8::internal::FLAG_enable_slow_asserts, v8::internal::HeapObject::GetIsolate(), v8::internal::Name::Hash(), v8::internal::Name::HasHashCode(), length(), v8::internal::Isolate::objects_string_compare_iterator_a(), and v8::internal::Isolate::objects_string_compare_iterator_b().

Referenced by v8::internal::Name::Equals(), GetForwardedInternalizedString(), v8::internal::StringTableInsertionKey::IsMatch(), and SetForwardedInternalizedString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SlowFlatten()

Handle< String > v8::internal::String::SlowFlatten ( Handle< ConsString cons,
PretenureFlag  tenure 
)
staticprivate

Definition at line 959 of file objects.cc.

960  {
961  DCHECK(AllowHeapAllocation::IsAllowed());
962  DCHECK(cons->second()->length() != 0);
963  Isolate* isolate = cons->GetIsolate();
964  int length = cons->length();
965  PretenureFlag tenure = isolate->heap()->InNewSpace(*cons) ? pretenure
966  : TENURED;
967  Handle<SeqString> result;
968  if (cons->IsOneByteRepresentation()) {
969  Handle<SeqOneByteString> flat = isolate->factory()->NewRawOneByteString(
970  length, tenure).ToHandleChecked();
972  WriteToFlat(*cons, flat->GetChars(), 0, length);
973  result = flat;
974  } else {
975  Handle<SeqTwoByteString> flat = isolate->factory()->NewRawTwoByteString(
976  length, tenure).ToHandleChecked();
978  WriteToFlat(*cons, flat->GetChars(), 0, length);
979  result = flat;
980  }
981  cons->set_first(*result);
982  cons->set_second(isolate->heap()->empty_string());
983  DCHECK(result->IsFlat());
984  return result;
985 }

References DCHECK, v8::internal::Isolate::factory(), v8::internal::Isolate::heap(), v8::internal::Heap::InNewSpace(), length(), v8::internal::TENURED, and WriteToFlat().

+ Here is the call graph for this function:

◆ STATIC_ASSERT() [1/3]

v8::internal::String::STATIC_ASSERT ( (kArrayIndexLengthBits > 0)  )

◆ STATIC_ASSERT() [2/3]

v8::internal::String::STATIC_ASSERT ( IS_POWER_OF_TWO(kMaxCachedArrayIndexLength+1)  )

◆ STATIC_ASSERT() [3/3]

v8::internal::String::STATIC_ASSERT ( )

Referenced by IsOneByteRepresentationUnderneath(), and IsTwoByteRepresentationUnderneath().

+ Here is the caller graph for this function:

◆ StringShortPrint()

void v8::internal::String::StringShortPrint ( StringStream *  accumulator)

Definition at line 1111 of file objects.cc.

1111  {
1112  int len = length();
1113  if (len > kMaxShortPrintLength) {
1114  accumulator->Add("<Very long string[%u]>", len);
1115  return;
1116  }
1117 
1118  if (!LooksValid()) {
1119  accumulator->Add("<Invalid String>");
1120  return;
1121  }
1122 
1123  ConsStringIteratorOp op;
1124  StringCharacterStream stream(this, &op);
1125 
1126  bool truncated = false;
1127  if (len > kMaxShortPrintLength) {
1128  len = kMaxShortPrintLength;
1129  truncated = true;
1130  }
1131  bool one_byte = true;
1132  for (int i = 0; i < len; i++) {
1133  uint16_t c = stream.GetNext();
1134 
1135  if (c < 32 || c >= 127) {
1136  one_byte = false;
1137  }
1138  }
1139  stream.Reset(this);
1140  if (one_byte) {
1141  accumulator->Add("<String[%u]: ", length());
1142  for (int i = 0; i < len; i++) {
1143  accumulator->Put(static_cast<char>(stream.GetNext()));
1144  }
1145  accumulator->Put('>');
1146  } else {
1147  // Backslash indicates that the string contains control
1148  // characters and that backslashes are therefore escaped.
1149  accumulator->Add("<String[%u]\\: ", length());
1150  for (int i = 0; i < len; i++) {
1151  uint16_t c = stream.GetNext();
1152  if (c == '\n') {
1153  accumulator->Add("\\n");
1154  } else if (c == '\r') {
1155  accumulator->Add("\\r");
1156  } else if (c == '\\') {
1157  accumulator->Add("\\\\");
1158  } else if (c < 32 || c > 126) {
1159  accumulator->Add("\\x%02x", c);
1160  } else {
1161  accumulator->Put(static_cast<char>(c));
1162  }
1163  }
1164  if (truncated) {
1165  accumulator->Put('.');
1166  accumulator->Put('.');
1167  accumulator->Put('.');
1168  }
1169  accumulator->Put('>');
1170  }
1171  return;
1172 }
static const int kMaxShortPrintLength
Definition: objects.h:8827

References v8::internal::StringCharacterStream::GetNext(), kMaxShortPrintLength, length(), LooksValid(), and v8::internal::StringCharacterStream::Reset().

+ Here is the call graph for this function:

◆ synchronized_length()

int v8::internal::String::synchronized_length ( ) const
inline

◆ synchronized_set_length()

void v8::internal::String::synchronized_set_length ( int  value)
inline

◆ ToCString() [1/2]

SmartArrayPointer< char > v8::internal::String::ToCString ( AllowNullsFlag  allow_nulls,
RobustnessFlag  robustness_flag,
int  offset,
int  length,
int length_output = 0 
)

Definition at line 8004 of file objects.cc.

8008  {
8009  if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
8010  return SmartArrayPointer<char>(NULL);
8011  }
8012  Heap* heap = GetHeap();
8013 
8014  // Negative length means the to the end of the string.
8015  if (length < 0) length = kMaxInt - offset;
8016 
8017  // Compute the size of the UTF-8 string. Start at the specified offset.
8018  Access<ConsStringIteratorOp> op(
8019  heap->isolate()->objects_string_iterator());
8020  StringCharacterStream stream(this, op.value(), offset);
8021  int character_position = offset;
8022  int utf8_bytes = 0;
8024  while (stream.HasMore() && character_position++ < offset + length) {
8025  uint16_t character = stream.GetNext();
8026  utf8_bytes += unibrow::Utf8::Length(character, last);
8027  last = character;
8028  }
8029 
8030  if (length_return) {
8031  *length_return = utf8_bytes;
8032  }
8033 
8034  char* result = NewArray<char>(utf8_bytes + 1);
8035 
8036  // Convert the UTF-16 string to a UTF-8 buffer. Start at the specified offset.
8037  stream.Reset(this, offset);
8038  character_position = offset;
8039  int utf8_byte_position = 0;
8041  while (stream.HasMore() && character_position++ < offset + length) {
8042  uint16_t character = stream.GetNext();
8043  if (allow_nulls == DISALLOW_NULLS && character == 0) {
8044  character = ' ';
8045  }
8046  utf8_byte_position +=
8047  unibrow::Utf8::Encode(result + utf8_byte_position, character, last);
8048  last = character;
8049  }
8050  result[utf8_byte_position] = 0;
8051  return SmartArrayPointer<char>(result);
8052 }
static const int kNoPreviousCharacter
Definition: unicode.h:97
static uchar Length(uchar chr, int previous)
Definition: unicode-inl.h:140
static unsigned Encode(char *out, uchar c, int previous, bool replace_invalid=false)
Definition: unicode-inl.h:91
@ DISALLOW_NULLS
Definition: objects.h:8337
const int kMaxInt
Definition: globals.h:109
@ ROBUST_STRING_TRAVERSAL
Definition: objects.h:8338

References v8::internal::DISALLOW_NULLS, unibrow::Utf8::Encode(), v8::internal::HeapObject::GetHeap(), v8::internal::StringCharacterStream::GetNext(), v8::internal::StringCharacterStream::HasMore(), v8::internal::Heap::isolate(), v8::internal::kMaxInt, unibrow::Utf16::kNoPreviousCharacter, unibrow::Utf8::Length(), NULL, v8::internal::Isolate::objects_string_iterator(), v8::internal::StringCharacterStream::Reset(), v8::internal::ROBUST_STRING_TRAVERSAL, and v8::internal::Access< T >::value().

Referenced by v8::internal::Logger::ApiIndexedPropertyAccess(), v8::internal::Logger::ApiNamedPropertyAccess(), v8::internal::Logger::ApiObjectAccess(), v8::internal::Logger::CodeCreateEvent(), v8::internal::Logger::CodeDisableOptEvent(), v8::internal::StringsStorage::GetName(), v8::internal::Deoptimizer::GetOutputInfo(), v8::internal::HeapObject::HeapObjectShortPrint(), v8::internal::RegExpImpl::IrregexpExec(), and v8::internal::JavaScriptFrame::PrintFunctionAndOffset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ToCString() [2/2]

SmartArrayPointer< char > v8::internal::String::ToCString ( AllowNullsFlag  allow_nulls = DISALLOW_NULLS,
RobustnessFlag  robustness_flag = FAST_STRING_TRAVERSAL,
int length_output = 0 
)

Definition at line 8055 of file objects.cc.

8057  {
8058  return ToCString(allow_nulls, robust_flag, 0, -1, length_return);
8059 }
SmartArrayPointer< char > ToCString(AllowNullsFlag allow_nulls, RobustnessFlag robustness_flag, int offset, int length, int *length_output=0)
Definition: objects.cc:8004

◆ ToWideCString()

SmartArrayPointer< uc16 > v8::internal::String::ToWideCString ( RobustnessFlag  robustness_flag = FAST_STRING_TRAVERSAL)

Definition at line 8083 of file objects.cc.

8083  {
8084  if (robust_flag == ROBUST_STRING_TRAVERSAL && !LooksValid()) {
8085  return SmartArrayPointer<uc16>();
8086  }
8087  Heap* heap = GetHeap();
8088 
8089  Access<ConsStringIteratorOp> op(
8090  heap->isolate()->objects_string_iterator());
8091  StringCharacterStream stream(this, op.value());
8092 
8093  uc16* result = NewArray<uc16>(length() + 1);
8094 
8095  int i = 0;
8096  while (stream.HasMore()) {
8097  uint16_t character = stream.GetNext();
8098  result[i++] = character;
8099  }
8100  result[i] = 0;
8101  return SmartArrayPointer<uc16>(result);
8102 }

References v8::internal::HeapObject::GetHeap(), v8::internal::StringCharacterStream::GetNext(), v8::internal::StringCharacterStream::HasMore(), v8::internal::Heap::isolate(), v8::internal::Isolate::objects_string_iterator(), v8::internal::ROBUST_STRING_TRAVERSAL, and v8::internal::Access< T >::value().

+ Here is the call graph for this function:

◆ VisitFlat()

template<class Visitor >
ConsString * v8::internal::String::VisitFlat ( Visitor *  visitor,
String string,
int  offset = 0 
)
inlinestatic

Definition at line 3416 of file objects-inl.h.

3418  {
3419  int slice_offset = offset;
3420  const int length = string->length();
3421  DCHECK(offset <= length);
3422  while (true) {
3423  int32_t type = string->map()->instance_type();
3424  switch (type & (kStringRepresentationMask | kStringEncodingMask)) {
3426  visitor->VisitOneByteString(
3427  SeqOneByteString::cast(string)->GetChars() + slice_offset,
3428  length - offset);
3429  return NULL;
3430 
3432  visitor->VisitTwoByteString(
3433  SeqTwoByteString::cast(string)->GetChars() + slice_offset,
3434  length - offset);
3435  return NULL;
3436 
3438  visitor->VisitOneByteString(
3439  ExternalOneByteString::cast(string)->GetChars() + slice_offset,
3440  length - offset);
3441  return NULL;
3442 
3444  visitor->VisitTwoByteString(
3445  ExternalTwoByteString::cast(string)->GetChars() + slice_offset,
3446  length - offset);
3447  return NULL;
3448 
3451  SlicedString* slicedString = SlicedString::cast(string);
3452  slice_offset += slicedString->offset();
3453  string = slicedString->parent();
3454  continue;
3455  }
3456 
3459  return ConsString::cast(string);
3460 
3461  default:
3462  UNREACHABLE();
3463  return NULL;
3464  }
3465  }
3466 }
int int32_t
Definition: unicode.cc:24
const uint32_t kStringRepresentationMask
Definition: objects.h:561

References DCHECK, v8::internal::kConsStringTag, v8::internal::kExternalStringTag, v8::internal::kOneByteStringTag, v8::internal::kSeqStringTag, v8::internal::kSlicedStringTag, v8::internal::kStringEncodingMask, v8::internal::kStringRepresentationMask, v8::internal::kTwoByteStringTag, v8::internal::FixedArrayBase::length(), NULL, v8::internal::SlicedString::offset(), v8::internal::SlicedString::parent(), and UNREACHABLE.

Referenced by v8::internal::StringComparator::State::Advance(), v8::ContainsOnlyOneByteHelper::Check(), v8::ContainsOnlyOneByteHelper::CheckCons(), v8::internal::IteratingStringHasher::Hash(), v8::internal::StringCharacterStream::HasMore(), v8::internal::StringComparator::State::Init(), v8::RecursivelySerializeToUtf8(), v8::internal::StringCharacterStream::Reset(), v8::Utf8LengthHelper::Visitor::VisitFlat(), and v8::String::WriteUtf8().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WriteToFlat()

template<typename sinkchar >
void v8::internal::String::WriteToFlat ( String source,
sinkchar *  sink,
int  from,
int  to 
)
static

Definition at line 8370 of file objects.cc.

8373  {
8374  String* source = src;
8375  int from = f;
8376  int to = t;
8377  while (true) {
8378  DCHECK(0 <= from && from <= to && to <= source->length());
8379  switch (StringShape(source).full_representation_tag()) {
8381  CopyChars(sink, ExternalOneByteString::cast(source)->GetChars() + from,
8382  to - from);
8383  return;
8384  }
8386  const uc16* data =
8387  ExternalTwoByteString::cast(source)->GetChars();
8388  CopyChars(sink,
8389  data + from,
8390  to - from);
8391  return;
8392  }
8394  CopyChars(sink,
8395  SeqOneByteString::cast(source)->GetChars() + from,
8396  to - from);
8397  return;
8398  }
8400  CopyChars(sink,
8401  SeqTwoByteString::cast(source)->GetChars() + from,
8402  to - from);
8403  return;
8404  }
8407  ConsString* cons_string = ConsString::cast(source);
8408  String* first = cons_string->first();
8409  int boundary = first->length();
8410  if (to - boundary >= boundary - from) {
8411  // Right hand side is longer. Recurse over left.
8412  if (from < boundary) {
8413  WriteToFlat(first, sink, from, boundary);
8414  sink += boundary - from;
8415  from = 0;
8416  } else {
8417  from -= boundary;
8418  }
8419  to -= boundary;
8420  source = cons_string->second();
8421  } else {
8422  // Left hand side is longer. Recurse over right.
8423  if (to > boundary) {
8424  String* second = cons_string->second();
8425  // When repeatedly appending to a string, we get a cons string that
8426  // is unbalanced to the left, a list, essentially. We inline the
8427  // common case of sequential one-byte right child.
8428  if (to - boundary == 1) {
8429  sink[boundary - from] = static_cast<sinkchar>(second->Get(0));
8430  } else if (second->IsSeqOneByteString()) {
8431  CopyChars(sink + boundary - from,
8432  SeqOneByteString::cast(second)->GetChars(),
8433  to - boundary);
8434  } else {
8435  WriteToFlat(second,
8436  sink + boundary - from,
8437  0,
8438  to - boundary);
8439  }
8440  to = boundary;
8441  }
8442  source = first;
8443  }
8444  break;
8445  }
8448  SlicedString* slice = SlicedString::cast(source);
8449  unsigned offset = slice->offset();
8450  WriteToFlat(slice->parent(), sink, from + offset, to + offset);
8451  return;
8452  }
8453  }
8454  }
8455 }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
void CopyChars(sinkchar *dest, const sourcechar *src, int chars)
Definition: utils.h:1258

References v8::internal::CopyChars(), DCHECK, v8::internal::ConsString::first(), v8::internal::kConsStringTag, v8::internal::kExternalStringTag, v8::internal::kOneByteStringTag, v8::internal::kSeqStringTag, v8::internal::kSlicedStringTag, v8::internal::kTwoByteStringTag, length(), v8::internal::SlicedString::offset(), v8::internal::SlicedString::parent(), v8::internal::ConsString::second(), and to().

Referenced by v8::internal::CodeEventLogger::NameBuffer::AppendString(), v8::internal::ConcatStringContent(), v8::internal::ExternalizeStringExtension::Externalize(), MakeExternal(), v8::internal::RUNTIME_FUNCTION(), SlowFlatten(), v8::internal::StringBuilderConcatHelper(), v8::internal::StringReplaceGlobalAtomRegExpWithString(), v8::internal::StringReplaceGlobalRegExpWithEmptyString(), v8::WriteHelper(), v8::internal::WriteOneByteData(), and v8::internal::WriteTwoByteData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ Name

friend class Name
friend

Definition at line 8913 of file objects.h.

◆ StringTableInsertionKey

friend class StringTableInsertionKey
friend

Definition at line 8914 of file objects.h.

Member Data Documentation

◆ kArrayIndexLengthBits

const int v8::internal::String::kArrayIndexLengthBits
static
Initial value:
=
static const int kNofHashBitFields
Definition: objects.h:8496
static const int kArrayIndexValueBits
Definition: objects.h:8601
const int kBitsPerInt
Definition: globals.h:165

Definition at line 8602 of file objects.h.

◆ kArrayIndexValueBits

const int v8::internal::String::kArrayIndexValueBits = 24
static

Definition at line 8601 of file objects.h.

Referenced by v8::internal::StringHasher::MakeArrayIndexHash().

◆ kContainsCachedArrayIndexMask

const unsigned int v8::internal::String::kContainsCachedArrayIndexMask
static
Initial value:

Definition at line 8618 of file objects.h.

Referenced by v8::internal::StringHasher::MakeArrayIndexHash().

◆ kEmptyStringHash

const int v8::internal::String::kEmptyStringHash = kIsNotArrayIndexMask
static

Definition at line 8817 of file objects.h.

Referenced by v8::internal::Heap::CreateInitialObjects().

◆ kLengthOffset

◆ kMaxArrayIndexSize

◆ kMaxCachedArrayIndexLength

const int v8::internal::String::kMaxCachedArrayIndexLength = 7
static

Definition at line 8596 of file objects.h.

Referenced by v8::internal::StringHasher::MakeArrayIndexHash(), and SlowAsArrayIndex().

◆ kMaxHashCalcLength

const int v8::internal::String::kMaxHashCalcLength = 16383
static

◆ kMaxLength

◆ kMaxOneByteCharCode

◆ kMaxOneByteCharCodeU

◆ kMaxShortPrintLength

const int v8::internal::String::kMaxShortPrintLength = 1024
static

Definition at line 8827 of file objects.h.

Referenced by StringShortPrint().

◆ kMaxUtf16CodeUnit

◆ kMaxUtf16CodeUnitU

const uint32_t v8::internal::String::kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit
static

Definition at line 8814 of file objects.h.

◆ kSize

const int v8::internal::String::kSize = kLengthOffset + kPointerSize
static

Definition at line 8803 of file objects.h.


The documentation for this class was generated from the following files: