haikuwebkit/LayoutTests/fetch/body-init.html

31 lines
874 B
HTML
Raw Permalink Normal View History

[Fetch API] TypeError when called with body === {} https://bugs.webkit.org/show_bug.cgi?id=173295 <rdar://problem/32746733> Patch by Youenn Fablet <youenn@apple.com> on 2017-06-21 Reviewed by Sam Weinig. Source/WebCore: Test: fetch/body-init.html Handling body of Request and Response using binding generator to correctly handle unions. The biggest change is that any value that is not a specific type in the union will match a String. This is matching WebIDL spec and Firefox behavior. Handling of ReadableStream bodies remains in JS builtin for Response. This allows easier handling cloning and consumption of body. Adding setBodyAsReadableStream since this is no longer handled by extractBody. * Modules/fetch/FetchBody.cpp: (WebCore::FetchBody::extract): Using Variant instead of JSC::JSValue. (WebCore::FetchBody::readableStreamBody): Introduced to handle the case of readable stream bodies. * Modules/fetch/FetchBody.h: * Modules/fetch/FetchBodyOwner.cpp: (WebCore::FetchBodyOwner::extractBody): * Modules/fetch/FetchBodyOwner.h: (WebCore::FetchBodyOwner::setBody): * Modules/fetch/FetchRequest.cpp: (WebCore::FetchRequest::setBody): Splitting setBody for ease of readability. (WebCore::FetchRequest::setBodyFromInputRequest): * Modules/fetch/FetchRequest.h: * Modules/fetch/FetchRequest.idl: * Modules/fetch/FetchRequest.js: (initializeFetchRequest): * Modules/fetch/FetchResponse.cpp: (WebCore::FetchResponse::initializeWith): (WebCore::FetchResponse::setBodyAsReadableStream): * Modules/fetch/FetchResponse.h: * Modules/fetch/FetchResponse.idl: * Modules/fetch/FetchResponse.js: (initializeFetchResponse): * WebCore.xcodeproj/project.pbxproj: * bindings/js/WebCoreBuiltinNames.h: LayoutTests: * fetch/body-init-expected.txt: Added. * fetch/body-init.html: Added. Canonical link: https://commits.webkit.org/190565@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@218677 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-06-22 04:31:12 +00:00
<!DOCTYPE html>
<script src='../resources/testharness.js'></script>
<script src='../resources/testharnessreport.js'></script>
<script>
promise_test(() => {
return new Response(1).text().then((text) => {
assert_equals(text, "1");
});
}, "Testing integer body passed to response");
promise_test(() => {
return new Response({}).text().then((text) => {
assert_equals(text, "[object Object]");
});
}, "Testing object body passed to response");
promise_test(() => {
return new Request("", {method: "POST", body: 1}).text().then((text) => {
assert_equals(text, "1");
});
}, "Testing integer body passed to request");
promise_test(() => {
return new Request("", {method: "POST", body: {}}).text().then((text) => {
assert_equals(text, "[object Object]");
});
}, "Testing object body passed to request");
</script>