2011-02-03 Jeremy Orlow <jorlow@chromium.org>
authorjorlow@chromium.org <jorlow@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 00:37:11 +0000 (00:37 +0000)
committerjorlow@chromium.org <jorlow@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 00:37:11 +0000 (00:37 +0000)
        Reviewed by Nate Chapin.

        SerializedScriptValue should not require v8 to create undefined and null values
        https://bugs.webkit.org/show_bug.cgi?id=53730

        Instead of creating a v8 type and passing that into the constructor, just use
        the writer class directly. While I was at it, I cleaned up the code a bit too
        by getting rid of the WireData/StringValue enum as I found that personally
        confusing.

        This is necessary because these methods are called by IndexedDB in the browser
        process where v8 is not spun up.

        No functionality changed and not possible to test.

        * bindings/v8/SerializedScriptValue.cpp:
        (WebCore::SerializedScriptValue::createFromWire):
        (WebCore::SerializedScriptValue::create):
        (WebCore::SerializedScriptValue::nullValue):
        (WebCore::SerializedScriptValue::undefinedValue):
        (WebCore::SerializedScriptValue::release):
        (WebCore::SerializedScriptValue::SerializedScriptValue):
        * bindings/v8/SerializedScriptValue.h:

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

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

index d7fda9a..4b1a298 100644 (file)
@@ -1,3 +1,29 @@
+2011-02-03  Jeremy Orlow  <jorlow@chromium.org>
+
+        Reviewed by Nate Chapin.
+
+        SerializedScriptValue should not require v8 to create undefined and null values
+        https://bugs.webkit.org/show_bug.cgi?id=53730
+
+        Instead of creating a v8 type and passing that into the constructor, just use
+        the writer class directly. While I was at it, I cleaned up the code a bit too
+        by getting rid of the WireData/StringValue enum as I found that personally
+        confusing.
+
+        This is necessary because these methods are called by IndexedDB in the browser
+        process where v8 is not spun up.
+
+        No functionality changed and not possible to test.
+
+        * bindings/v8/SerializedScriptValue.cpp:
+        (WebCore::SerializedScriptValue::createFromWire):
+        (WebCore::SerializedScriptValue::create):
+        (WebCore::SerializedScriptValue::nullValue):
+        (WebCore::SerializedScriptValue::undefinedValue):
+        (WebCore::SerializedScriptValue::release):
+        (WebCore::SerializedScriptValue::SerializedScriptValue):
+        * bindings/v8/SerializedScriptValue.h:
+
 2011-02-03  Beth Dakin  <bdakin@apple.com>
 
         Reviewed by Sam Weinig.
index 666e619..1c5e4e7 100644 (file)
@@ -1118,12 +1118,15 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(v8::Handle<v8::V
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::createFromWire(String data)
 {
-    return adoptRef(new SerializedScriptValue(data, WireData));
+    return adoptRef(new SerializedScriptValue(data));
 }
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create(String data)
 {
-    return adoptRef(new SerializedScriptValue(data, StringValue));
+    Writer writer;
+    writer.writeWebCoreString(data);
+    String wireData = StringImpl::adopt(writer.data());
+    return adoptRef(new SerializedScriptValue(wireData));
 }
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::create()
@@ -1133,19 +1136,31 @@ PassRefPtr<SerializedScriptValue> SerializedScriptValue::create()
 
 SerializedScriptValue* SerializedScriptValue::nullValue()
 {
-    DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, nullValue, (SerializedScriptValue::create()));
+    DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, nullValue, (0));
+    if (!nullValue) {
+        Writer writer;
+        writer.writeNull();
+        String wireData = StringImpl::adopt(writer.data());
+        nullValue = adoptRef(new SerializedScriptValue(wireData));
+    }
     return nullValue.get();
 }
 
 SerializedScriptValue* SerializedScriptValue::undefinedValue()
 {
-    DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, undefinedValue, (SerializedScriptValue::create(v8::Undefined())));
+    DEFINE_STATIC_LOCAL(RefPtr<SerializedScriptValue>, undefinedValue, (0));
+    if (!undefinedValue) {
+        Writer writer;
+        writer.writeUndefined();
+        String wireData = StringImpl::adopt(writer.data());
+        undefinedValue = adoptRef(new SerializedScriptValue(wireData));
+    }
     return undefinedValue.get();
 }
 
 PassRefPtr<SerializedScriptValue> SerializedScriptValue::release()
 {
-    RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data, WireData));
+    RefPtr<SerializedScriptValue> result = adoptRef(new SerializedScriptValue(m_data));
     m_data = String().crossThreadString();
     return result.release();
 }
@@ -1167,16 +1182,9 @@ SerializedScriptValue::SerializedScriptValue(v8::Handle<v8::Value> value, bool&
     m_data = String(StringImpl::adopt(writer.data())).crossThreadString();
 }
 
-SerializedScriptValue::SerializedScriptValue(String data, StringDataMode mode)
+SerializedScriptValue::SerializedScriptValue(String wireData)
 {
-    if (mode == WireData)
-        m_data = data.crossThreadString();
-    else {
-        ASSERT(mode == StringValue);
-        Writer writer;
-        writer.writeWebCoreString(data);
-        m_data = String(StringImpl::adopt(writer.data())).crossThreadString();
-    }
+    m_data = wireData.crossThreadString();
 }
 
 v8::Handle<v8::Value> SerializedScriptValue::deserialize()
index ead9511..d0d8575 100644 (file)
@@ -72,7 +72,7 @@ private:
 
     SerializedScriptValue();
     SerializedScriptValue(v8::Handle<v8::Value>, bool& didThrow);
-    SerializedScriptValue(String data, StringDataMode mode);
+    explicit SerializedScriptValue(String wireData);
 
     String m_data;
 };