V8 Project
v8::String::Utf8Value Class Reference

Converts an object to a UTF-8-encoded character array. More...

#include <v8.h>

+ Collaboration diagram for v8::String::Utf8Value:

Public Member Functions

 Utf8Value (Handle< v8::Value > obj)
 
 ~Utf8Value ()
 
char * operator* ()
 
const char * operator* () const
 
int length () const
 

Private Member Functions

 Utf8Value (const Utf8Value &)
 
void operator= (const Utf8Value &)
 

Private Attributes

char * str_
 
int length_
 

Detailed Description

Converts an object to a UTF-8-encoded character array.

Useful if you want to print the object. If conversion to a string fails (e.g. due to an exception in the toString() method of the object) then the length() method returns 0 and the * operator returns NULL.

Definition at line 2048 of file v8.h.

Constructor & Destructor Documentation

◆ Utf8Value() [1/2]

v8::String::Utf8Value::Utf8Value ( Handle< v8::Value obj)
explicit

Definition at line 6841 of file api.cc.

6842  : str_(NULL), length_(0) {
6843  i::Isolate* isolate = i::Isolate::Current();
6844  if (obj.IsEmpty()) return;
6845  ENTER_V8(isolate);
6846  i::HandleScope scope(isolate);
6847  TryCatch try_catch;
6848  Handle<String> str = obj->ToString();
6849  if (str.IsEmpty()) return;
6851  length_ = v8::Utf8Length(*i_str, isolate);
6852  str_ = i::NewArray<char>(length_ + 1);
6853  str->WriteUtf8(str_);
6854 }
#define ENTER_V8(isolate)
Definition: api.cc:54
bool IsEmpty() const
Returns true if the handle is empty.
Definition: v8.h:228
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
Definition: api.h:288
Local< String > ToString() const
Definition: api.cc:2584
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
static int Utf8Length(i::String *str, i::Isolate *isolate)
Definition: api.cc:4549

References ENTER_V8, v8::Handle< T >::IsEmpty(), length_, v8::Utils::OpenHandle(), str_, v8::Value::ToString(), and v8::Utf8Length().

+ Here is the call graph for this function:

◆ ~Utf8Value()

v8::String::Utf8Value::~Utf8Value ( )

Definition at line 6857 of file api.cc.

6857  {
6859 }
void DeleteArray(T *array)
Definition: allocation.h:68

References v8::internal::DeleteArray().

+ Here is the call graph for this function:

◆ Utf8Value() [2/2]

v8::String::Utf8Value::Utf8Value ( const Utf8Value )
private

Member Function Documentation

◆ length()

int v8::String::Utf8Value::length ( ) const
inline

Definition at line 2054 of file v8.h.

2054 { return length_; }

Referenced by v8::Shell::ExecuteString(), v8::HandleDebugEvent(), v8::ExecArgs::Init(), v8::internal::BreakIterator::InitializeBreakIterator(), v8::internal::Collator::InitializeCollator(), v8::internal::DateFormat::InitializeDateTimeFormat(), v8::internal::NumberFormat::InitializeNumberFormat(), v8::Shell::ReportException(), and v8::Shell::Write().

+ Here is the caller graph for this function:

◆ operator*() [1/2]

char* v8::String::Utf8Value::operator* ( )
inline

Definition at line 2052 of file v8.h.

2052 { return str_; }

◆ operator*() [2/2]

const char* v8::String::Utf8Value::operator* ( ) const
inline

Definition at line 2053 of file v8.h.

2053 { return str_; }

◆ operator=()

void v8::String::Utf8Value::operator= ( const Utf8Value )
private

Member Data Documentation

◆ length_

int v8::String::Utf8Value::length_
private

Definition at line 2057 of file v8.h.

Referenced by Utf8Value().

◆ str_

char* v8::String::Utf8Value::str_
private

Definition at line 2056 of file v8.h.

Referenced by Utf8Value().


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