2008-11-21 Darin Fisher <darin@chromium.org>
authordarin@chromium.org <darin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Nov 2008 00:11:28 +0000 (00:11 +0000)
committerdarin@chromium.org <darin@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 22 Nov 2008 00:11:28 +0000 (00:11 +0000)
        Reviewed by Geoffrey Garen.

        https://bugs.webkit.org/show_bug.cgi?id=22390
        Abstract away JSC:: usage in WebCore/xml

        * bindings/js/ScriptString.h: Added.
        (WebCore::ScriptString::ScriptString):
        (WebCore::ScriptString::operator JSC::UString):
        (WebCore::ScriptString::isNull):
        (WebCore::ScriptString::size):
        (WebCore::ScriptString::operator=):
        (WebCore::ScriptString::operator+=):
        * inspector/InspectorController.cpp:
        (WebCore::XMLHttpRequestResource::XMLHttpRequestResource):
        (WebCore::InspectorResource::setXMLHttpRequestProperties):
        (WebCore::InspectorController::resourceRetrievedByXMLHttpRequest):
        * inspector/InspectorController.h:
        * xml/XMLHttpRequest.cpp:
        (WebCore::XMLHttpRequest::responseText):
        (WebCore::XMLHttpRequest::clearResponse):
        (WebCore::XMLHttpRequest::dropProtection):
        (WebCore::XMLHttpRequest::didFinishLoading):
        (WebCore::XMLHttpRequest::didReceiveData):
        * xml/XMLHttpRequest.h:
        (WebCore::XMLHttpRequest::setLastSendURL):

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

WebCore/ChangeLog
WebCore/bindings/js/ScriptString.h [new file with mode: 0644]
WebCore/inspector/InspectorController.cpp
WebCore/inspector/InspectorController.h
WebCore/xml/XMLHttpRequest.cpp
WebCore/xml/XMLHttpRequest.h

index 98976494b3149e333b293a97528016940ce07099..4005bd03adb09b5acfa8120835d61da4027cd7f9 100644 (file)
@@ -1,3 +1,31 @@
+2008-11-21  Darin Fisher  <darin@chromium.org>
+
+        Reviewed by Geoffrey Garen.
+
+        https://bugs.webkit.org/show_bug.cgi?id=22390
+        Abstract away JSC:: usage in WebCore/xml
+
+        * bindings/js/ScriptString.h: Added.
+        (WebCore::ScriptString::ScriptString):
+        (WebCore::ScriptString::operator JSC::UString):
+        (WebCore::ScriptString::isNull):
+        (WebCore::ScriptString::size):
+        (WebCore::ScriptString::operator=):
+        (WebCore::ScriptString::operator+=):
+        * inspector/InspectorController.cpp:
+        (WebCore::XMLHttpRequestResource::XMLHttpRequestResource):
+        (WebCore::InspectorResource::setXMLHttpRequestProperties):
+        (WebCore::InspectorController::resourceRetrievedByXMLHttpRequest):
+        * inspector/InspectorController.h:
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::responseText):
+        (WebCore::XMLHttpRequest::clearResponse):
+        (WebCore::XMLHttpRequest::dropProtection):
+        (WebCore::XMLHttpRequest::didFinishLoading):
+        (WebCore::XMLHttpRequest::didReceiveData):
+        * xml/XMLHttpRequest.h:
+        (WebCore::XMLHttpRequest::setLastSendURL):
+
 2008-11-21  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Geoffrey Garen.
diff --git a/WebCore/bindings/js/ScriptString.h b/WebCore/bindings/js/ScriptString.h
new file mode 100644 (file)
index 0000000..b03bc9b
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2008, Google Inc.
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * 
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScriptString_h
+#define ScriptString_h
+
+#include <runtime/JSLock.h>
+#include <runtime/UString.h>
+
+namespace WebCore {
+
+class String;
+
+class ScriptString {
+public:
+    ScriptString(const char* s) : m_str(s) {}
+    ScriptString(const JSC::UString& s) : m_str(s) {}
+
+    operator JSC::UString() const { return m_str; }
+
+    bool isNull() const { return m_str.isNull(); }
+    size_t size() const { return m_str.size(); }
+
+    ScriptString& operator=(const char* s)
+    {
+        JSC::JSLock lock(false);
+        m_str = s;
+        return *this;
+    }
+
+    ScriptString& operator+=(const String& s)
+    {
+        JSC::JSLock lock(false);
+        m_str += s;
+        return *this;
+    }
+
+private:
+    JSC::UString m_str;
+};
+
+} // namespace WebCore
+
+#endif // ScriptString_h
index 1c8c18f5c43939eeb6f6f2f8d9050735e4be8ec7..84badb118bfc8c74ad641fb17351e763597eaad0 100644 (file)
@@ -217,7 +217,7 @@ struct ConsoleMessage {
 // XMLHttpRequestResource Class
 
 struct XMLHttpRequestResource {
-    XMLHttpRequestResource(JSC::UString& sourceString)
+    XMLHttpRequestResource(const JSC::UString& sourceString)
     {
         JSC::JSLock lock(false);
         this->sourceString = sourceString.rep();
@@ -302,7 +302,7 @@ struct InspectorResource : public RefCounted<InspectorResource> {
             JSValueProtect(context, newScriptObject);
     }
 
-    void setXMLHttpRequestProperties(JSC::UString& data)
+    void setXMLHttpRequestProperties(const JSC::UString& data)
     {
         xmlHttpRequestResource.set(new XMLHttpRequestResource(data));
     }
@@ -2498,7 +2498,7 @@ void InspectorController::didFailLoading(DocumentLoader* loader, unsigned long i
     }
 }
 
-void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, JSC::UString& sourceString)
+void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, const JSC::UString& sourceString)
 {
     if (!enabled())
         return;
index 62f3bdbae4f78919ded1a48844bfca6fa6f0edd8..f4d247272fd2f54056af7fd6b8402ca1cc23ba79 100644 (file)
@@ -203,7 +203,7 @@ public:
     void didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived);
     void didFinishLoading(DocumentLoader*, unsigned long identifier);
     void didFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&);
