Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit206817f

Browse files
andreubotellayouennf
authored andcommitted
[fetch] Implement theResponse.json static method
https://bugs.webkit.org/show_bug.cgi?id=240375Reviewed by Youenn Fablet.This implements the `Response.json` static method, added to the fetchspec inwhatwg/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
1 parent84eb232 commit206817f

File tree

8 files changed

+93
-92
lines changed

8 files changed

+93
-92
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11

2-
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)"
3-
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)"
4-
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)"
5-
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)"
6-
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)"
7-
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)"
2+
PASS Check response returned by static json() with init undefined
3+
PASS Check response returned by static json() with init {"status":400}
4+
PASS Check response returned by static json() with init {"statusText":"foo"}
5+
PASS Check response returned by static json() with init {"headers":{}}
6+
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}}
7+
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}}
88
PASS Throws TypeError when calling static json() with a status of 204
99
PASS Throws TypeError when calling static json() with a status of 205
1010
PASS Throws TypeError when calling static json() with a status of 304
11-
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)"
11+
PASS Check static json() encodes JSON objects correctly
1212
PASS Check static json() throws when data is not encodable
1313
PASS Check static json() throws when data is circular
14-
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () {
15-
Response.json({ get foo() { throw new CustomError("bar") }});
16-
}" 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 {
17-
name = "CustomError";
18-
}" ("CustomError")
14+
PASS Check static json() propagates JSON serializer errors
1915

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11

2-
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)"
3-
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)"
4-
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)"
5-
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)"
6-
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)"
7-
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)"
2+
PASS Check response returned by static json() with init undefined
3+
PASS Check response returned by static json() with init {"status":400}
4+
PASS Check response returned by static json() with init {"statusText":"foo"}
5+
PASS Check response returned by static json() with init {"headers":{}}
6+
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}}
7+
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}}
88
PASS Throws TypeError when calling static json() with a status of 204
99
PASS Throws TypeError when calling static json() with a status of 205
1010
PASS Throws TypeError when calling static json() with a status of 304
11-
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)"
11+
PASS Check static json() encodes JSON objects correctly
1212
PASS Check static json() throws when data is not encodable
1313
PASS Check static json() throws when data is circular
14-
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () {
15-
Response.json({ get foo() { throw new CustomError("bar") }});
16-
}" 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 {
17-
name = "CustomError";
18-
}" ("CustomError")
14+
PASS Check static json() propagates JSON serializer errors
1915

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11

2-
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)"
3-
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)"
4-
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)"
5-
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)"
6-
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)"
7-
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)"
2+
PASS Check response returned by static json() with init undefined
3+
PASS Check response returned by static json() with init {"status":400}
4+
PASS Check response returned by static json() with init {"statusText":"foo"}
5+
PASS Check response returned by static json() with init {"headers":{}}
6+
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}}
7+
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}}
88
PASS Throws TypeError when calling static json() with a status of 204
99
PASS Throws TypeError when calling static json() with a status of 205
1010
PASS Throws TypeError when calling static json() with a status of 304
11-
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)"
11+
PASS Check static json() encodes JSON objects correctly
1212
PASS Check static json() throws when data is not encodable
1313
PASS Check static json() throws when data is circular
14-
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () {
15-
Response.json({ get foo() { throw new CustomError("bar") }});
16-
}" 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 {
17-
name = "CustomError";
18-
}" ("CustomError")
14+
PASS Check static json() propagates JSON serializer errors
1915

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11

2-
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)"
3-
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)"
4-
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)"
5-
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)"
6-
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)"
7-
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)"
2+
PASS Check response returned by static json() with init undefined
3+
PASS Check response returned by static json() with init {"status":400}
4+
PASS Check response returned by static json() with init {"statusText":"foo"}
5+
PASS Check response returned by static json() with init {"headers":{}}
6+
PASS Check response returned by static json() with init {"headers":{"content-type":"foo/bar"}}
7+
PASS Check response returned by static json() with init {"headers":{"x-foo":"bar"}}
88
PASS Throws TypeError when calling static json() with a status of 204
99
PASS Throws TypeError when calling static json() with a status of 205
1010
PASS Throws TypeError when calling static json() with a status of 304
11-
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)"
11+
PASS Check static json() encodes JSON objects correctly
1212
PASS Check static json() throws when data is not encodable
1313
PASS Check static json() throws when data is circular
14-
FAIL Check static json() propagates JSON serializer errors assert_throws_js: function "function () {
15-
Response.json({ get foo() { throw new CustomError("bar") }});
16-
}" 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 {
17-
name = "CustomError";
18-
}" ("CustomError")
14+
PASS Check static json() propagates JSON serializer errors
1915

‎Source/WebCore/Modules/fetch/FetchBody.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class FetchBody {
6060
WEBCORE_EXPORT~FetchBody();
6161
FetchBody&operator=(FetchBody&&) =default;
6262

63+
explicitFetchBody(String&& data)
64+
: m_data(WTFMove(data))
65+
{
66+
}
67+
6368
WEBCORE_EXPORTstatic std::optional<FetchBody>fromFormData(ScriptExecutionContext&, Ref<FormData>&&);
6469

6570
voidloadingFailed(const Exception&);
@@ -96,7 +101,6 @@ class FetchBody {
96101
explicitFetchBody(Ref<const ArrayBuffer>&& data) : m_data(WTFMove(data)) { }
97102
explicitFetchBody(Ref<const ArrayBufferView>&& data) : m_data(WTFMove(data)) { }
98103
explicitFetchBody(Ref<FormData>&& data) : m_data(WTFMove(data)) { }
99-
explicitFetchBody(String&& data) : m_data(WTFMove(data)) { }
100104
explicitFetchBody(Ref<const URLSearchParams>&& data) : m_data(WTFMove(data)) { }
101105
explicitFetchBody(Ref<ReadableStream>&& stream) : m_data(stream) { m_readableStream =WTFMove(stream); }
102106
explicitFetchBody(FetchBodyConsumer&& consumer) : m_consumer(WTFMove(consumer)) { }
@@ -130,4 +134,9 @@ class FetchBody {
130134
RefPtr<ReadableStream> m_readableStream;
131135
};
132136

137+
structFetchBodyWithType {
138+
FetchBody body;
139+
String type;
140+
};
141+
133142
}// namespace WebCore

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp