Diff
Modified: trunk/LayoutTests/ChangeLog (212180 => 212181)
--- trunk/LayoutTests/ChangeLog 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/LayoutTests/ChangeLog 2017-02-11 05:49:23 UTC (rev 212181)
@@ -1,3 +1,13 @@
+2017-02-10 Sam Weinig <s...@webkit.org>
+
+ [WebIDL] Cleanup XMLHttpRequest's bindings
+ https://bugs.webkit.org/show_bug.cgi?id=168067
+
+ Reviewed by Chris Dumez.
+
+ * http/tests/xmlhttprequest/set-bad-headervalue.html:
+ Update test now that we throw the correct exceptions.
+
2017-02-10 Chris Dumez <cdu...@apple.com>
document.origin doesn't match spec
Modified: trunk/LayoutTests/http/tests/xmlhttprequest/set-bad-headervalue.html (212180 => 212181)
--- trunk/LayoutTests/http/tests/xmlhttprequest/set-bad-headervalue.html 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/LayoutTests/http/tests/xmlhttprequest/set-bad-headervalue.html 2017-02-11 05:49:23 UTC (rev 212181)
@@ -15,21 +15,21 @@
var client = new XMLHttpRequest()
client.open("GET", "...")
if (expectError)
- assert_throws("SyntaxError", function() { client.setRequestHeader("x-test", value) }, ' given value ' + value+', ')
+ assert_throws(expectError, function() { client.setRequestHeader("x-test", value) }, ' given value ' + value+', ')
else
client.setRequestHeader("x-test", value)
})
}
- try_value("t\rt", true)
- try_value("t\nt", true)
- try_value("テスト", true)
- try_value("t\bt", true)
- try_value("t\vt", true)
- try_value("t\tt", false)
- try_value("t t", false)
- try_value("\xd0\xa1", false)
- try_value("\x7f", true)
+ try_value("t\rt", {name:'SyntaxError'})
+ try_value("t\nt", {name:'SyntaxError'})
+ try_value("テスト", {name:'TypeError'})
+ try_value("t\bt", {name:'SyntaxError'})
+ try_value("t\vt", {name:'SyntaxError'})
+ try_value("t\tt")
+ try_value("t t")
+ try_value("\xd0\xa1")
+ try_value("\x7f", {name:'SyntaxError'})
test(function() {
var client = new XMLHttpRequest()
client.open("GET", "...")
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (212180 => 212181)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-02-11 05:49:23 UTC (rev 212181)
@@ -1,3 +1,14 @@
+2017-02-10 Sam Weinig <s...@webkit.org>
+
+ [WebIDL] Cleanup XMLHttpRequest's bindings
+ https://bugs.webkit.org/show_bug.cgi?id=168067
+
+ Reviewed by Chris Dumez.
+
+ * web-platform-tests/XMLHttpRequest/setrequestheader-bogus-name-expected.txt:
+ * web-platform-tests/XMLHttpRequest/setrequestheader-bogus-value-expected.txt:
+ Update results now that we pass.
+
2017-02-10 Chris Dumez <cdu...@apple.com>
document.origin doesn't match spec
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-name-expected.txt (212180 => 212181)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-name-expected.txt 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-name-expected.txt 2017-02-11 05:49:23 UTC (rev 212181)
@@ -68,6 +68,6 @@
PASS setRequestHeader should throw with header name "\x1d".
PASS setRequestHeader should throw with header name "\x1e".
PASS setRequestHeader should throw with header name "\x1f".
-FAIL setRequestHeader should throw with header name "テスト". assert_throws: function "function () { client.setRequestHeader(name, 'x-value') }" threw object "SyntaxError (DOM Exception 12): The string did not match the expected pattern." ("SyntaxError") expected object "TypeError" ("TypeError")
-FAIL setRequestHeader should throw with header name "X-テスト". assert_throws: function "function () { client.setRequestHeader(name, 'x-value') }" threw object "SyntaxError (DOM Exception 12): The string did not match the expected pattern." ("SyntaxError") expected object "TypeError" ("TypeError")
+PASS setRequestHeader should throw with header name "テスト".
+PASS setRequestHeader should throw with header name "X-テスト".
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-value-expected.txt (212180 => 212181)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-value-expected.txt 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/setrequestheader-bogus-value-expected.txt 2017-02-11 05:49:23 UTC (rev 212181)
@@ -3,6 +3,6 @@
PASS XMLHttpRequest: setRequestHeader() value argument checks 1
PASS XMLHttpRequest: setRequestHeader() value argument checks 2
PASS XMLHttpRequest: setRequestHeader() value argument checks 3
-FAIL XMLHttpRequest: setRequestHeader() value argument checks 4 assert_throws: given value テスト, function "function () { client.setRequestHeader("x-test", "テスト") }" threw object "SyntaxError (DOM Exception 12): The string did not match the expected pattern." ("SyntaxError") expected object "TypeError" ("TypeError")
+PASS XMLHttpRequest: setRequestHeader() value argument checks 4
PASS Omitted value argument
Modified: trunk/Source/WebCore/ChangeLog (212180 => 212181)
--- trunk/Source/WebCore/ChangeLog 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/ChangeLog 2017-02-11 05:49:23 UTC (rev 212181)
@@ -1,3 +1,33 @@
+2017-02-10 Sam Weinig <s...@webkit.org>
+
+ [WebIDL] Cleanup XMLHttpRequest's bindings
+ https://bugs.webkit.org/show_bug.cgi?id=168067
+
+ Reviewed by Chris Dumez.
+
+ * bindings/js/JSDOMBinding.cpp:
+ (WebCore::jsOwnedStringOrNull): Deleted.
+ * bindings/js/JSDOMBinding.h:
+ Remove jsOwnedStringOrNull and inline it into it's one use
+ in JSXMLHttpRequestCustom.
+
+ * bindings/js/JSXMLHttpRequestCustom.cpp:
+ (WebCore::JSXMLHttpRequest::responseText):
+ (WebCore::SendFunctor::SendFunctor): Deleted.
+ (WebCore::SendFunctor::line): Deleted.
+ (WebCore::SendFunctor::column): Deleted.
+ (WebCore::SendFunctor::url): Deleted.
+ (WebCore::SendFunctor::operator()): Deleted.
+ (WebCore::JSXMLHttpRequest::send): Deleted.
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::send):
+ * xml/XMLHttpRequest.h:
+ Remove custom send, replacing it with a single send implementation that
+ takes a variant.
+
+ * xml/XMLHttpRequest.idl:
+ Cleanup the IDL to better match the spec. Update correct types where trivial.
+
2017-02-10 Chris Dumez <cdu...@apple.com>
document.origin doesn't match spec
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (212180 => 212181)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp 2017-02-11 05:49:23 UTC (rev 212181)
@@ -33,13 +33,6 @@
commonVM().addImpureProperty(propertyName);
}
-JSValue jsOwnedStringOrNull(ExecState* exec, const String& s)
-{
- if (s.isNull())
- return jsNull();
- return jsOwnedString(exec, s);
-}
-
JSValue jsStringOrUndefined(ExecState* exec, const String& s)
{
if (s.isNull())
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (212180 => 212181)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2017-02-11 05:49:23 UTC (rev 212181)
@@ -51,10 +51,6 @@
JSC::JSValue jsStringOrUndefined(JSC::ExecState*, const String&); // undefined if the string is null
-// See _javascript_Core for explanation: Should be used for any string that is already owned by another
-// object, to let the engine know that collecting the JSString wrapper is unlikely to save memory.
-JSC::JSValue jsOwnedStringOrNull(JSC::ExecState*, const String&);
-
WEBCORE_EXPORT bool hasIteratorMethod(JSC::ExecState&, JSC::JSValue);
template<JSC::NativeFunction nativeFunction, int length> JSC::EncodedJSValue nonCachingStaticFunctionGetter(JSC::ExecState* exec, JSC::EncodedJSValue, JSC::PropertyName propertyName)
Modified: trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp (212180 => 212181)
--- trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/bindings/js/JSXMLHttpRequestCustom.cpp 2017-02-11 05:49:23 UTC (rev 212181)
@@ -46,7 +46,6 @@
#include "JSEvent.h"
#include "JSEventListener.h"
#include "XMLHttpRequest.h"
-#include <interpreter/StackVisitor.h>
#include <runtime/ArrayBuffer.h>
#include <runtime/Error.h>
#include <runtime/JSArrayBuffer.h>
@@ -66,85 +65,6 @@
visitor.addOpaqueRoot(responseDocument);
}
-class SendFunctor {
-public:
- SendFunctor()
- : m_hasSkippedFirstFrame(false)
- , m_line(0)
- , m_column(0)
- {
- }
-
- unsigned line() const { return m_line; }
- unsigned column() const { return m_column; }
- String url() const { return m_url; }
-
- StackVisitor::Status operator()(StackVisitor& visitor) const
- {
- if (!m_hasSkippedFirstFrame) {
- m_hasSkippedFirstFrame = true;
- return StackVisitor::Continue;
- }
-
- unsigned line = 0;
- unsigned column = 0;
- visitor->computeLineAndColumn(line, column);
- m_line = line;
- m_column = column;
- m_url = visitor->sourceURL();
- return StackVisitor::Done;
- }
-
-private:
- mutable bool m_hasSkippedFirstFrame;
- mutable unsigned m_line;
- mutable unsigned m_column;
- mutable String m_url;
-};
-
-JSValue JSXMLHttpRequest::send(ExecState& state)
-{
- InspectorInstrumentation::willSendXMLHttpRequest(wrapped().scriptExecutionContext(), wrapped().url());
-
- VM& vm = state.vm();
- JSValue value = state.argument(0);
- ExceptionOr<void> result;
- if (value.isUndefinedOrNull())
- result = wrapped().send();
- else if (value.inherits(vm, JSDocument::info()))
- result = wrapped().send(*JSDocument::toWrapped(vm, value));
- else if (value.inherits(vm, JSBlob::info()))
- result = wrapped().send(*JSBlob::toWrapped(vm, value));
- else if (value.inherits(vm, JSDOMFormData::info()))
- result = wrapped().send(*JSDOMFormData::toWrapped(vm, value));
- else if (RefPtr<ArrayBuffer> arrayBuffer = toUnsharedArrayBuffer(vm, value))
- result = wrapped().send(*arrayBuffer);
- else if (RefPtr<ArrayBufferView> arrayBufferView = toUnsharedArrayBufferView(vm, value))
- result = wrapped().send(*arrayBufferView);
- else {
- // FIXME: If toString raises an exception, should we exit before calling willSendXMLHttpRequest?
- // FIXME: If toString raises an exception, should we exit before calling send?
- result = wrapped().send(value.toWTFString(&state));
- }
-
- // FIXME: This should probably use ShadowChicken so that we get the right frame even when it did a tail call.
- // https://bugs.webkit.org/show_bug.cgi?id=155688
- SendFunctor functor;
- state.iterate(functor);
- wrapped().setLastSendLineAndColumnNumber(functor.line(), functor.column());
- wrapped().setLastSendURL(functor.url());
-
- // FIXME: Is it correct to do this only after the paragraph code of code just above, or should we exit earlier?
- if (UNLIKELY(result.hasException())) {
- auto& vm = state.vm();
- auto scope = DECLARE_THROW_SCOPE(vm);
- propagateException(state, scope, result.releaseException());
- return { };
- }
-
- return jsUndefined();
-}
-
JSValue JSXMLHttpRequest::responseText(ExecState& state) const
{
auto result = wrapped().responseText();
@@ -156,7 +76,13 @@
return { };
}
- return jsOwnedStringOrNull(&state, result.releaseReturnValue());
+ auto resultValue = result.releaseReturnValue();
+ if (resultValue.isNull())
+ return jsNull();
+
+ // See _javascript_Core for explanation: Should be used for any string that is already owned by another
+ // object, to let the engine know that collecting the JSString wrapper is unlikely to save memory.
+ return jsOwnedString(&state, resultValue);
}
JSValue JSXMLHttpRequest::retrieveResponse(ExecState& state)
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (212180 => 212181)
--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp 2017-02-11 05:49:23 UTC (rev 212181)
@@ -54,6 +54,7 @@
#include "XMLHttpRequestProgressEvent.h"
#include "XMLHttpRequestUpload.h"
#include "markup.h"
+#include <interpreter/StackVisitor.h>
#include <mutex>
#include <runtime/ArrayBuffer.h>
#include <runtime/ArrayBufferView.h>
@@ -498,6 +499,72 @@
return std::nullopt;
}
+namespace {
+
+// FIXME: This should be abstracted out, so that any IDL function can be passed the line/column/url tuple.
+
+// FIXME: This should probably use ShadowChicken so that we get the right frame even when it did a tail call.
+// https://bugs.webkit.org/show_bug.cgi?id=155688
+
+class SendFunctor {
+public:
+ SendFunctor() = default;
+
+ unsigned line() const { return m_line; }
+ unsigned column() const { return m_column; }
+ String url() const { return m_url; }
+
+ JSC::StackVisitor::Status operator()(JSC::StackVisitor& visitor) const
+ {
+ if (!m_hasSkippedFirstFrame) {
+ m_hasSkippedFirstFrame = true;
+ return JSC::StackVisitor::Continue;
+ }
+
+ unsigned line = 0;
+ unsigned column = 0;
+ visitor->computeLineAndColumn(line, column);
+ m_line = line;
+ m_column = column;
+ m_url = visitor->sourceURL();
+ return JSC::StackVisitor::Done;
+ }
+
+private:
+ mutable bool m_hasSkippedFirstFrame { false };
+ mutable unsigned m_line { 0 };
+ mutable unsigned m_column { 0 };
+ mutable String m_url;
+};
+
+}
+
+ExceptionOr<void> XMLHttpRequest::send(JSC::ExecState& state, std::optional<SendTypes>&& sendType)
+{
+ InspectorInstrumentation::willSendXMLHttpRequest(scriptExecutionContext(), url());
+
+ ExceptionOr<void> result;
+ if (!sendType)
+ result = send();
+ else {
+ result = WTF::switchOn(sendType.value(),
+ [this] (const RefPtr<Document>& document) -> ExceptionOr<void> { return send(*document); },
+ [this] (const RefPtr<Blob>& blob) -> ExceptionOr<void> { return send(*blob); },
+ [this] (const RefPtr<JSC::ArrayBufferView>& arrayBufferView) -> ExceptionOr<void> { return send(*arrayBufferView); },
+ [this] (const RefPtr<JSC::ArrayBuffer>& arrayBuffer) -> ExceptionOr<void> { return send(*arrayBuffer); },
+ [this] (const RefPtr<DOMFormData>& formData) -> ExceptionOr<void> { return send(*formData); },
+ [this] (const String& string) -> ExceptionOr<void> { return send(string); }
+ );
+ }
+
+ SendFunctor functor;
+ state.iterate(functor);
+ setLastSendLineAndColumnNumber(functor.line(), functor.column());
+ setLastSendURL(functor.url());
+
+ return result;
+}
+
ExceptionOr<void> XMLHttpRequest::send(Document& document)
{
if (auto result = prepareToSend())
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.h (212180 => 212181)
--- trunk/Source/WebCore/xml/XMLHttpRequest.h 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.h 2017-02-11 05:49:23 UTC (rev 212181)
@@ -26,13 +26,16 @@
#include "FormData.h"
#include "ResourceResponse.h"
#include "ThreadableLoaderClient.h"
+#include "URL.h"
#include "XMLHttpRequestEventTarget.h"
#include "XMLHttpRequestProgressEventThrottle.h"
+#include <wtf/Variant.h>
#include <wtf/text/StringBuilder.h>
namespace JSC {
class ArrayBuffer;
class ArrayBufferView;
+class ExecState;
}
namespace WebCore {
@@ -65,6 +68,8 @@
EventTargetInterface eventTargetInterface() const override { return XMLHttpRequestEventTargetInterfaceType; }
ScriptExecutionContext* scriptExecutionContext() const override { return ActiveDOMObject::scriptExecutionContext(); }
+ using SendTypes = Variant<RefPtr<Document>, RefPtr<Blob>, RefPtr<JSC::ArrayBufferView>, RefPtr<JSC::ArrayBuffer>, RefPtr<DOMFormData>, String>;
+
const URL& url() const { return m_url; }
String statusText() const;
int status() const;
@@ -74,12 +79,7 @@
ExceptionOr<void> open(const String& method, const String& url);
ExceptionOr<void> open(const String& method, const URL&, bool async);
ExceptionOr<void> open(const String& method, const String&, bool async, const String& user, const String& password);
- ExceptionOr<void> send(Document&);
- ExceptionOr<void> send(const String& = { });
- ExceptionOr<void> send(Blob&);
- ExceptionOr<void> send(DOMFormData&);
- ExceptionOr<void> send(JSC::ArrayBuffer&);
- ExceptionOr<void> send(JSC::ArrayBufferView&);
+ ExceptionOr<void> send(JSC::ExecState&, std::optional<SendTypes>&&);
void abort();
ExceptionOr<void> setRequestHeader(const String& name, const String& value);
ExceptionOr<void> overrideMimeType(const String& override);
@@ -154,6 +154,12 @@
bool responseIsXML() const;
std::optional<ExceptionOr<void>> prepareToSend();
+ ExceptionOr<void> send(Document&);
+ ExceptionOr<void> send(const String& = { });
+ ExceptionOr<void> send(Blob&);
+ ExceptionOr<void> send(DOMFormData&);
+ ExceptionOr<void> send(JSC::ArrayBuffer&);
+ ExceptionOr<void> send(JSC::ArrayBufferView&);
ExceptionOr<void> sendBytesData(const void*, size_t);
void changeState(State);
Modified: trunk/Source/WebCore/xml/XMLHttpRequest.idl (212180 => 212181)
--- trunk/Source/WebCore/xml/XMLHttpRequest.idl 2017-02-11 05:33:44 UTC (rev 212180)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.idl 2017-02-11 05:49:23 UTC (rev 212181)
@@ -26,6 +26,10 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+typedef (ArrayBufferView or ArrayBuffer) BufferSource;
+// FIXME: Add URLSearchParams and ReadableStream to the union when supported.
+typedef (Blob or BufferSource or DOMFormData or USVString) BodyInit;
+
enum XMLHttpRequestResponseType {
"",
"arraybuffer",
@@ -47,6 +51,7 @@
PrivateIdentifier,
PublicIdentifier,
] interface XMLHttpRequest : XMLHttpRequestEventTarget {
+ // event handler
attribute EventHandler onreadystatechange;
// state
@@ -55,38 +60,33 @@
const unsigned short HEADERS_RECEIVED = 2;
const unsigned short LOADING = 3;
const unsigned short DONE = 4;
+ readonly attribute unsigned short readyState;
+ // request
+ [MayThrowException] void open(ByteString method, DOMString url); // FIXME: url should be a USVString.
+ [MayThrowException] void open(ByteString method, DOMString url, boolean async, optional DOMString? user = null, optional DOMString? password = null); // FIXME: url/user/password should all be a USVStrings.
+ [MayThrowException] void setRequestHeader(ByteString header, ByteString value);
[SetterMayThrowException] attribute unsigned long timeout;
- readonly attribute unsigned short readyState;
-
[SetterMayThrowException] attribute boolean withCredentials;
-
- // Use overloading rather than "boolean async = true" because legacy content prevents treating the 'async' argument being undefined identical from it being omitted.
- [MayThrowException] void open(DOMString method, DOMString url);
- [MayThrowException] void open(DOMString method, DOMString url, boolean async, optional DOMString? user = null, optional DOMString? password = null);
-
- [MayThrowException] void setRequestHeader(DOMString header, DOMString value);
-
- [Custom, MayThrowException] void send();
-
+ readonly attribute XMLHttpRequestUpload upload;
+ [CallWith=ScriptState, MayThrowException] void send(optional (Document or BodyInit)? body = null);
void abort();
- readonly attribute XMLHttpRequestUpload upload;
-
- DOMString getAllResponseHeaders();
- DOMString? getResponseHeader(DOMString header);
- [GetterMayThrowException, CustomGetter] readonly attribute DOMString? responseText;
- [GetterMayThrowException] readonly attribute Document responseXML;
-
+ // response
+ readonly attribute USVString responseURL;
+ readonly attribute unsigned short status;
+ readonly attribute ByteString statusText;
+ ByteString? getResponseHeader(ByteString name);
+ ByteString getAllResponseHeaders();
+ [MayThrowException] void overrideMimeType(DOMString mime);
[SetterMayThrowException] attribute XMLHttpRequestResponseType responseType;
- [JSBuiltin] readonly attribute Object response;
+ [JSBuiltin] readonly attribute any response;
+ [GetterMayThrowException, CustomGetter] readonly attribute USVString? responseText;
+ // FIXME: responseXML should be annotated with [Exposed=Window].
+ [GetterMayThrowException] readonly attribute Document? responseXML;
- readonly attribute unsigned short status;
- readonly attribute DOMString statusText;
- readonly attribute DOMString responseURL;
-
+ // internals
[PrivateIdentifier] boolean responseCacheIsValid();
[PrivateIdentifier, Custom] any retrieveResponse();
- [MayThrowException] void overrideMimeType(DOMString override);
};