-    void resourceRetrievedByXMLHttpRequest(unsigned long identifier, JSC::UString& sourceString);
+    void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const JSC::UString& sourceString);
 
 #if ENABLE(DATABASE)
     void didOpenDatabase(Database*, const String& domain, const String& name, const String& version);
index 42a51f5aebcb7f5f9eda16b153f949e9e7d329b6..c796747dd310810d869c21031de4acfdc154b04c 100644 (file)
@@ -34,8 +34,6 @@
 #include "FrameLoader.h"
 #include "HTTPParsers.h"
 #include "InspectorController.h"
-#include "JSDOMBinding.h"
-#include "JSDOMWindow.h"
 #include "KURL.h"
 #include "KURLHash.h"
 #include "Page.h"
 #include "XMLHttpRequestProgressEvent.h"
 #include "XMLHttpRequestUpload.h"
 #include "markup.h"
-#include <runtime/JSLock.h>
 #include <wtf/StdLibExtras.h>
 
+#if USE(JSC)
+#include "JSDOMWindow.h"
+#endif
+
 namespace WebCore {
 
 typedef HashSet<String, CaseFoldingHash> HeadersSet;
@@ -206,7 +207,7 @@ XMLHttpRequest::State XMLHttpRequest::readyState() const
     return m_state;
 }
 
-const JSC::UString& XMLHttpRequest::responseText() const
+const ScriptString& XMLHttpRequest::responseText() const
 {
     return m_responseText;
 }
@@ -778,10 +779,7 @@ void XMLHttpRequest::internalAbort()
 void XMLHttpRequest::clearResponse()
 {
     m_response = ResourceResponse();
-    {
-        JSC::JSLock lock(false);
-        m_responseText = "";
-    }
+    m_responseText = "";
     m_createdDocument = false;
     m_responseXML = 0;
 }
@@ -826,6 +824,7 @@ void XMLHttpRequest::abortError()
 
 void XMLHttpRequest::dropProtection()        
 {
+#if USE(JSC)
     // The XHR object itself holds on to the responseText, and
     // thus has extra cost even independent of any
     // responseText or responseXML objects it has handed
@@ -837,6 +836,7 @@ void XMLHttpRequest::dropProtection()
         if (JSC::JSValue* wrapper = getCachedDOMObjectWrapper(*window->globalData(), this))
             JSC::Heap::heap(wrapper)->reportExtraMemoryCost(m_responseText.size() * 2);
     }
+#endif
 
     unsetPendingActivity(this);
 }
@@ -1052,11 +1052,8 @@ void XMLHttpRequest::didFinishLoading(SubresourceLoader* loader)
     if (m_state < HEADERS_RECEIVED)
         changeState(HEADERS_RECEIVED);
 
-    {
-        JSC::JSLock lock(false);
-        if (m_decoder)
-            m_responseText += m_decoder->flush();
-    }
+    if (m_decoder)
+        m_responseText += m_decoder->flush();
 
     if (Frame* frame = document()->frame()) {
         if (Page* page = frame->page()) {
@@ -1252,12 +1249,7 @@ void XMLHttpRequest::didReceiveData(SubresourceLoader*, const char* data, int le
     if (len == -1)
         len = strlen(data);
 
-    String decoded = m_decoder->decode(data, len);
-
-    {
-        JSC::JSLock lock(false);
-        m_responseText += decoded;
-    }
+    m_responseText += m_decoder->decode(data, len);
 
     if (!m_error) {
         updateAndDispatchOnProgress(len);
index 6962ab184374f366e94d8a4d107fa9ad34cd5e19..1946aa53be5eb4cd0223a4c11439809e737234bf 100644 (file)
@@ -27,6 +27,7 @@
 #include "FormData.h"
 #include "ResourceResponse.h"
 #include "SubresourceLoaderClient.h"
+#include "ScriptString.h"
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
@@ -71,10 +72,10 @@ public:
     void overrideMimeType(const String& override);
     String getAllResponseHeaders(ExceptionCode&) const;
     String getResponseHeader(const String& name, ExceptionCode&) const;
-    const JSC::UString& responseText() const;
+    const ScriptString& responseText() const;
     Document* responseXML() const;
     void setLastSendLineNumber(unsigned lineNumber) { m_lastSendLineNumber = lineNumber; }
-    void setLastSendURL(JSC::UString url) { m_lastSendURL = url; }
+    void setLastSendURL(const String& url) { m_lastSendURL = url; }
 
     XMLHttpRequestUpload* upload();
     XMLHttpRequestUpload* optionalUpload() const { return m_upload.get(); }
@@ -208,7 +209,7 @@ private:
     // to be able to share the buffer with JavaScript versions of the whole or partial string.
     // In contrast, this string doesn't interact much with the rest of the engine so it's not that
     // big a cost that it isn't a String.
-    JSC::UString m_responseText;
+    ScriptString m_responseText;
     mutable bool m_createdDocument;
     mutable RefPtr<Document> m_responseXML;
 
@@ -224,7 +225,7 @@ private:
     long long m_receivedLength;
     
     unsigned m_lastSendLineNumber;
-    JSC::UString m_lastSendURL;
+    String m_lastSendURL;
 };
 
 } // namespace WebCore