-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fetch] Implement the
Response.json
static method
https://bugs.webkit.org/show_bug.cgi?id=240375 Reviewed by Youenn Fablet. This implements the `Response.json` static method, added to the fetch spec in whatwg/fetch#1392. * LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.serviceworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.sharedworker-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any.worker-expected.txt: * Source/WebCore/Modules/fetch/FetchBody.h: * Source/WebCore/Modules/fetch/FetchResponse.cpp: (WebCore::FetchResponse::create): Added this method overload to implement the spec's "initialize a response" algorithm. This algortihm used to be combined with the regular Response creation algorithm which extracts the body, but Response.json cannot use that directly. (WebCore::FetchResponse::staticJson): * Source/WebCore/Modules/fetch/FetchResponse.h: * Source/WebCore/Modules/fetch/FetchResponse.idl: Canonical link: https://commits.webkit.org/261960@main
- Loading branch information
1 parent
84eb232
commit 206817f
Showing
8 changed files
with
93 additions
and
92 deletions.
There are no files selected for viewing
20 changes: 8 additions & 12 deletions
20
.../imported/w3c/web-platform-tests/fetch/api/response/response-static-json.any-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
|
||
FAIL Check response returned by static json() with init undefined promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"status":400} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"statusText":"foo"} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"x-foo":"bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
PASS Check response returned by static json() with init undefined | ||
PASS Check response returned by static json() with init {"status":400} | ||
PASS Check response returned by static json() with init {"statusText":"foo"} | ||
PASS Check response returned by static json() with init {"headers":{}} | ||
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} | ||
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}} | ||
PASS Throws TypeError when calling static json() with a status of 204 | ||
PASS Throws TypeError when calling static json() with a status of 205 | ||
PASS Throws TypeError when calling static json() with a status of 304 | ||
FAIL Check static json() encodes JSON objects correctly promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json({ foo: "bar" })', 'Response.json' is undefined)" | ||
PASS Check static json() encodes JSON objects correctly | ||
PASS Check static json() throws when data is not encodable | ||
PASS Check static json() throws when data is circular | ||
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () { | ||
Response.json({ get foo() { throw new CustomError("bar") }}); | ||
}" threw object "TypeError: Response.json is not a function. (In 'Response.json({ get foo() { throw new CustomError("bar") }})', 'Response.json' is undefined)" ("TypeError") expected instance of function "class CustomError extends Error { | ||
name = "CustomError"; | ||
}" ("CustomError") | ||
PASS Check static json() propagates JSON serializer errors | ||
|
20 changes: 8 additions & 12 deletions
20
...web-platform-tests/fetch/api/response/response-static-json.any.serviceworker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
|
||
FAIL Check response returned by static json() with init undefined promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"status":400} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"statusText":"foo"} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"x-foo":"bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
PASS Check response returned by static json() with init undefined | ||
PASS Check response returned by static json() with init {"status":400} | ||
PASS Check response returned by static json() with init {"statusText":"foo"} | ||
PASS Check response returned by static json() with init {"headers":{}} | ||
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} | ||
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}} | ||
PASS Throws TypeError when calling static json() with a status of 204 | ||
PASS Throws TypeError when calling static json() with a status of 205 | ||
PASS Throws TypeError when calling static json() with a status of 304 | ||
FAIL Check static json() encodes JSON objects correctly promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json({ foo: "bar" })', 'Response.json' is undefined)" | ||
PASS Check static json() encodes JSON objects correctly | ||
PASS Check static json() throws when data is not encodable | ||
PASS Check static json() throws when data is circular | ||
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () { | ||
Response.json({ get foo() { throw new CustomError("bar") }}); | ||
}" threw object "TypeError: Response.json is not a function. (In 'Response.json({ get foo() { throw new CustomError("bar") }})', 'Response.json' is undefined)" ("TypeError") expected instance of function "class CustomError extends Error { | ||
name = "CustomError"; | ||
}" ("CustomError") | ||
PASS Check static json() propagates JSON serializer errors | ||
|
20 changes: 8 additions & 12 deletions
20
.../web-platform-tests/fetch/api/response/response-static-json.any.sharedworker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
|
||
FAIL Check response returned by static json() with init undefined promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"status":400} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"statusText":"foo"} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"x-foo":"bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
PASS Check response returned by static json() with init undefined | ||
PASS Check response returned by static json() with init {"status":400} | ||
PASS Check response returned by static json() with init {"statusText":"foo"} | ||
PASS Check response returned by static json() with init {"headers":{}} | ||
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} | ||
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}} | ||
PASS Throws TypeError when calling static json() with a status of 204 | ||
PASS Throws TypeError when calling static json() with a status of 205 | ||
PASS Throws TypeError when calling static json() with a status of 304 | ||
FAIL Check static json() encodes JSON objects correctly promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json({ foo: "bar" })', 'Response.json' is undefined)" | ||
PASS Check static json() encodes JSON objects correctly | ||
PASS Check static json() throws when data is not encodable | ||
PASS Check static json() throws when data is circular | ||
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () { | ||
Response.json({ get foo() { throw new CustomError("bar") }}); | ||
}" threw object "TypeError: Response.json is not a function. (In 'Response.json({ get foo() { throw new CustomError("bar") }})', 'Response.json' is undefined)" ("TypeError") expected instance of function "class CustomError extends Error { | ||
name = "CustomError"; | ||
}" ("CustomError") | ||
PASS Check static json() propagates JSON serializer errors | ||
|
20 changes: 8 additions & 12 deletions
20
...ed/w3c/web-platform-tests/fetch/api/response/response-static-json.any.worker-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,15 @@ | ||
|
||
FAIL Check response returned by static json() with init undefined promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"status":400} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"statusText":"foo"} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
FAIL Check response returned by static json() with init {"headers":{"x-foo":"bar"}} promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json("hello world", init)', 'Response.json' is undefined)" | ||
PASS Check response returned by static json() with init undefined | ||
PASS Check response returned by static json() with init {"status":400} | ||
PASS Check response returned by static json() with init {"statusText":"foo"} | ||
PASS Check response returned by static json() with init {"headers":{}} | ||
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}} | ||
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}} | ||
PASS Throws TypeError when calling static json() with a status of 204 | ||
PASS Throws TypeError when calling static json() with a status of 205 | ||
PASS Throws TypeError when calling static json() with a status of 304 | ||
FAIL Check static json() encodes JSON objects correctly promise_test: Unhandled rejection with value: object "TypeError: Response.json is not a function. (In 'Response.json({ foo: "bar" })', 'Response.json' is undefined)" | ||
PASS Check static json() encodes JSON objects correctly | ||
PASS Check static json() throws when data is not encodable | ||
PASS Check static json() throws when data is circular | ||
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () { | ||
Response.json({ get foo() { throw new CustomError("bar") }}); | ||
}" threw object "TypeError: Response.json is not a function. (In 'Response.json({ get foo() { throw new CustomError("bar") }})', 'Response.json' is undefined)" ("TypeError") expected instance of function "class CustomError extends Error { | ||
name = "CustomError"; | ||
}" ("CustomError") | ||
PASS Check static json() propagates JSON serializer errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.