Chromium Code Reviews

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp

Issue 1389383003: WIP: Introduce CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bug fix Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
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 afb0dde5a7098e3586512891f6b6fafd91578856..a883765ef76e55ea5f520d7cd12cb14dd9f8dbe0 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8ValueCache.cpp
@@ -84,6 +84,27 @@ static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const Stri
return newString;
}
+static v8::Local<v8::String> makeExternalString(v8::Isolate* isolate, const CompressableString& string)
+{
+ if (string.is8Bit()) {
+ WebCoreCompressableStringResource8* stringResource = new WebCoreCompressableStringResource8(string);
+ v8::Local<v8::String> newString;
+ if (!v8::String::NewExternalOneByte(isolate, stringResource).ToLocal(&newString)) {
+ delete stringResource;
+ return v8::String::Empty(isolate);
+ }
+ return newString;
+ }
+
+ WebCoreCompressableStringResource16* stringResource = new WebCoreCompressableStringResource16(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())
@@ -99,6 +120,14 @@ v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, St
return createStringAndInsertIntoCache(isolate, stringImpl);
}
+v8::Local<v8::String> StringCache::v8ExternalStringSlow(v8::Isolate* isolate, const CompressableString& string)
+{
+ if (!string.length())
+ return v8::String::Empty(isolate);
+
+ return createStringAndInsertIntoCache(isolate, string);
+}
+
void StringCache::setReturnValueFromStringSlow(v8::ReturnValue<v8::Value> returnValue, StringImpl* stringImpl)
{
if (!stringImpl->length()) {
@@ -136,6 +165,26 @@ v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* i
return newString;
}
+v8::Local<v8::String> StringCache::createStringAndInsertIntoCache(v8::Isolate* isolate, const CompressableString& string)
+{
+ // ASSERT(!m_stringCache.Contains(stringImpl));
+ ASSERT(string.length());
+
+ v8::Local<v8::String> newString = makeExternalString(isolate, string);
+ ASSERT(!newString.IsEmpty());
+ ASSERT(newString->Length());
+
+ v8::UniquePersistent<v8::String> wrapper(isolate, newString);
+
+ // TODO(hajimehoshi): I'm not sure this ref is needed.
+ // string->ref();
haraken 2015/11/24 11:15:41 This ref is needed. If you don't have the ref, who
+ wrapper.MarkIndependent();
+ // m_stringCache.Set(stringImpl, wrapper.Pass(), &m_lastV8String);
haraken 2015/11/24 11:15:41 You need to put the CompressableString into the m_
hajimehoshi 2015/11/26 10:49:13 Hmm, I didn't know m_stringCache was the owner of
+ // m_lastStringImpl = stringImpl;
+
+ return newString;
+}
+
void StringCache::InvalidateLastString()
{
m_lastStringImpl = nullptr;

Powered by Google App Engine