V8 Project
|
A JavaScript string value (ECMA-262, 4.3.17). More...
#include <v8.h>
Classes | |
class | ExternalOneByteStringResource |
An ExternalOneByteStringResource is a wrapper around an one-byte string buffer that resides outside V8's heap. More... | |
class | ExternalStringResource |
An ExternalStringResource is a wrapper around a two-byte string buffer that resides outside V8's heap. More... | |
class | ExternalStringResourceBase |
class | Utf8Value |
Converts an object to a UTF-8-encoded character array. More... | |
class | Value |
Converts an object to a two-byte string. More... | |
Public Types | |
enum | Encoding { UNKNOWN_ENCODING = 0x1 , TWO_BYTE_ENCODING = 0x0 , ASCII_ENCODING = 0x4 , ONE_BYTE_ENCODING = 0x4 } |
enum | WriteOptions { NO_OPTIONS = 0 , HINT_MANY_WRITES_EXPECTED = 1 , NO_NULL_TERMINATION = 2 , PRESERVE_ASCII_NULL = 4 , PRESERVE_ONE_BYTE_NULL = 4 , REPLACE_INVALID_UTF8 = 8 } |
Write the contents of the string to an external buffer. More... | |
enum | NewStringType { kNormalString , kInternalizedString , kUndetectableString } |
typedef ExternalOneByteStringResource | ExternalAsciiStringResource |
Public Member Functions | |
int | Length () const |
Returns the number of characters in this string. More... | |
int | Utf8Length () const |
Returns the number of bytes in the UTF-8 encoded representation of this string. More... | |
bool | IsOneByte () const |
Returns whether this string is known to contain only one byte data. More... | |
bool | ContainsOnlyOneByte () const |
Returns whether this string contain only one byte data. More... | |
int | Write (uint16_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const |
int | WriteOneByte (uint8_t *buffer, int start=0, int length=-1, int options=NO_OPTIONS) const |
int | WriteUtf8 (char *buffer, int length=-1, int *nchars_ref=NULL, int options=NO_OPTIONS) const |
bool | IsExternal () const |
Returns true if the string is external. More... | |
bool | IsExternalOneByte () const |
Returns true if the string is both external and one-byte. More... | |
bool | IsExternalAscii () const |
ExternalStringResourceBase * | GetExternalStringResourceBase (Encoding *encoding_out) const |
If the string is an external string, return the ExternalStringResourceBase regardless of the encoding, otherwise return NULL. More... | |
ExternalStringResource * | GetExternalStringResource () const |
Get the ExternalStringResource for an external string. More... | |
const ExternalOneByteStringResource * | GetExternalOneByteStringResource () const |
Get the ExternalOneByteStringResource for an external one-byte string. More... | |
const ExternalAsciiStringResource * | GetExternalAsciiStringResource () const |
bool | MakeExternal (ExternalStringResource *resource) |
Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource. More... | |
bool | MakeExternal (ExternalOneByteStringResource *resource) |
Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource. More... | |
bool | CanMakeExternal () |
Returns true if this string can be made external. More... | |
![]() | |
bool | IsUndefined () const |
Returns true if this value is the undefined value. More... | |
bool | IsNull () const |
Returns true if this value is the null value. More... | |
bool | IsTrue () const |
Returns true if this value is true. More... | |
bool | IsFalse () const |
Returns true if this value is false. More... | |
bool | IsName () const |
Returns true if this value is a symbol or a string. More... | |
bool | IsString () const |
Returns true if this value is an instance of the String type. More... | |
bool | IsSymbol () const |
Returns true if this value is a symbol. More... | |
bool | IsFunction () const |
Returns true if this value is a function. More... | |
bool | IsArray () const |
Returns true if this value is an array. More... | |
bool | IsObject () const |
Returns true if this value is an object. More... | |
bool | IsBoolean () const |
Returns true if this value is boolean. More... | |
bool | IsNumber () const |
Returns true if this value is a number. More... | |
bool | IsExternal () const |
Returns true if this value is external. More... | |
bool | IsInt32 () const |
Returns true if this value is a 32-bit signed integer. More... | |
bool | IsUint32 () const |
Returns true if this value is a 32-bit unsigned integer. More... | |
bool | IsDate () const |
Returns true if this value is a Date. More... | |
bool | IsArgumentsObject () const |
Returns true if this value is an Arguments object. More... | |
bool | IsBooleanObject () const |
Returns true if this value is a Boolean object. More... | |
bool | IsNumberObject () const |
Returns true if this value is a Number object. More... | |
bool | IsStringObject () const |
Returns true if this value is a String object. More... | |
bool | IsSymbolObject () const |
Returns true if this value is a Symbol object. More... | |
bool | IsNativeError () const |
Returns true if this value is a NativeError. More... | |
bool | IsRegExp () const |
Returns true if this value is a RegExp. More... | |
bool | IsGeneratorFunction () const |
Returns true if this value is a Generator function. More... | |
bool | IsGeneratorObject () const |
Returns true if this value is a Generator object (iterator). More... | |
bool | IsPromise () const |
Returns true if this value is a Promise. More... | |
bool | IsMap () const |
Returns true if this value is a Map. More... | |
bool | IsSet () const |
Returns true if this value is a Set. More... | |
bool | IsWeakMap () const |
Returns true if this value is a WeakMap. More... | |
bool | IsWeakSet () const |
Returns true if this value is a WeakSet. More... | |
bool | IsArrayBuffer () const |
Returns true if this value is an ArrayBuffer. More... | |
bool | IsArrayBufferView () const |
Returns true if this value is an ArrayBufferView. More... | |
bool | IsTypedArray () const |
Returns true if this value is one of TypedArrays. More... | |
bool | IsUint8Array () const |
Returns true if this value is an Uint8Array. More... | |
bool | IsUint8ClampedArray () const |
Returns true if this value is an Uint8ClampedArray. More... | |
bool | IsInt8Array () const |
Returns true if this value is an Int8Array. More... | |
bool | IsUint16Array () const |
Returns true if this value is an Uint16Array. More... | |
bool | IsInt16Array () const |
Returns true if this value is an Int16Array. More... | |
bool | IsUint32Array () const |
Returns true if this value is an Uint32Array. More... | |
bool | IsInt32Array () const |
Returns true if this value is an Int32Array. More... | |
bool | IsFloat32Array () const |
Returns true if this value is a Float32Array. More... | |
bool | IsFloat64Array () const |
Returns true if this value is a Float64Array. More... | |
bool | IsDataView () const |
Returns true if this value is a DataView. More... | |
Local< Boolean > | ToBoolean () const |
Local< Number > | ToNumber () const |
Local< String > | ToString () const |
Local< String > | ToDetailString () const |
Local< Object > | ToObject () const |
Local< Integer > | ToInteger () const |
Local< Uint32 > | ToUint32 () const |
Local< Int32 > | ToInt32 () const |
Local< Uint32 > | ToArrayIndex () const |
Attempts to convert a string to an array index. More... | |
bool | BooleanValue () const |
double | NumberValue () const |
int64_t | IntegerValue () const |
uint32_t | Uint32Value () const |
int32_t | Int32Value () const |
bool | Equals (Handle< Value > that) const |
JS ==. More... | |
bool | StrictEquals (Handle< Value > that) const |
bool | SameValue (Handle< Value > that) const |
Static Public Member Functions | |
static v8::Local< v8::String > | Empty (Isolate *isolate) |
A zero length string. More... | |
static String * | Cast (v8::Value *obj) |
static Local< String > | NewFromUtf8 (Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1) |
Allocates a new string from UTF-8 data. More... | |
static Local< String > | NewFromOneByte (Isolate *isolate, const uint8_t *data, NewStringType type=kNormalString, int length=-1) |
Allocates a new string from Latin-1 data. More... | |
static Local< String > | NewFromTwoByte (Isolate *isolate, const uint16_t *data, NewStringType type=kNormalString, int length=-1) |
Allocates a new string from UTF-16 data. More... | |
static Local< String > | Concat (Handle< String > left, Handle< String > right) |
Creates a new string by concatenating the left and the right strings passed in as parameters. More... | |
static Local< String > | NewExternal (Isolate *isolate, ExternalStringResource *resource) |
Creates a new external string using the data defined in the given resource. More... | |
static Local< String > | NewExternal (Isolate *isolate, ExternalOneByteStringResource *resource) |
Creates a new external string using the one-byte data defined in the given resource. More... | |
![]() | |
static Name * | Cast (v8::Value *obj) |
![]() | |
template<class T > | |
static Value * | Cast (T *value) |
Private Member Functions | |
void | VerifyExternalStringResourceBase (ExternalStringResourceBase *v, Encoding encoding) const |
void | VerifyExternalStringResource (ExternalStringResource *val) const |
Static Private Member Functions | |
static void | CheckCast (v8::Value *obj) |
enum v8::String::Encoding |
Write the contents of the string to an external buffer.
If no arguments are given, expects the buffer to be large enough to hold the entire string and NULL terminator. Copies the contents of the string and the NULL terminator into the buffer.
WriteUtf8 will not write partial UTF-8 sequences, preferring to stop before the end of the buffer.
Copies up to length characters into the output buffer. Only null-terminates if there is enough space in the buffer.
buffer | The buffer into which the string will be copied. |
start | The starting position within the string at which copying begins. |
length | The number of characters to copy from the string. For WriteUtf8 the number of bytes in the buffer. |
nchars_ref | The number of characters written, can be NULL. |
options | Various options that might affect performance of this or subsequent operations. |
Enumerator | |
---|---|
NO_OPTIONS | |
HINT_MANY_WRITES_EXPECTED | |
NO_NULL_TERMINATION | |
PRESERVE_ASCII_NULL | |
PRESERVE_ONE_BYTE_NULL | |
REPLACE_INVALID_UTF8 |
Definition at line 1809 of file v8.h.
bool v8::String::CanMakeExternal | ( | ) |
Returns true if this string can be made external.
Definition at line 5597 of file api.cc.
References v8::internal::StringTracker::IsFreshUnusedString(), v8::internal::ExternalString::kShortSize, v8::Utils::OpenHandle(), size, and v8::internal::Isolate::string_tracker().
|
staticprivate |
Definition at line 2730 of file api.cc.
References v8::Utils::ApiCheck(), and v8::Utils::OpenHandle().
Creates a new string by concatenating the left and the right strings passed in as parameters.
Definition at line 5486 of file api.cc.
References ENTER_V8, v8::internal::Isolate::factory(), LOG_API, v8::Utils::OpenHandle(), and v8::Utils::ToLocal().
Referenced by v8::GetStdout(), and v8::Shell::ReadFromStdin().
bool v8::String::ContainsOnlyOneByte | ( | ) | const |
Returns whether this string contain only one byte data.
Will read the entire string in some cases.
Definition at line 4360 of file api.cc.
References v8::ContainsOnlyOneByteHelper::Check(), and v8::Utils::OpenHandle().
A zero length string.
Definition at line 6469 of file v8.h.
Referenced by v8::GetStdout(), and v8::anonymous_namespace{api.cc}::NewString().
|
inline |
Definition at line 1956 of file v8.h.
const v8::String::ExternalOneByteStringResource * v8::String::GetExternalOneByteStringResource | ( | ) | const |
Get the ExternalOneByteStringResource for an external one-byte string.
Returns NULL if IsExternalOneByte() doesn't return true.
Definition at line 4920 of file api.cc.
References v8::internal::Handle< T >::cast(), NULL, and v8::Utils::OpenHandle().
|
inline |
Get the ExternalStringResource for an external string.
Returns NULL if IsExternal() doesn't return true.
Definition at line 6478 of file v8.h.
|
inline |
If the string is an external string, return the ExternalStringResourceBase regardless of the encoding, otherwise return NULL.
The encoding of the string is returned in encoding_out.
Definition at line 6496 of file v8.h.
References I, v8::internal::kStringEncodingMask, and NULL.
bool v8::String::IsExternal | ( | ) | const |
Returns true if the string is external.
Definition at line 4869 of file api.cc.
References v8::Utils::OpenHandle().
|
inline |
Definition at line 1853 of file v8.h.
bool v8::String::IsExternalOneByte | ( | ) | const |
Returns true if the string is both external and one-byte.
Definition at line 4875 of file api.cc.
References v8::Utils::OpenHandle().
bool v8::String::IsOneByte | ( | ) | const |
Returns whether this string is known to contain only one byte data.
Does not read the string. False negatives are possible.
Definition at line 4245 of file api.cc.
References v8::Utils::OpenHandle().
int v8::String::Length | ( | ) | const |
Returns the number of characters in this string.
Definition at line 4239 of file api.cc.
References v8::Utils::OpenHandle().
bool v8::String::MakeExternal | ( | ExternalOneByteStringResource * | resource | ) |
Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource.
The external string resource's character contents need to be equivalent to this string. Returns true if the string has been changed to be an external string. The string is not modified if the operation fails. See NewExternal for information on the lifetime of the resource.
Definition at line 5570 of file api.cc.
References v8::internal::ExternalStringTable::AddString(), CHECK, v8::String::ExternalOneByteStringResource::data(), DCHECK, ENTER_V8, v8::internal::Heap::external_string_table(), v8::internal::Isolate::heap(), v8::internal::StringTracker::IsFreshUnusedString(), v8::internal::Heap::IsInGCPostProcessing(), v8::Utils::OpenHandle(), and v8::internal::Isolate::string_tracker().
bool v8::String::MakeExternal | ( | ExternalStringResource * | resource | ) |
Associate an external string resource with this string by transforming it in place so that existing references to this string in the JavaScript heap will use the external string resource.
The external string resource's character contents need to be equivalent to this string. Returns true if the string has been changed to be an external string. The string is not modified if the operation fails. See NewExternal for information on the lifetime of the resource.
Definition at line 5528 of file api.cc.
References v8::internal::ExternalStringTable::AddString(), CHECK, v8::String::ExternalStringResource::data(), DCHECK, ENTER_V8, v8::internal::Heap::external_string_table(), v8::internal::Isolate::heap(), v8::internal::StringTracker::IsFreshUnusedString(), v8::internal::Heap::IsInGCPostProcessing(), v8::Utils::OpenHandle(), and v8::internal::Isolate::string_tracker().
|
static |
Creates a new external string using the one-byte data defined in the given resource.
When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource.
Definition at line 5554 of file api.cc.
References v8::internal::ExternalStringTable::AddString(), CHECK, v8::String::ExternalOneByteStringResource::data(), ENTER_V8, EXCEPTION_BAILOUT_CHECK, EXCEPTION_PREAMBLE, v8::internal::Heap::external_string_table(), v8::internal::Isolate::heap(), LOG_API, v8::NewExternalOneByteStringHandle(), and v8::Utils::ToLocal().
|
static |
Creates a new external string using the data defined in the given resource.
When the external string is no longer live on V8's heap the resource will be disposed by calling its Dispose method. The caller of this function should not otherwise delete or modify the resource. Neither should the underlying buffer be deallocated or modified except through the destructor of the external string resource.
Definition at line 5511 of file api.cc.
References v8::internal::ExternalStringTable::AddString(), CHECK, v8::String::ExternalStringResource::data(), ENTER_V8, EXCEPTION_BAILOUT_CHECK, EXCEPTION_PREAMBLE, v8::internal::Heap::external_string_table(), v8::internal::Isolate::heap(), LOG_API, v8::NewExternalStringHandle(), and v8::Utils::ToLocal().
|
static |
Allocates a new string from Latin-1 data.
Definition at line 5460 of file api.cc.
References v8::anonymous_namespace{api.cc}::NewString().
|
static |
Allocates a new string from UTF-16 data.
Definition at line 5473 of file api.cc.
References v8::anonymous_namespace{api.cc}::NewString().
|
static |
Allocates a new string from UTF-8 data.
Definition at line 5447 of file api.cc.
References v8::anonymous_namespace{api.cc}::NewString().
Referenced by v8::internal::AddCounter(), v8::internal::AddNumber(), v8::internal::AddNumber64(), v8::Shell::AddOSMethods(), v8::Shell::ChangeDirectory(), v8::CheckItsADirectory(), v8::ChildLaunchedOK(), v8::ReadLineEditor::CompletionGenerator(), v8::Shell::CreateEvaluationContext(), v8::Shell::CreateGlobalTemplate(), v8::Shell::DebugCommandToJSONRequest(), v8::Shell::DebugMessageDetails(), v8::SourceGroup::Execute(), v8::Shell::ExecuteString(), v8::internal::ExternalizeStringExtension::Externalize(), v8::Shell::GetCompletions(), v8::GetStdout(), v8::GetTimeouts(), v8::GetWellKnownSymbol(), v8::HandleDebugEvent(), v8::ExecArgs::Init(), v8::Shell::InstallUtilityScript(), v8::internal::ExternalizeStringExtension::IsOneByte(), v8::Shell::Load(), main(), v8::Shell::MakeDirectory(), v8::mkdirp(), v8::Object::ObjectProtoToString(), v8::ReadLineEditor::Prompt(), v8::SourceGroup::ReadFile(), v8::Shell::ReadFile(), v8::Shell::ReadFromStdin(), v8::Shell::RemoveDirectory(), v8::Shell::RunShell(), v8::Template::Set(), v8::Shell::SetEnvironment(), v8::Shell::SetUMask(), v8::Shell::System(), v8::Throw(), v8::Shell::UnsetEnvironment(), v8::Shell::Version(), and v8::WaitForChild().
int v8::String::Utf8Length | ( | ) | const |
Returns the number of bytes in the UTF-8 encoded representation of this string.
Definition at line 4560 of file api.cc.
References v8::Utils::OpenHandle(), and v8::Utf8Length().
|
private |
Definition at line 4881 of file api.cc.
References v8::internal::Handle< T >::cast(), CHECK_EQ, NULL, and v8::Utils::OpenHandle().
|
private |
Definition at line 4895 of file api.cc.
References v8::internal::Handle< T >::cast(), CHECK_EQ, NULL, and v8::Utils::OpenHandle().
int v8::String::Write | ( | uint16_t * | buffer, |
int | start = 0 , |
||
int | length = -1 , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 4861 of file api.cc.
References v8::WriteHelper().
int v8::String::WriteOneByte | ( | uint8_t * | buffer, |
int | start = 0 , |
||
int | length = -1 , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 4853 of file api.cc.
References v8::WriteHelper().
int v8::String::WriteUtf8 | ( | char * | buffer, |
int | length = -1 , |
||
int * | nchars_ref = NULL , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 4772 of file api.cc.
References v8::Utf8WriterVisitor::CompleteWrite(), ENTER_V8, v8::internal::String::Flatten(), unibrow::Utf8::kMax16BitCodeUnitSize, LOG_API, NULL, v8::Utils::OpenHandle(), v8::RecursivelySerializeToUtf8(), v8::Utf8Length(), and v8::internal::String::VisitFlat().