[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.15.1-1414-gc69ee75
abarth at webkit.org
abarth at webkit.org
Thu Oct 29 20:48:31 UTC 2009
The following commit has been merged in the webkit-1.1 branch:
commit 1c18236b4310b142cbedb447bdf2763254373de8
Author: abarth at webkit.org <abarth at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Oct 20 05:01:32 2009 +0000
2009-10-19 James Robinson <jamesr at chromium.org>
Reviewed by Adam Barth.
Better implementation of WebCore::ScriptString for the V8 bindings.
https://bugs.webkit.org/show_bug.cgi?id=29909
WebCore::ScriptString is used for XMLHttpRequest's responseText attribute which is
shared with JavaScript. Thus, simply using a WebCore::String and copying the value
is pretty inefficient, especially since responseText is built up with a sequence of
operator+= calls. JSC builds use a JSC::UString to share the buffer when possible,
this patch adopts a similar approach for V8.
No new tests, behavior is unchanged and covered by LayoutTests/http/tests/xmlhttprequest
* WebCore.gypi:
* bindings/v8/ScriptString.h:
(WebCore::ScriptString::ScriptString):
(WebCore::ScriptString::operator String):
(WebCore::ScriptString::isNull):
(WebCore::ScriptString::size):
(WebCore::ScriptString::operator=):
(WebCore::ScriptString::operator+=):
(WebCore::ScriptString::v8StringOrNull):
* bindings/v8/ScriptStringImpl.cpp: Added.
(WebCore::ScriptStringImpl::ScriptStringImpl):
(WebCore::ScriptStringImpl::~ScriptStringImpl):
(WebCore::ScriptStringImpl::toString):
(WebCore::ScriptStringImpl::isNull):
(WebCore::ScriptStringImpl::size):
(WebCore::ScriptStringImpl::append):
* bindings/v8/ScriptStringImpl.h: Added.
(WebCore::ScriptStringImpl::ScriptStringImpl):
(WebCore::ScriptStringImpl::v8StringHandle):
* bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
(WebCore::ACCESSOR_GETTER):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49840 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 4aeb096..c5f5f52 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,41 @@
+2009-10-19 James Robinson <jamesr at chromium.org>
+
+ Reviewed by Adam Barth.
+
+ Better implementation of WebCore::ScriptString for the V8 bindings.
+
+ https://bugs.webkit.org/show_bug.cgi?id=29909
+
+ WebCore::ScriptString is used for XMLHttpRequest's responseText attribute which is
+ shared with JavaScript. Thus, simply using a WebCore::String and copying the value
+ is pretty inefficient, especially since responseText is built up with a sequence of
+ operator+= calls. JSC builds use a JSC::UString to share the buffer when possible,
+ this patch adopts a similar approach for V8.
+
+ No new tests, behavior is unchanged and covered by LayoutTests/http/tests/xmlhttprequest
+
+ * WebCore.gypi:
+ * bindings/v8/ScriptString.h:
+ (WebCore::ScriptString::ScriptString):
+ (WebCore::ScriptString::operator String):
+ (WebCore::ScriptString::isNull):
+ (WebCore::ScriptString::size):
+ (WebCore::ScriptString::operator=):
+ (WebCore::ScriptString::operator+=):
+ (WebCore::ScriptString::v8StringOrNull):
+ * bindings/v8/ScriptStringImpl.cpp: Added.
+ (WebCore::ScriptStringImpl::ScriptStringImpl):
+ (WebCore::ScriptStringImpl::~ScriptStringImpl):
+ (WebCore::ScriptStringImpl::toString):
+ (WebCore::ScriptStringImpl::isNull):
+ (WebCore::ScriptStringImpl::size):
+ (WebCore::ScriptStringImpl::append):
+ * bindings/v8/ScriptStringImpl.h: Added.
+ (WebCore::ScriptStringImpl::ScriptStringImpl):
+ (WebCore::ScriptStringImpl::v8StringHandle):
+ * bindings/v8/custom/V8XMLHttpRequestCustom.cpp:
+ (WebCore::ACCESSOR_GETTER):
+
2009-10-19 Adam Barth <abarth at webkit.org>
No review, rolling out r49837.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 91d8fc4..c0da0ec 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -771,6 +771,8 @@
'bindings/v8/ScriptState.h',
'bindings/v8/ScriptState.cpp',
'bindings/v8/ScriptString.h',
+ 'bindings/v8/ScriptStringImpl.cpp',
+ 'bindings/v8/ScriptStringImpl.h',
'bindings/v8/ScriptValue.cpp',
'bindings/v8/ScriptValue.h',
'bindings/v8/SerializedScriptValue.h',
diff --git a/WebCore/bindings/v8/ScriptString.h b/WebCore/bindings/v8/ScriptString.h
index fe254a5..b017a0c 100644
--- a/WebCore/bindings/v8/ScriptString.h
+++ b/WebCore/bindings/v8/ScriptString.h
@@ -32,34 +32,41 @@
#define ScriptString_h
#include "PlatformString.h"
+#include "ScriptStringImpl.h"
+#include "V8Binding.h"
namespace WebCore {
class ScriptString {
public:
- ScriptString() {}
- ScriptString(const String& s) : m_str(s) {}
- ScriptString(const char* s) : m_str(s) {}
+ ScriptString() : m_impl(0) {}
+ ScriptString(const String& s) : m_impl(new ScriptStringImpl(s)) {}
+ ScriptString(const char* s) : m_impl(new ScriptStringImpl(s)) {}
- operator String() const { return m_str; }
+ operator String() const { return m_impl->toString(); }
- bool isNull() const { return m_str.isNull(); }
- size_t size() const { return m_str.length(); }
+ bool isNull() const { return !m_impl.get() || m_impl->isNull(); }
+ size_t size() const { return m_impl->size(); }
ScriptString& operator=(const char* s)
{
- m_str = s;
+ m_impl = new ScriptStringImpl(s);
return *this;
}
ScriptString& operator+=(const String& s)
{
- m_str += s;
+ m_impl->append(s);
return *this;
}
+ v8::Handle<v8::Value> v8StringOrNull() const
+ {
+ return isNull() ? v8::Handle<v8::Value>(v8::Null()) : v8::Handle<v8::Value>(m_impl->v8StringHandle());
+ }
+
private:
- String m_str;
+ RefPtr<ScriptStringImpl> m_impl;
};
} // namespace WebCore
diff --git a/WebCore/bindings/v8/ScriptStringImpl.cpp b/WebCore/bindings/v8/ScriptStringImpl.cpp
new file mode 100644
index 0000000..afe74b1
--- /dev/null
+++ b/WebCore/bindings/v8/ScriptStringImpl.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008, 2009 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.
+ */
+
+#include "config.h"
+#include "ScriptStringImpl.h"
+
+#include "V8Binding.h"
+
+namespace WebCore {
+
+ScriptStringImpl::ScriptStringImpl(const String& s)
+{
+ v8::HandleScope scope;
+ m_handle.set(v8String(s));
+}
+
+ScriptStringImpl::ScriptStringImpl(const char* s)
+{
+ v8::HandleScope scope;
+ m_handle.set(v8::String::New(s));
+}
+
+String ScriptStringImpl::toString() const
+{
+ return v8StringToWebCoreString(m_handle.get());
+}
+
+bool ScriptStringImpl::isNull() const
+{
+ return m_handle.get().IsEmpty();
+}
+
+size_t ScriptStringImpl::size() const
+{
+ return m_handle.get()->Length();
+}
+
+void ScriptStringImpl::append(const String& s)
+{
+ v8::HandleScope scope;
+ if (m_handle.get().IsEmpty())
+ m_handle.set(v8String(s));
+ else
+ m_handle.set(v8::String::Concat(m_handle.get(), v8String(s)));
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/v8/ScriptStringImpl.h b/WebCore/bindings/v8/ScriptStringImpl.h
new file mode 100644
index 0000000..5faf0ba
--- /dev/null
+++ b/WebCore/bindings/v8/ScriptStringImpl.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2008, 2009 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 ScriptStringImpl_h
+#define ScriptStringImpl_h
+
+#include "OwnHandle.h"
+#include "PlatformString.h"
+
+#include <v8.h>
+
+namespace WebCore {
+
+// This class is used for strings that tend to be shared with JavaScript frequently. The JSC implementation uses wtf::UString - see bindings/js/ScriptString.h
+// Currently XMLHttpRequest uses a ScriptString to build up the responseText attribute. As data arrives from the network, it is appended to the ScriptString
+// via operator+= and a JavaScript readystatechange event is fired. JavaScript can access the responseText attribute of the XMLHttpRequest object. JavaScript
+// may also query the responseXML attribute of the XMLHttpRequest object which results in the responseText attribute being coerced into a WebCore::String and
+// then parsed as an XML document.
+// This implementation optimizes for the common case where the responseText is built up with many calls to operator+= before the actual text is queried.
+class ScriptStringImpl : public RefCounted<ScriptStringImpl> {
+public:
+ ScriptStringImpl() {}
+ ScriptStringImpl(const String& s);
+ ScriptStringImpl(const char* s);
+
+ String toString() const;
+
+ bool isNull() const;
+ size_t size() const;
+
+ void append(const String& s);
+
+ v8::Handle<v8::String> v8StringHandle() { return m_handle.get(); }
+
+private:
+ OwnHandle<v8::String> m_handle;
+};
+
+} // namespace WebCore
+
+#endif // ScriptStringImpl_h
diff --git a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
index 39105de..c3e4645 100644
--- a/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8XMLHttpRequestCustom.cpp
@@ -46,11 +46,9 @@ namespace WebCore {
ACCESSOR_GETTER(XMLHttpRequestResponseText)
{
- // FIXME: This is only needed because webkit set this getter as custom.
- // So we need a custom method to avoid forking the IDL file.
INC_STATS("DOM.XMLHttpRequest.responsetext._get");
XMLHttpRequest* xmlHttpRequest = V8DOMWrapper::convertToNativeObject<XMLHttpRequest>(V8ClassIndex::XMLHTTPREQUEST, info.Holder());
- return v8StringOrNull(xmlHttpRequest->responseText());
+ return xmlHttpRequest->responseText().v8StringOrNull();
}
CALLBACK_FUNC_DECL(XMLHttpRequestAddEventListener)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list