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();";
77 if (args.
Length() < 1 || !args[0]->IsString()) {
79 "First parameter to externalizeString() must be a string."));
81 bool force_two_byte =
false;
83 if (args[1]->IsBoolean()) {
84 force_two_byte = args[1]->BooleanValue();
87 "Second parameter to externalizeString() must be a boolean."));
92 if (string->IsExternalString()) {
94 "externalizeString() can't externalize twice."));
96 if (string->IsAsciiRepresentation() && !force_two_byte) {
97 char* data =
new char[
string->length()];
100 data, string->length());
101 result =
string->MakeExternal(resource);
102 if (result && !string->IsSymbol()) {
103 HEAP->external_string_table()->AddString(*
string);
105 if (!result)
delete resource;
107 uc16* data =
new uc16[
string->length()];
110 data, string->length());
111 result =
string->MakeExternal(resource);
112 if (result && !string->IsSymbol()) {
113 HEAP->external_string_table()->AddString(*
string);
115 if (!result)
delete resource;
126 if (args.
Length() != 1 || !args[0]->IsString()) {
128 "isAsciiString() requires a single string argument."));
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
static v8::Handle< v8::Value > Externalize(const v8::Arguments &args)
Handle< Boolean > V8EXPORT True()
static V8EXPORT Local< String > New(const char *data, int length=-1)
virtual size_t length() const
#define ASSERT(condition)
virtual const Char * data() const
SimpleStringResource(Char *data, size_t length)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< v8::String > name)
virtual ~SimpleStringResource()
Handle< Boolean > V8EXPORT False()
static v8::Handle< v8::Value > IsAscii(const v8::Arguments &args)
static void WriteToFlat(String *source, sinkchar *sink, int from, int to)
SimpleStringResource< char, v8::String::ExternalAsciiStringResource > SimpleAsciiStringResource
Handle< Primitive > V8EXPORT Undefined()
Handle< Value > V8EXPORT ThrowException(Handle< Value > exception)
SimpleStringResource< uc16, v8::String::ExternalStringResource > SimpleTwoByteStringResource
static v8::internal::Handle< v8::internal::TemplateInfo > OpenHandle(const Template *that)