Chromium Code Reviews| Index: include/v8.h |
| diff --git a/include/v8.h b/include/v8.h |
| index ddde388cd4f27c970c29e351333b06cd94b5c026..37d66586aa08f0aea782f8152bc9639e4bef4de8 100644 |
| --- a/include/v8.h |
| +++ b/include/v8.h |
| @@ -1018,6 +1018,11 @@ class Boolean : public Primitive { |
| */ |
| class String : public Primitive { |
| public: |
| + enum Encoding { |
| + UNKNOWN_ENCODING = 0x1, |
| + TWO_BYTE_ENCODING = 0x0, |
| + ASCII_ENCODING = 0x4 |
| + }; |
| /** |
| * Returns the number of characters in this string. |
| */ |
| @@ -1181,6 +1186,14 @@ class String : public Primitive { |
| }; |
| /** |
| + * 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 type_out. |
| + */ |
| + inline ExternalStringResourceBase* GetExternalStringResourceBase( |
| + Encoding* encoding_out) const; |
| + |
| + /** |
| * Get the ExternalStringResource for an external string. Returns |
| * NULL if IsExternal() doesn't return true. |
| */ |
| @@ -1226,6 +1239,8 @@ class String : public Primitive { |
| * 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. |
| + * The optional encoding argument provides a hint on whether scanning for |
| + * ASCII content is necessary. |
|
drcarney
2012/09/12 11:27:09
Looks like this comment accidentally slipped in.
Yang
2012/09/12 11:28:50
Done.
|
| */ |
| V8EXPORT static Local<String> NewExternal(ExternalStringResource* resource); |
| @@ -1343,6 +1358,8 @@ class String : public Primitive { |
| }; |
| private: |
| + V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
| + Encoding encoding_out) const; |
| V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
| V8EXPORT static void CheckCast(v8::Value* obj); |
| }; |
| @@ -4033,7 +4050,9 @@ class Internals { |
| static const int kForeignAddressOffset = kApiPointerSize; |
| static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
| static const int kFullStringRepresentationMask = 0x07; |
| + static const int kStringEncodingMask = 0x4; |
| static const int kExternalTwoByteRepresentationTag = 0x02; |
| + static const int kExternalAsciiRepresentationTag = 0x06; |
| static const int kIsolateStateOffset = 0; |
| static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| @@ -4388,6 +4407,26 @@ String::ExternalStringResource* String::GetExternalStringResource() const { |
| } |
| +String::ExternalStringResourceBase* String::GetExternalStringResourceBase( |
| + String::Encoding* encoding_out) const { |
| + typedef internal::Object O; |
| + typedef internal::Internals I; |
| + O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); |
| + int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask; |
| + *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); |
| + ExternalStringResourceBase* resource = NULL; |
| + if (type == I::kExternalAsciiRepresentationTag || |
| + type == I::kExternalTwoByteRepresentationTag) { |
| + void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
| + resource = static_cast<ExternalStringResourceBase*>(value); |
| + } |
| +#ifdef V8_ENABLE_CHECKS |
| + VerifyExternalStringResourceBase(resource, *encoding_out); |
| +#endif |
| + return resource; |
| +} |
| + |
| + |
| bool Value::IsUndefined() const { |
| #ifdef V8_ENABLE_CHECKS |
| return FullIsUndefined(); |