- Revision
- 203961
- Author
- [email protected]
- Date
- 2016-07-31 23:00:56 -0700 (Sun, 31 Jul 2016)
Log Message
Fetch Response built-ins should use @makeThisTypeError
https://bugs.webkit.org/show_bug.cgi?id=160290
Patch by Youenn Fablet <[email protected]> on 2016-07-31
Reviewed by Darin Adler.
Source/WebCore:
Covered by updated test.
Fixed type error checks.
Making use of @makeThisTypeError to have the correct error message.
Updating arrayBuffer, blob, json and text to return rejected promises in lieu of throwing
in case the 'this' value is not q Response object.
* Modules/fetch/FetchResponse.js:
(clone): Updated instanceof check and making use of @makeThisTypeError.
(arrayBuffer): Ditto.
(blob): Ditto.
(formData): Ditto.
(json): Ditto.
(text): Ditto.
LayoutTests:
* fetch/fetch-error-messages-expected.txt:
* fetch/fetch-error-messages.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (203960 => 203961)
--- trunk/LayoutTests/ChangeLog 2016-08-01 05:43:57 UTC (rev 203960)
+++ trunk/LayoutTests/ChangeLog 2016-08-01 06:00:56 UTC (rev 203961)
@@ -1,3 +1,13 @@
+2016-07-31 Youenn Fablet <[email protected]>
+
+ Fetch Response built-ins should use @makeThisTypeError
+ https://bugs.webkit.org/show_bug.cgi?id=160290
+
+ Reviewed by Darin Adler.
+
+ * fetch/fetch-error-messages-expected.txt:
+ * fetch/fetch-error-messages.html:
+
2016-07-31 Nan Wang <[email protected]>
AX: Add a check for touch event listener on iOS accessibility object
Modified: trunk/LayoutTests/fetch/fetch-error-messages-expected.txt (203960 => 203961)
--- trunk/LayoutTests/fetch/fetch-error-messages-expected.txt 2016-08-01 05:43:57 UTC (rev 203960)
+++ trunk/LayoutTests/fetch/fetch-error-messages-expected.txt 2016-08-01 06:00:56 UTC (rev 203961)
@@ -1,6 +1,12 @@
+CONSOLE MESSAGE: line 11: TypeError: Can only call Response.clone on instances of Response
CONSOLE MESSAGE: line 11: TypeError: The Response.body getter can only be used on instances of Response
CONSOLE MESSAGE: line 11: TypeError: The Request.method getter can only be used on instances of Request
CONSOLE MESSAGE: line 11: TypeError: Can only call Request.clone on instances of Request
+CONSOLE MESSAGE: line 18: Promise rejected with: TypeError: Can only call Response.arrayBuffer on instances of Response
+CONSOLE MESSAGE: line 18: Promise rejected with: TypeError: Can only call Response.blob on instances of Response
+CONSOLE MESSAGE: line 18: Promise rejected with: TypeError: Can only call Response.formData on instances of Response
+CONSOLE MESSAGE: line 18: Promise rejected with: TypeError: Can only call Response.json on instances of Response
+CONSOLE MESSAGE: line 18: Promise rejected with: TypeError: Can only call Response.text on instances of Response
-PASS Exercising TypeError messages in Fetch Response
+PASS Exercising TypeError messages in Fetch Request and Response
Modified: trunk/LayoutTests/fetch/fetch-error-messages.html (203960 => 203961)
--- trunk/LayoutTests/fetch/fetch-error-messages.html 2016-08-01 05:43:57 UTC (rev 203960)
+++ trunk/LayoutTests/fetch/fetch-error-messages.html 2016-08-01 06:00:56 UTC (rev 203961)
@@ -12,6 +12,13 @@
}
}
+function printPromiseMethodError(method, target)
+{
+ return method.call(target).then(assert_unreached, (e) => {
+ console.log("Promise rejected with: " + e);
+ });
+}
+
function printGetterError(object, getterName, target)
{
const getter = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(object), getterName).get;
@@ -18,15 +25,23 @@
printMethodError(getter, target);
}
-test(function(test) {
+promise_test(function(test) {
// This test prints exceptions to check the format of their messages.
var request = new Request("");
var response = new Response("");
- printGetterError(response, "body", request);
- printGetterError(request, "method", response);
- printMethodError(request.clone, response);
-
-}, "Exercising TypeError messages in Fetch Response");
+ var results = [
+ printMethodError(response.clone, request),
+ printPromiseMethodError(response.arrayBuffer, request),
+ printPromiseMethodError(response.blob, request),
+ printPromiseMethodError(response.formData, request),
+ printPromiseMethodError(response.json, request),
+ printPromiseMethodError(response.text, request),
+ printGetterError(response, "body", request),
+ printGetterError(request, "method", response),
+ printMethodError(request.clone, response),
+ ];
+ return Promise.all(results);
+}, "Exercising TypeError messages in Fetch Request and Response");
</script>
Modified: trunk/Source/WebCore/ChangeLog (203960 => 203961)
--- trunk/Source/WebCore/ChangeLog 2016-08-01 05:43:57 UTC (rev 203960)
+++ trunk/Source/WebCore/ChangeLog 2016-08-01 06:00:56 UTC (rev 203961)
@@ -1,3 +1,25 @@
+2016-07-31 Youenn Fablet <[email protected]>
+
+ Fetch Response built-ins should use @makeThisTypeError
+ https://bugs.webkit.org/show_bug.cgi?id=160290
+
+ Reviewed by Darin Adler.
+
+ Covered by updated test.
+
+ Fixed type error checks.
+ Making use of @makeThisTypeError to have the correct error message.
+ Updating arrayBuffer, blob, json and text to return rejected promises in lieu of throwing
+ in case the 'this' value is not q Response object.
+
+ * Modules/fetch/FetchResponse.js:
+ (clone): Updated instanceof check and making use of @makeThisTypeError.
+ (arrayBuffer): Ditto.
+ (blob): Ditto.
+ (formData): Ditto.
+ (json): Ditto.
+ (text): Ditto.
+
2016-07-31 Adrian Perez de Castro <[email protected]>
[GTK] Implement missing WebCore::moveFile() using GLib functions
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.js (203960 => 203961)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-08-01 05:43:57 UTC (rev 203960)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-08-01 06:00:56 UTC (rev 203961)
@@ -80,8 +80,8 @@
function clone()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ throw @makeThisTypeError("Response", "clone");
if (@Response.prototype.@isDisturbed.@call(this))
throw new @TypeError("Cannot clone a disturbed Response");
@@ -98,8 +98,8 @@
// consume and consumeStream single parameter should be kept in sync with FetchBodyConsumer::Type.
function arrayBuffer()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ return @Promise.@reject(@makeThisTypeError("Response", "arrayBuffer"));
const arrayBufferConsumerType = 1;
if (!this.@body)
@@ -110,8 +110,8 @@
function blob()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ return @Promise.@reject(@makeThisTypeError("Response", "blob"));
const blobConsumerType = 2;
if (!this.@body)
@@ -122,8 +122,8 @@
function formData()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ return @Promise.@reject(@makeThisTypeError("Response", "formData"));
return @Promise.@reject("Not implemented");
}
@@ -130,8 +130,8 @@
function json()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ return @Promise.@reject(@makeThisTypeError("Response", "json"));
const jsonConsumerType = 3;
if (!this.@body)
@@ -142,8 +142,8 @@
function text()
{
- if (!this instanceof @Response)
- throw new @TypeError("Function should be called on a Response");
+ if (!(this instanceof @Response))
+ return @Promise.@reject(@makeThisTypeError("Response", "text"));
const textConsumerType = 4;
if (!this.@body)