Diff
Modified: trunk/Source/WebCore/ChangeLog (200299 => 200300)
--- trunk/Source/WebCore/ChangeLog 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/ChangeLog 2016-05-01 04:50:10 UTC (rev 200300)
@@ -1,5 +1,57 @@
2016-04-30 Darin Adler <[email protected]>
+ Update XMLHttpRequest to use enum class instead of string for enumeration
+ https://bugs.webkit.org/show_bug.cgi?id=157238
+
+ Reviewed by Chris Dumez.
+
+ * bindings/js/JSXMLHttpRequestCustom.cpp:
+ (WebCore::JSXMLHttpRequest::response): Rewrite to use responseType function
+ instead of responseTypeCode function.
+
+ * bindings/scripts/CodeGenerator.pm: Removed XMLHttpRequestResponseType
+ from the list of enumerations that use a string-based implementation.
+
+ * bindings/scripts/CodeGeneratorJS.pm:
+ (GetEnumerationImplementationContent): Use emptyString instead of ASCIILiteral
+ when the string constant is empty, to avoid the assertion.
+
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::XMLHttpRequest): Move simple scalar data member
+ initialization to where the data members are defined in the header.
+ (WebCore::XMLHttpRequest::responseText): Use m_responseType instead of
+ m_responseTypeCode.
+ (WebCore::XMLHttpRequest::didCacheResponseJSON): Ditto.
+ (WebCore::XMLHttpRequest::responseXML): Ditto.
+ (WebCore::XMLHttpRequest::responseBlob): Ditto.
+ (WebCore::XMLHttpRequest::responseArrayBuffer): Ditto.
+ (WebCore::XMLHttpRequest::setResponseType): Ditto.
+ (WebCore::XMLHttpRequest::responseType): Moved to header now that it's a
+ trivial function that should be inlined.
+ (WebCore::XMLHttpRequest::open): Use m_responseType instead of
+ m_responseTypeCode.
+ (WebCore::XMLHttpRequest::responseMIMEType): Removed one redundant check.
+ (WebCore::XMLHttpRequest::status): Ditto.
+ (WebCore::XMLHttpRequest::statusText): Ditto.
+ (WebCore::shouldDecodeResponse): Moved here from the header. This is now
+ a non-member function that gets passed a response type. It uses a switch
+ now instead of ordering the types so that the binary ones are all at the
+ end of the list.
+ (WebCore::XMLHttpRequest::didReceiveData): Use the new shouldDecodeResponse.
+ Also removed an unnecessary check that non-decoded responses are of type
+ "arraybuffer" or "blob"; that's the same check that shouldDecodeResponse does.
+
+ * xml/XMLHttpRequest.h: Removed some unneeded includes and forward declarations.
+ Removed a comment about the State values needing to be stable numbers; for one
+ thing the bindings already check that these values have no changed. It's not a
+ valuable comment. Removed ResponseTypeCode, responseTypeCode, and
+ m_responseTypeCode. Changed the type of the result of responseType and the
+ argument to setResponseType from a string to XMLHttpRequestResponseType.
+ Removed shouldDecodeResponse. Added the initial values for lots of data members
+ that are simple scalars, matching what was set in the constructor before.
+
+2016-04-30 Darin Adler <[email protected]>
+
Streamline and remove unused bindings generation code
https://bugs.webkit.org/show_bug.cgi?id=157237
Modified: trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp (200299 => 200300)
--- trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp 2016-05-01 04:50:10 UTC (rev 200300)
@@ -186,27 +186,36 @@
if (m_response && wrapped().responseCacheIsValid())
return m_response.get();
- if (!wrapped().doneWithoutErrors() && wrapped().responseTypeCode() > XMLHttpRequest::ResponseTypeText)
- return jsNull();
+ auto type = wrapped().responseType();
- switch (wrapped().responseTypeCode()) {
- case XMLHttpRequest::ResponseTypeDefault:
- case XMLHttpRequest::ResponseTypeText:
+ switch (type) {
+ case XMLHttpRequestResponseType::EmptyString:
+ case XMLHttpRequestResponseType::Text:
return responseText(state);
+ default:
+ break;
+ }
- case XMLHttpRequest::ResponseTypeJSON:
+ if (!wrapped().doneWithoutErrors())
+ return jsNull();
+
+ switch (type) {
+ case XMLHttpRequestResponseType::EmptyString:
+ case XMLHttpRequestResponseType::Text:
+ ASSERT_NOT_REACHED();
+ break;
+
+ case XMLHttpRequestResponseType::Json:
{
JSValue value = JSONParse(&state, wrapped().responseTextIgnoringResponseType());
if (!value)
value = jsNull();
m_response.set(state.vm(), this, value);
-
wrapped().didCacheResponseJSON();
-
return value;
}
- case XMLHttpRequest::ResponseTypeDocument:
+ case XMLHttpRequestResponseType::Document:
{
ExceptionCode ec = 0;
Document* document = wrapped().responseXML(ec);
@@ -217,13 +226,14 @@
return toJS(&state, globalObject(), document);
}
- case XMLHttpRequest::ResponseTypeBlob:
+ case XMLHttpRequestResponseType::Blob:
return toJS(&state, globalObject(), wrapped().responseBlob());
- case XMLHttpRequest::ResponseTypeArrayBuffer:
+ case XMLHttpRequestResponseType::Arraybuffer:
return toJS(&state, globalObject(), wrapped().responseArrayBuffer());
}
+ ASSERT_NOT_REACHED();
return jsUndefined();
}
Modified: trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm (200299 => 200300)
--- trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/bindings/scripts/CodeGenerator.pm 2016-05-01 04:50:10 UTC (rev 200300)
@@ -144,7 +144,6 @@
"RequestType" => 1,
"TextTrackKind" => 1,
"TextTrackMode" => 1,
- "XMLHttpRequestResponseType" => 1,
);
# Cache of IDL file pathnames.
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (200299 => 200300)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm 2016-05-01 04:50:10 UTC (rev 200300)
@@ -862,7 +862,11 @@
# FIXME: Might be nice to make the entire array be NeverDestroyed instead of each value, but not sure the syntax for that.
$result .= " static NeverDestroyed<const String> values[] = {\n";
foreach my $value (@{$enumeration->values}) {
- $result .= " ASCIILiteral(\"$value\"),\n";
+ if ($value eq "") {
+ $result .= " emptyString(),\n";
+ } else {
+ $result .= " ASCIILiteral(\"$value\"),\n";
+ }
}
$result .= " };\n";
my $index = 0;
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (200299 => 200300)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2016-05-01 04:50:10 UTC (rev 200300)
@@ -81,7 +81,7 @@
static void replaceCharsetInMediaType(String& mediaType, const String& charsetValue)
{
- unsigned int pos = 0, len = 0;
+ unsigned pos = 0, len = 0;
findCharsetInMediaType(mediaType, pos, len);
@@ -93,7 +93,7 @@
// Found at least one existing charset, replace all occurrences with new charset.
while (len) {
mediaType.replace(pos, len, charsetValue);
- unsigned int start = pos + charsetValue.length();
+ unsigned start = pos + charsetValue.length();
findCharsetInMediaType(mediaType, pos, len, start);
}
}
@@ -109,30 +109,15 @@
Ref<XMLHttpRequest> XMLHttpRequest::create(ScriptExecutionContext& context)
{
- Ref<XMLHttpRequest> xmlHttpRequest = adoptRef(*new XMLHttpRequest(context));
+ auto xmlHttpRequest = adoptRef(*new XMLHttpRequest(context));
xmlHttpRequest->suspendIfNeeded();
return xmlHttpRequest;
}
XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext& context)
: ActiveDOMObject(&context)
- , m_async(true)
- , m_includeCredentials(false)
- , m_state(UNSENT)
- , m_createdDocument(false)
- , m_error(false)
- , m_uploadEventsAllowed(true)
- , m_uploadComplete(false)
- , m_sameOriginRequest(true)
- , m_receivedLength(0)
- , m_lastSendLineNumber(0)
- , m_lastSendColumnNumber(0)
- , m_exceptionCode(0)
, m_progressEventThrottle(this)
- , m_responseTypeCode(ResponseTypeDefault)
- , m_responseCacheIsValid(false)
, m_resumeTimer(*this, &XMLHttpRequest::resumeTimerFired)
- , m_dispatchErrorOnResuming(false)
, m_networkErrorTimer(*this, &XMLHttpRequest::networkErrorTimerFired)
, m_timeoutTimer(*this, &XMLHttpRequest::didReachTimeout)
{
@@ -160,6 +145,7 @@
}
#if ENABLE(DASHBOARD_SUPPORT)
+
bool XMLHttpRequest::usesDashboardBackwardCompatibilityMode() const
{
if (scriptExecutionContext()->isWorkerGlobalScope())
@@ -167,6 +153,7 @@
Settings* settings = document()->settings();
return settings && settings->usesDashboardBackwardCompatibilityMode();
}
+
#endif
XMLHttpRequest::State XMLHttpRequest::readyState() const
@@ -176,16 +163,16 @@
String XMLHttpRequest::responseText(ExceptionCode& ec)
{
- if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != ResponseTypeText) {
+ if (m_responseType != XMLHttpRequestResponseType::EmptyString && m_responseType != XMLHttpRequestResponseType::Text) {
ec = INVALID_STATE_ERR;
- return "";
+ return { };
}
return responseTextIgnoringResponseType();
}
void XMLHttpRequest::didCacheResponseJSON()
{
- ASSERT(m_responseTypeCode == ResponseTypeJSON);
+ ASSERT(m_responseType == XMLHttpRequestResponseType::Json);
ASSERT(doneWithoutErrors());
m_responseCacheIsValid = true;
m_responseBuilder.clear();
@@ -193,7 +180,7 @@
Document* XMLHttpRequest::responseXML(ExceptionCode& ec)
{
- if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != ResponseTypeDocument) {
+ if (m_responseType != XMLHttpRequestResponseType::EmptyString && m_responseType != XMLHttpRequestResponseType::Document) {
ec = INVALID_STATE_ERR;
return nullptr;
}
@@ -208,7 +195,7 @@
// The W3C spec requires the final MIME type to be some valid XML type, or text/html.
// If it is text/html, then the responseType of "document" must have been supplied explicitly.
if ((m_response.isHTTP() && !responseIsXML() && !isHTML)
- || (isHTML && m_responseTypeCode == ResponseTypeDefault)
+ || (isHTML && m_responseType == XMLHttpRequestResponseType::EmptyString)
|| scriptExecutionContext()->isWorkerGlobalScope()) {
m_responseDocument = nullptr;
} else {
@@ -232,7 +219,7 @@
Blob* XMLHttpRequest::responseBlob()
{
- ASSERT(m_responseTypeCode == ResponseTypeBlob);
+ ASSERT(m_responseType == XMLHttpRequestResponseType::Blob);
ASSERT(doneWithoutErrors());
if (!m_responseBlob) {
@@ -254,7 +241,7 @@
ArrayBuffer* XMLHttpRequest::responseArrayBuffer()
{
- ASSERT(m_responseTypeCode == ResponseTypeArrayBuffer);
+ ASSERT(m_responseType == XMLHttpRequestResponseType::Arraybuffer);
ASSERT(doneWithoutErrors());
if (!m_responseArrayBuffer) {
@@ -286,7 +273,7 @@
m_timeoutTimer.startOneShot(std::max(0.0, interval.count()));
}
-void XMLHttpRequest::setResponseType(const String& responseType, ExceptionCode& ec)
+void XMLHttpRequest::setResponseType(XMLHttpRequestResponseType type, ExceptionCode& ec)
{
if (m_state >= LOADING) {
ec = INVALID_STATE_ERR;
@@ -303,41 +290,9 @@
return;
}
- if (responseType == "")
- m_responseTypeCode = ResponseTypeDefault;
- else if (responseType == "text")
- m_responseTypeCode = ResponseTypeText;
- else if (responseType == "json")
- m_responseTypeCode = ResponseTypeJSON;
- else if (responseType == "document")
- m_responseTypeCode = ResponseTypeDocument;
- else if (responseType == "blob")
- m_responseTypeCode = ResponseTypeBlob;
- else if (responseType == "arraybuffer")
- m_responseTypeCode = ResponseTypeArrayBuffer;
- else
- ASSERT_NOT_REACHED();
+ m_responseType = type;
}
-String XMLHttpRequest::responseType()
-{
- switch (m_responseTypeCode) {
- case ResponseTypeDefault:
- return "";
- case ResponseTypeText:
- return "text";
- case ResponseTypeJSON:
- return "json";
- case ResponseTypeDocument:
- return "document";
- case ResponseTypeBlob:
- return "blob";
- case ResponseTypeArrayBuffer:
- return "arraybuffer";
- }
- return "";
-}
-
String XMLHttpRequest::responseURL() const
{
URL responseURL(m_response.url());
@@ -508,7 +463,7 @@
// attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
// We'll only disable this functionality for HTTP(S) requests since sync requests for local protocols
// such as file: and data: still make sense to allow.
- if (url.protocolIsInHTTPFamily() && m_responseTypeCode != ResponseTypeDefault) {
+ if (url.protocolIsInHTTPFamily() && m_responseType != XMLHttpRequestResponseType::EmptyString) {
logConsoleError(scriptExecutionContext(), "Synchronous HTTP(S) requests made from the window context cannot have XMLHttpRequest.responseType set.");
ec = INVALID_ACCESS_ERR;
return;
@@ -1025,10 +980,9 @@
mimeType = extractMIMETypeFromMediaType(m_response.httpHeaderField(HTTPHeaderName::ContentType));
else
mimeType = m_response.mimeType();
+ if (mimeType.isEmpty())
+ mimeType = ASCIILiteral("text/xml");
}
- if (mimeType.isEmpty())
- mimeType = "text/xml";
-
return mimeType;
}
@@ -1042,10 +996,7 @@
if (m_state == UNSENT || m_state == OPENED || m_error)
return 0;
- if (m_response.httpStatusCode())
- return m_response.httpStatusCode();
-
- return 0;
+ return m_response.httpStatusCode();
}
String XMLHttpRequest::statusText() const
@@ -1053,10 +1004,7 @@
if (m_state == UNSENT || m_state == OPENED || m_error)
return String();
- if (!m_response.httpStatusText().isNull())
- return m_response.httpStatusText();
-
- return String();
+ return m_response.httpStatusText();
}
void XMLHttpRequest::didFail(const ResourceError& error)
@@ -1147,6 +1095,22 @@
m_response.setHTTPHeaderField(HTTPHeaderName::ContentType, m_mimeTypeOverride);
}
+static inline bool shouldDecodeResponse(XMLHttpRequestResponseType type)
+{
+ switch (type) {
+ case XMLHttpRequestResponseType::EmptyString:
+ case XMLHttpRequestResponseType::Document:
+ case XMLHttpRequestResponseType::Json:
+ case XMLHttpRequestResponseType::Text:
+ return true;
+ case XMLHttpRequestResponseType::Arraybuffer:
+ case XMLHttpRequestResponseType::Blob:
+ return false;
+ }
+ ASSERT_NOT_REACHED();
+ return true;
+}
+
void XMLHttpRequest::didReceiveData(const char* data, int len)
{
if (m_error)
@@ -1161,7 +1125,7 @@
if (m_responseEncoding.isEmpty())
m_responseEncoding = m_response.textEncodingName();
- bool useDecoder = shouldDecodeResponse();
+ bool useDecoder = shouldDecodeResponse(m_responseType);
if (useDecoder && !m_decoder) {
if (!m_responseEncoding.isEmpty())
@@ -1185,7 +1149,7 @@
if (useDecoder)
m_responseBuilder.append(m_decoder->decode(data, len));
- else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCode == ResponseTypeBlob) {
+ else {
// Buffer binary data.
if (!m_binaryResponseBuilder)
m_binaryResponseBuilder = SharedBuffer::create();
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.h (200299 => 200300)
--- trunk/Source/WebCore/xml/XMLHttpRequest.h 2016-05-01 04:17:54 UTC (rev 200299)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.h 2016-05-01 04:50:10 UTC (rev 200300)
@@ -19,18 +19,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef XMLHttpRequest_h
-#define XMLHttpRequest_h
+#pragma once
#include "ActiveDOMObject.h"
-#include "EventListener.h"
#include "FormData.h"
#include "ResourceResponse.h"
-#include "ScriptWrappable.h"
#include "ThreadableLoaderClient.h"
#include "XMLHttpRequestEventTarget.h"
#include "XMLHttpRequestProgressEventThrottle.h"
-#include <wtf/text/AtomicStringHash.h>
#include <wtf/text/StringBuilder.h>
namespace JSC {
@@ -43,19 +39,19 @@
class Blob;
class Document;
class DOMFormData;
-class ResourceRequest;
class SecurityOrigin;
class SharedBuffer;
class TextResourceDecoder;
class ThreadableLoader;
+enum class XMLHttpRequestResponseType { EmptyString, Arraybuffer, Blob, Document, Json, Text };
+
class XMLHttpRequest final : public RefCounted<XMLHttpRequest>, public XMLHttpRequestEventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
WTF_MAKE_FAST_ALLOCATED;
public:
static Ref<XMLHttpRequest> create(ScriptExecutionContext&);
WEBCORE_EXPORT ~XMLHttpRequest();
- // These exact numeric values are important because JS expects them.
enum State {
UNSENT = 0,
OPENED = 1,
@@ -64,18 +60,6 @@
DONE = 4
};
- enum ResponseTypeCode {
- ResponseTypeDefault,
- ResponseTypeText,
- ResponseTypeJSON,
- ResponseTypeDocument,
-
- // Binary format
- ResponseTypeBlob,
- ResponseTypeArrayBuffer
- };
- static const ResponseTypeCode FirstBinaryResponseType = ResponseTypeBlob;
-
virtual void didReachTimeout();
EventTargetInterface eventTargetInterface() const override { return XMLHttpRequestEventTargetInterfaceType; }
@@ -122,9 +106,8 @@
static String uppercaseKnownHTTPMethod(const String&);
static bool isAllowedHTTPHeader(const String&);
- void setResponseType(const String&, ExceptionCode&);
- String responseType();
- ResponseTypeCode responseTypeCode() const { return m_responseTypeCode; }
+ void setResponseType(XMLHttpRequestResponseType, ExceptionCode&);
+ XMLHttpRequestResponseType responseType() const;
String responseURL() const;
@@ -194,8 +177,6 @@
void networkError();
void abortError();
- bool shouldDecodeResponse() const { return m_responseTypeCode < FirstBinaryResponseType; }
-
void dispatchErrorEvents(const AtomicString&);
void resumeTimerFired();
@@ -207,12 +188,12 @@
HTTPHeaderMap m_requestHeaders;
RefPtr<FormData> m_requestEntityBody;
String m_mimeTypeOverride;
- bool m_async;
- bool m_includeCredentials;
+ bool m_async { true };
+ bool m_includeCredentials { false };
RefPtr<Blob> m_responseBlob;
RefPtr<ThreadableLoader> m_loader;
- State m_state;
+ State m_state { UNSENT };
bool m_sendFlag { false };
ResourceResponse m_response;
@@ -221,35 +202,34 @@
RefPtr<TextResourceDecoder> m_decoder;
StringBuilder m_responseBuilder;
- bool m_createdDocument;
+ bool m_createdDocument { false };
RefPtr<Document> m_responseDocument;
RefPtr<SharedBuffer> m_binaryResponseBuilder;
RefPtr<JSC::ArrayBuffer> m_responseArrayBuffer;
- bool m_error;
+ bool m_error { false };
- bool m_uploadEventsAllowed;
- bool m_uploadComplete;
+ bool m_uploadEventsAllowed { true };
+ bool m_uploadComplete { false };
- bool m_sameOriginRequest;
+ bool m_sameOriginRequest { true };
- // Used for onprogress tracking
- long long m_receivedLength;
+ // Used for progress event tracking.
+ long long m_receivedLength { 0 };
- unsigned m_lastSendLineNumber;
- unsigned m_lastSendColumnNumber;
+ unsigned m_lastSendLineNumber { 0 };
+ unsigned m_lastSendColumnNumber { 0 };
String m_lastSendURL;
- ExceptionCode m_exceptionCode;
+ ExceptionCode m_exceptionCode { 0 };
XMLHttpRequestProgressEventThrottle m_progressEventThrottle;
- // An enum corresponding to the allowed string values for the responseType attribute.
- ResponseTypeCode m_responseTypeCode;
- bool m_responseCacheIsValid;
+ XMLHttpRequestResponseType m_responseType { XMLHttpRequestResponseType::EmptyString };
+ bool m_responseCacheIsValid { false };
Timer m_resumeTimer;
- bool m_dispatchErrorOnResuming;
+ bool m_dispatchErrorOnResuming { false };
Timer m_networkErrorTimer;
void networkErrorTimerFired();
@@ -259,6 +239,9 @@
Timer m_timeoutTimer;
};
-} // namespace WebCore
+inline XMLHttpRequestResponseType XMLHttpRequest::responseType() const
+{
+ return m_responseType;
+}
-#endif // XMLHttpRequest_h
+} // namespace WebCore