Index: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp |
index 9c902c2811dcd4401d5d6e5cb19832f297d71a21..a39f489d461df5b2b02387098d2ddb05ee2c0f6b 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp |
@@ -54,6 +54,29 @@ void StringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbac |
V8PerIsolateData::from(data.GetIsolate())->stringCache()->InvalidateLastString(); |
} |
+ |
+CompressibleStringCacheMapTraits::MapType* CompressibleStringCacheMapTraits::MapFromWeakCallbackInfo( |
+ const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
+{ |
+ return &(V8PerIsolateData::from(data.GetIsolate())->stringCache()->m_compressibleStringCache); |
+} |
+ |
+void CompressibleStringCacheMapTraits::Dispose( |
+ v8::Isolate* isolate, v8::Global<v8::String> value, CompressibleStringImpl* key) |
+{ |
+ key->deref(); |
+} |
+ |
+void CompressibleStringCacheMapTraits::DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
+{ |
+ data.GetParameter()->deref(); |
+} |
+ |
+void CompressibleStringCacheMapTraits::OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>& data) |
+{ |
+} |
+ |
+ |
void StringCache::dispose() |
{ |
// The MapType::Dispose callback calls StringCache::InvalidateLastString, |
@@ -83,6 +106,27 @@ static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri |
return newString; |
} |
+static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const CompressibleString& string) |
+{ |
+ if (string.is8Bit()) { |
+ WebCoreCompressibleStringResource8* stringResource = new WebCoreCompressibleStringResource8(string); |
+ v8::Local<v8::String> newString; |
+ if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&newString)) { |
+ delete stringResource; |
+ return v8::String::Empty(isolate); |
+ } |
+ return newString; |
+ } |
+ |
+ WebCoreCompressibleStringResource16* stringResource = new WebCoreCompressibleStringResource16(string); |
+ v8::Local<v8::String> newString; |
+ if (!v8::String::NewExternalTwoByte(isolate, stringResource).ToLocal(&newString)) { |
+ delete stringResource; |
+ return v8::String::Empty(isolate); |
+ } |
+ return newString; |
+} |
+ |
v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, StringImpl* stringImpl) |
{ |
if (!stringImpl->length()) |
@@ -98,6 +142,18 @@ v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St |
return createStringAndInsertIntoCache(isolate, stringImpl); |
} |
+v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, const CompressibleString& string) |
+{ |
+ if (!string.length()) |
+ return v8::String::Empty(isolate); |
+ |
+ CompressibleStringCacheMapTraits::MapType::PersistentValueReference cachedV8String = m_compressibleStringCache.GetReference(string.impl()); |
+ if (!cachedV8String.IsEmpty()) |
+ return cachedV8String.NewLocal(isolate); |
+ |
+ return createStringAndInsertIntoCache(isolate, string); |
+} |
+ |
void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> returnValue, StringImpl* stringImpl) |
{ |
if (!stringImpl->length()) { |
@@ -135,6 +191,31 @@ v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i |
return newString; |
} |
+v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* isolate, const CompressibleString& string) |
+{ |
+ CompressibleStringImpl* stringImpl = string.impl(); |
+ |
+ ASSERT(!m_compressibleStringCache.Contains(stringImpl)); |
+ ASSERT(stringImpl->originalLength()); |
+ |
+ v8::Local<v8::String> newString = makeExternalString(isolate, string); |
+ ASSERT(!newString.IsEmpty()); |
+ ASSERT(newString->Length()); |
+ |
+ v8::UniquePersistent<v8::String> wrapper(isolate, newString); |
+ |
+ stringImpl->ref(); |
+ wrapper.MarkIndependent(); |
+ // CompressibleStringImpl objects are NOT cached on |m_stringCache| or |
+ // |m_lastStringImpl|. It's because if even one objects holds a StringImpl |
+ // object in a CompressibleStringImpl, uncompressed string will exists even |
+ // when compressing the string. |
+ CompressibleStringCacheMapTraits::MapType::PersistentValueReference unused; |
+ m_compressibleStringCache.Set(stringImpl, wrapper.Pass(), &unused); |
+ |
+ return newString; |
+} |
+ |
void StringCache::InvalidateLastString() |
{ |
m_lastStringImpl = nullptr; |