33 template <
typename Char,
typename Base>
43 virtual const Char*
data()
const {
return data_; }
45 virtual size_t length()
const {
return length_; }
53 typedef SimpleStringResource<char, v8::String::ExternalAsciiStringResource>
59 const char*
const ExternalizeStringExtension::kSource =
60 "native function externalizeString();"
61 "native function isAsciiString();";
79 if (args.
Length() < 1 || !args[0]->IsString()) {
82 "First parameter to externalizeString() must be a string."));
85 bool force_two_byte =
false;
87 if (args[1]->IsBoolean()) {
88 force_two_byte = args[1]->BooleanValue();
92 "Second parameter to externalizeString() must be a boolean."));
98 if (string->IsExternalString()) {
101 "externalizeString() can't externalize twice."));
104 if (string->IsOneByteRepresentation() && !force_two_byte) {
105 uint8_t* data =
new uint8_t[
string->length()];
108 reinterpret_cast<char*>(data), string->length());
109 result =
string->MakeExternal(resource);
114 if (!result)
delete resource;
116 uc16* data =
new uc16[
string->length()];
119 data, string->length());
120 result =
string->MakeExternal(resource);
125 if (!result)
delete resource;
129 args.
GetIsolate(),
"externalizeString() failed."));
137 if (args.
Length() != 1 || !args[0]->IsString()) {
140 "isAsciiString() requires a single string argument."));
V8_INLINE Isolate * GetIsolate() const
V8_INLINE ReturnValue< T > GetReturnValue() const
static void Externalize(const v8::FunctionCallbackInfo< v8::Value > &args)
void AddString(String *string)
virtual size_t length() const
V8_INLINE int Length() const
#define ASSERT(condition)
virtual const Char * data() const
SimpleStringResource(Char *data, size_t length)
static void IsAscii(const v8::FunctionCallbackInfo< v8::Value > &args)
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
virtual ~SimpleStringResource()
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< v8::String > name)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
ExternalStringTable * external_string_table()
SimpleStringResource< char, v8::String::ExternalAsciiStringResource > SimpleAsciiStringResource
SimpleStringResource< uc16, v8::String::ExternalStringResource > SimpleTwoByteStringResource
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)