[v8] Convert string conversion calls to one byte versions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2013 11:59:19 +0000 (11:59 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 22 Jan 2013 11:59:19 +0000 (11:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107524

Patch by Dan Carney <dcarney@google.com> on 2013-01-22
Reviewed by Kentaro Hara.

No new tests. No change in functionality.

* bindings/v8/SerializedScriptValue.cpp:
* bindings/v8/V8StringResource.cpp:
(WebCore::WebCoreStringResourceBase::toWebCoreStringResourceBase):
(StringTraits):
(WebCore::true):
(WebCore::v8StringToWebCoreString):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@140409 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/SerializedScriptValue.cpp
Source/WebCore/bindings/v8/V8StringResource.cpp

index 553a5ef..8d741f9 100644 (file)
@@ -1,3 +1,19 @@
+2013-01-22  Dan Carney  <dcarney@google.com>
+
+        [v8] Convert string conversion calls to one byte versions
+        https://bugs.webkit.org/show_bug.cgi?id=107524
+
+        Reviewed by Kentaro Hara.
+
+        No new tests. No change in functionality.
+
+        * bindings/v8/SerializedScriptValue.cpp:
+        * bindings/v8/V8StringResource.cpp:
+        (WebCore::WebCoreStringResourceBase::toWebCoreStringResourceBase):
+        (StringTraits):
+        (WebCore::true):
+        (WebCore::v8StringToWebCoreString):
+
 2013-01-22  Eugene Klyuchnikov  <eustas@chromium.org>
 
         Web Inspector: [Network] CookiesTable refactoring.
index be54df0..8626d7b 100644 (file)
@@ -313,7 +313,7 @@ public:
         doWriteString(data, length);
     }
 
-    void writeAsciiString(v8::Handle<v8::String>& string)
+    void writeOneByteString(v8::Handle<v8::String>& string)
     {
         int length = string->Length();
         ASSERT(length >= 0);
@@ -322,8 +322,7 @@ public:
         doWriteUint32(static_cast<uint32_t>(length));
         ensureSpace(length);
 
-        char* buffer = reinterpret_cast<char*>(byteAt(m_position));
-        string->WriteAscii(buffer, 0, length, v8StringWriteOptions());
+        string->WriteOneByte(byteAt(m_position), 0, length, v8StringWriteOptions());
         m_position += length;
     }
 
@@ -666,7 +665,7 @@ private:
 
     int v8StringWriteOptions()
     {
-        return v8::String::NO_NULL_TERMINATION | v8::String::PRESERVE_ASCII_NULL;
+        return v8::String::NO_NULL_TERMINATION;
     }
 
     Vector<BufferValueType> m_buffer;
@@ -1048,8 +1047,8 @@ private:
     void writeString(v8::Handle<v8::Value> value)
     {
         v8::Handle<v8::String> string = value.As<v8::String>();
-        if (!string->Length() || !string->MayContainNonAscii())
-            m_writer.writeAsciiString(string);
+        if (!string->Length() || string->IsOneByte())
+            m_writer.writeOneByteString(string);
         else
             m_writer.writeUCharString(string);
     }
index 371391d..8ac6f0c 100644 (file)
@@ -37,7 +37,7 @@ WebCoreStringResourceBase* WebCoreStringResourceBase::toWebCoreStringResourceBas
     v8::String::ExternalStringResourceBase* resource = string->GetExternalStringResourceBase(&encoding);
     if (!resource)
         return 0;
-    if (encoding == v8::String::ASCII_ENCODING)
+    if (encoding == v8::String::ONE_BYTE_ENCODING)
         return static_cast<WebCoreStringResource8*>(resource);
     return static_cast<WebCoreStringResource16*>(resource);
 }
@@ -52,7 +52,7 @@ void WebCoreStringResourceBase::visitStrings(ExternalStringVisitor* visitor)
 template<class StringClass> struct StringTraits {
     static const StringClass& fromStringResource(WebCoreStringResourceBase*);
     static bool is16BitAtomicString(StringClass&);
-    template<bool ascii>
+    template<bool oneByte>
     static StringClass fromV8String(v8::Handle<v8::String>, int);
 };
 
@@ -66,7 +66,7 @@ struct StringTraits<String> {
     {
         return false;
     }
-    template<bool ascii>
+    template<bool oneByte>
     static String fromV8String(v8::Handle<v8::String>, int);
 };
 
@@ -80,7 +80,7 @@ struct StringTraits<AtomicString> {
     {
         return !string.string().is8Bit();
     }
-    template<bool ascii>
+    template<bool oneByte>
     static AtomicString fromV8String(v8::Handle<v8::String>, int);
 };
 
@@ -116,7 +116,7 @@ String StringTraits<String>::fromV8String<true>(v8::Handle<v8::String> v8String,
     ASSERT(v8String->Length() == length);
     LChar* buffer;
     String result = String::createUninitialized(length, buffer);
-    v8String->WriteAscii(reinterpret_cast<char*>(buffer), 0, length, v8::String::PRESERVE_ASCII_NULL);
+    v8String->WriteOneByte(buffer, 0, length);
     return result;
 }
 
@@ -127,12 +127,12 @@ AtomicString StringTraits<AtomicString>::fromV8String<true>(v8::Handle<v8::Strin
     static const int inlineBufferSize = 32;
     if (length <= inlineBufferSize) {
         LChar inlineBuffer[inlineBufferSize];
-        v8String->WriteAscii(reinterpret_cast<char*>(inlineBuffer), 0, length, v8::String::PRESERVE_ASCII_NULL);
+        v8String->WriteOneByte(inlineBuffer, 0, length);
         return AtomicString(inlineBuffer, length);
     }
     LChar* buffer;
     String string = String::createUninitialized(length, buffer);
-    v8String->WriteAscii(reinterpret_cast<char*>(buffer), 0, length, v8::String::PRESERVE_ASCII_NULL);
+    v8String->WriteOneByte(buffer, 0, length);
     return AtomicString(string);
 }
 
@@ -146,7 +146,7 @@ StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode
         v8::String::ExternalStringResourceBase* resource = v8String->GetExternalStringResourceBase(&encoding);
         if (LIKELY(!!resource)) {
             WebCoreStringResourceBase* base;
-            if (encoding == v8::String::ASCII_ENCODING)
+            if (encoding == v8::String::ONE_BYTE_ENCODING)
                 base = static_cast<WebCoreStringResource8*>(resource);
             else
                 base = static_cast<WebCoreStringResource16*>(resource);
@@ -158,13 +158,13 @@ StringType v8StringToWebCoreString(v8::Handle<v8::String> v8String, ExternalMode
     if (UNLIKELY(!length))
         return String("");
 
-    bool nonAscii = v8String->MayContainNonAscii();
-    StringType result(nonAscii ? StringTraits<StringType>::template fromV8String<false>(v8String, length) : StringTraits<StringType>::template fromV8String<true>(v8String, length));
+    bool oneByte = v8String->IsOneByte();
+    StringType result(oneByte ? StringTraits<StringType>::template fromV8String<true>(v8String, length) : StringTraits<StringType>::template fromV8String<false>(v8String, length));
 
     if (external != Externalize || !v8String->CanMakeExternal())
         return result;
 
-    if (!nonAscii && !StringTraits<StringType>::is16BitAtomicString(result)) {
+    if (oneByte && !StringTraits<StringType>::is16BitAtomicString(result)) {
         WebCoreStringResource8* stringResource = new WebCoreStringResource8(result);
         if (UNLIKELY(!v8String->MakeExternal(stringResource)))
             delete stringResource;