Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Unified Diff: include/v8.h

Issue 153803003: Correctly recognize external strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index a019c9d561f92a00ece1efd263e5d0a0c1deb987..26f09d5a3899ce62d48ea8fe8f0b979f24667447 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1897,6 +1897,7 @@ class V8_EXPORT String : public Primitive {
void VerifyExternalStringResourceBase(ExternalStringResourceBase* v,
Encoding encoding) const;
void VerifyExternalStringResource(ExternalStringResource* val) const;
+ static internal::Object* GetRedirectedString(internal::Object* cons);
static void CheckCast(v8::Value* obj);
};
@@ -5388,9 +5389,12 @@ class Internals {
static const int kContextHeaderSize = 2 * kApiPointerSize;
static const int kContextEmbedderDataIndex = 65;
static const int kFullStringRepresentationMask = 0x07;
+ static const int kStringRepresentationMask = 0x03;
static const int kStringEncodingMask = 0x4;
+ static const int kConsTwoByteRepresentationTag = 0x01;
static const int kExternalTwoByteRepresentationTag = 0x02;
- static const int kExternalAsciiRepresentationTag = 0x06;
+ static const int kConsRepresentationTag = 0x01;
+ static const int kExternalRepresentationTag = 0x02;
static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
static const int kIsolateRootsOffset = 5 * kApiPointerSize;
@@ -5454,11 +5458,6 @@ class Internals {
return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
}
- V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
- int representation = (instance_type & kFullStringRepresentationMask);
- return representation == kExternalTwoByteRepresentationTag;
- }
-
V8_INLINE static uint8_t GetNodeFlag(internal::Object** obj, int shift) {
uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
return *addr & static_cast<uint8_t>(1U << shift);
@@ -5991,12 +5990,16 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
typedef internal::Object O;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(const_cast<String*>(this));
- String::ExternalStringResource* result;
- if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
+ String::ExternalStringResource* result = NULL;
+ int type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
+ // Resolve redirected string via cons string.
+ if (type == I::kConsTwoByteRepresentationTag) {
+ obj = GetRedirectedString(obj);
+ type = I::GetInstanceType(obj) & I::kFullStringRepresentationMask;
+ }
+ if (type == I::kExternalTwoByteRepresentationTag) {
void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value);
- } else {
- result = NULL;
}
#ifdef V8_ENABLE_CHECKS
VerifyExternalStringResource(result);
@@ -6010,11 +6013,16 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
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);
+ int instance_type = I::GetInstanceType(obj);
+ int string_type = instance_type & I::kStringRepresentationMask;
+ *encoding_out = static_cast<Encoding>(instance_type & I::kStringEncodingMask);
ExternalStringResourceBase* resource = NULL;
- if (type == I::kExternalAsciiRepresentationTag ||
- type == I::kExternalTwoByteRepresentationTag) {
+ // Resolve redirected string via cons string.
+ if (string_type == I::kConsRepresentationTag) {
+ obj = GetRedirectedString(obj);
+ string_type = I::GetInstanceType(obj) & I::kStringRepresentationMask;
+ }
+ if (string_type == I::kExternalRepresentationTag) {
void* value = I::ReadField<void*>(obj, I::kStringResourceOffset);
resource = static_cast<ExternalStringResourceBase*>(value);
}
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698