Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index ddde388cd4f27c970c29e351333b06cd94b5c026..6d0eec8f2ca3ca29707a5137557c08a3c2a0ff59 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -1018,6 +1018,8 @@ class Boolean : public Primitive { |
*/ |
class String : public Primitive { |
public: |
+ static const int kExternalAsciiStringType = 0x06; |
+ static const int kExternalTwoByteStringType = 0x02; |
/** |
* Returns the number of characters in this string. |
*/ |
@@ -1181,6 +1183,15 @@ class String : public Primitive { |
}; |
/** |
+ * Get any type of external string resource. |
+ * Returns 0 if there is no external string and does not modify resource or |
+ * returns either kExternalAsciiStringType or kExternalTwoByteStringType and |
+ * sets the resource pointer. |
+ */ |
+ inline int GetExternalStringResourceBase( |
+ ExternalStringResourceBase*& resource) const; |
+ |
+ /** |
* Get the ExternalStringResource for an external string. Returns |
* NULL if IsExternal() doesn't return true. |
*/ |
@@ -1343,6 +1354,8 @@ class String : public Primitive { |
}; |
private: |
+ V8EXPORT void VerifyExternalStringResourceBase(ExternalStringResourceBase* v, |
+ int type) const; |
V8EXPORT void VerifyExternalStringResource(ExternalStringResource* val) const; |
V8EXPORT static void CheckCast(v8::Value* obj); |
}; |
@@ -4034,6 +4047,7 @@ class Internals { |
static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
static const int kFullStringRepresentationMask = 0x07; |
static const int kExternalTwoByteRepresentationTag = 0x02; |
+ static const int kExternalAsciiRepresentationTag = 0x06; |
static const int kIsolateStateOffset = 0; |
static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
@@ -4387,6 +4401,27 @@ String::ExternalStringResource* String::GetExternalStringResource() const { |
return result; |
} |
+int String::GetExternalStringResourceBase( |
+ String::ExternalStringResourceBase*& resource) 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; |
+ if (type == I::kExternalAsciiRepresentationTag |
+ || type == I::kExternalTwoByteRepresentationTag) { |
+ void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); |
+ resource = static_cast<String::ExternalStringResourceBase*>(value); |
+#ifdef V8_ENABLE_CHECKS |
+ VerifyExternalStringResourceBase(resource, type); |
+#endif |
+ return type; |
+ } else { |
+#ifdef V8_ENABLE_CHECKS |
+ VerifyExternalStringResourceBase(NULL, 0); |
+#endif |
+ return 0; |
+ } |
+} |
bool Value::IsUndefined() const { |
#ifdef V8_ENABLE_CHECKS |