v8
3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
|
#include <v8.h>
Data Structures | |
class | AsciiValue |
class | ExternalAsciiStringResource |
class | ExternalStringResource |
class | ExternalStringResourceBase |
class | Utf8Value |
class | Value |
Public Types | |
enum | Encoding { UNKNOWN_ENCODING = 0x1, TWO_BYTE_ENCODING = 0x0, ASCII_ENCODING = 0x4 } |
enum | WriteOptions { NO_OPTIONS = 0, HINT_MANY_WRITES_EXPECTED = 1, NO_NULL_TERMINATION = 2, PRESERVE_ASCII_NULL = 4 } |
Static Public Member Functions | |
static V8EXPORT v8::Local < v8::String > | Empty () |
static v8::Local< v8::String > | Empty (Isolate *isolate) |
static String * | Cast (v8::Value *obj) |
static V8EXPORT Local< String > | New (const char *data, int length=-1) |
static V8EXPORT Local< String > | New (const uint16_t *data, int length=-1) |
static V8EXPORT Local< String > | NewSymbol (const char *data, int length=-1) |
static V8EXPORT Local< String > | Concat (Handle< String > left, Handle< String > right) |
static V8EXPORT Local< String > | NewExternal (ExternalStringResource *resource) |
static V8EXPORT Local< String > | NewExternal (ExternalAsciiStringResource *resource) |
static V8EXPORT Local< String > | NewUndetectable (const char *data, int length=-1) |
static V8EXPORT Local< String > | NewUndetectable (const uint16_t *data, int length=-1) |
enum Encoding |
enum WriteOptions |
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 |
bool CanMakeExternal | ( | ) |
Returns true if this string can be made external.
Definition at line 4944 of file api.cc.
References StringTracker::IsFreshUnusedString(), ExternalString::kShortSize, and Isolate::string_tracker().
Definition at line 4417 of file v8.h.
Referenced by ReadLine(), and TEST().
Creates a new string by concatenating the left and the right strings passed in as parameters.
Definition at line 4793 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewConsString(), and Utils::ToLocal().
Referenced by Shell::ReadFromStdin().
A zero length string.
Definition at line 4769 of file api.cc.
References Isolate::factory(), LOG_API, and Utils::ToLocal().
Referenced by String::Empty(), and TEST().
Definition at line 4425 of file v8.h.
References String::Empty(), I, and S.
const v8::String::ExternalAsciiStringResource * GetExternalAsciiStringResource | ( | ) | const |
Get the ExternalAsciiStringResource for an external ASCII string. Returns NULL if IsExternalAscii() doesn't return true.
Definition at line 4122 of file api.cc.
References Handle< T >::cast(), and NULL.
|
inline |
Get the ExternalStringResource for an external string. Returns NULL if IsExternal() doesn't return true.
|
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 4452 of file v8.h.
References I, v8::internal::kStringEncodingMask, and NULL.
bool IsExternal | ( | ) | const |
Returns true if the string is external
Definition at line 4064 of file api.cc.
Referenced by TEST(), and VisitorImpl::VisitExternalString().
bool IsExternalAscii | ( | ) | const |
Returns true if the string is both external and ASCII
Definition at line 4074 of file api.cc.
Referenced by VisitorImpl::VisitExternalString().
int Length | ( | ) | const |
Returns the number of characters in this string.
Definition at line 3741 of file api.cc.
Referenced by Object::ObjectProtoToString(), and TEST().
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. 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 4884 of file api.cc.
References ExternalStringTable::AddString(), CHECK, String::ExternalStringResource::data(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), StringTracker::IsFreshUnusedString(), Heap::IsInGCPostProcessing(), and Isolate::string_tracker().
bool MakeExternal | ( | ExternalAsciiStringResource * | 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 4920 of file api.cc.
References ExternalStringTable::AddString(), CHECK, String::ExternalAsciiStringResource::data(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), StringTracker::IsFreshUnusedString(), Heap::IsInGCPostProcessing(), and Isolate::string_tracker().
bool MayContainNonAscii | ( | ) | const |
Allocates a new string from either UTF-8 encoded or ASCII data. The second parameter 'length' gives the buffer length. If the data is UTF-8 encoded, the caller must be careful to supply the length parameter. If it is not given, the function calls 'strlen' to determine the buffer length, it might be wrong if 'data' contains a null character.
Definition at line 4779 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromUtf8(), v8::internal::StrLength(), and Utils::ToLocal().
Referenced by Shell::AddOSMethods(), Shell::ArrayBuffer(), Shell::ArrayBufferSlice(), Shell::ArraySet(), Shell::ArraySubArray(), Shell::ChangeDirectory(), Shell::CreateEvaluationContext(), CreateGlobalTemplate(), CreateShellContext(), DEPENDENT_TEST(), DoLoop(), DoLoopNoCall(), SourceGroup::Execute(), ExternalizeStringExtension::Externalize(), Shell::GetCompletions(), ProfilerExtension::GetNativeFunction(), ExecArgs::Init(), ExternalizeStringExtension::IsAscii(), Load(), Shell::Load(), Loop(), LoopGetProperty(), main(), Shell::MakeDirectory(), Object::ObjectProtoToString(), ReadLineEditor::Prompt(), Read(), Shell::Read(), Shell::ReadBuffer(), ReadFile(), Shell::ReadFile(), Shell::ReadFromStdin(), ReadLine(), ReenterAfterTermination(), Shell::RemoveDirectory(), ThreadA::Run(), LoopingThread::Run(), ShellThread::Run(), RunCppCycle(), RunMain(), RunShell(), Template::Set(), Shell::SetEnvironment(), Shell::SetUMask(), ProfilerExtension::StartProfiling(), ProfilerExtension::StopProfiling(), Shell::System(), TerminateOrReturnObject(), TEST(), THREADED_TEST(), Shell::UnsetEnvironment(), Version(), and Shell::Version().
Allocates a new string from 16-bit character codes.
Definition at line 4827 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromTwoByte(), and 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 4871 of file api.cc.
References ExternalStringTable::AddString(), CHECK, String::ExternalStringResource::data(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), LOG_API, v8::NewExternalStringHandle(), and Utils::ToLocal().
Referenced by TEST().
|
static |
Creates a new external string using the ASCII 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 4907 of file api.cc.
References ExternalStringTable::AddString(), CHECK, String::ExternalAsciiStringResource::data(), ENTER_V8, Heap::external_string_table(), Isolate::heap(), LOG_API, v8::NewExternalAsciiStringHandle(), and Utils::ToLocal().
Creates a symbol. Returns one if it exists already.
Definition at line 5203 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::LookupSymbol(), v8::internal::StrLength(), and Utils::ToLocal().
Referenced by THREADED_TEST().
Creates an undetectable string from the supplied ASCII or UTF-8 data.
Definition at line 4806 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromUtf8(), v8::internal::StrLength(), and Utils::ToLocal().
Creates an undetectable string from the supplied 16-bit character codes.
Definition at line 4841 of file api.cc.
References ENTER_V8, Isolate::factory(), LOG_API, Factory::NewStringFromTwoByte(), and Utils::ToLocal().
int Utf8Length | ( | ) | const |
Returns the number of bytes in the UTF-8 encoded representation of this string.
Definition at line 3748 of file api.cc.
References v8::internal::Utf8Length().
int Write | ( | uint16_t * | buffer, |
int | start = 0 , |
||
int | length = -1 , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 4035 of file api.cc.
References ASSERT, ENTER_V8, v8::internal::FlattenString(), String::HINT_MANY_WRITES_EXPECTED, LOG_API, String::NO_NULL_TERMINATION, StringTracker::RecordWrite(), Isolate::string_tracker(), and String::WriteToFlat().
int WriteAscii | ( | char * | buffer, |
int | start = 0 , |
||
int | length = -1 , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 3984 of file api.cc.
References ASSERT, ENTER_V8, v8::internal::FlattenString(), CharacterStream::GetNext(), String::HINT_MANY_WRITES_EXPECTED, LOG_API, String::NO_NULL_TERMINATION, String::PRESERVE_ASCII_NULL, StringTracker::RecordWrite(), InputBuffer< Reader, Input, kSize >::Reset(), Isolate::string_tracker(), Isolate::write_input_buffer(), and String::WriteToFlat().
Referenced by Object::ObjectProtoToString(), and TEST().
int WriteUtf8 | ( | char * | buffer, |
int | length = -1 , |
||
int * | nchars_ref = NULL , |
||
int | options = NO_OPTIONS |
||
) | const |
Definition at line 3852 of file api.cc.
References ASSERT, Utf8::Encode(), ENTER_V8, v8::internal::FlattenString(), CharacterStream::GetNext(), String::HINT_MANY_WRITES_EXPECTED, Utf16::IsLeadSurrogate(), Utf16::IsTrailSurrogate(), Utf8::kMaxEncodedSize, Utf16::kNoPreviousCharacter, LOG_API, String::NO_NULL_TERMINATION, NULL, StringTracker::RecordWrite(), InputBuffer< Reader, Input, kSize >::Reset(), Isolate::string_tracker(), v8::internal::Utf8Length(), Isolate::write_input_buffer(), and String::WriteToFlat().