Commit 03f68472 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Stringify RequestInit.body

As specified, RequestInit.body should be stringified, i.e.,
{toString(): () => 'hi!'} should be treated as same as 'hi!'.

Bug: 831076
Change-Id: I4118c0faa9535d62b3db2529bf23716fdc25a997
Reviewed-on: https://chromium-review.googlesource.com/1004561Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550523}
parent 6f874680
......@@ -43,7 +43,7 @@
//not equals: cannot guess formData exact value
assert_true( bodyAsText.search(expectedTextBody) > -1, "Retrieve and verify request body");
});
}, "Initialize Request's body with " + bodyType);
}, `Initialize Request's body with "${body}", ${bodyType}`);
}
var blob = new Blob(["This is a blob"], {type: "application/octet-binary"});
......@@ -56,6 +56,7 @@
checkRequestInit(blob, "application/octet-binary", "This is a blob");
checkRequestInit(formaData, "multipart/form-data", "name=\"name\"\r\n\r\nvalue");
checkRequestInit(usvString, "text/plain;charset=UTF-8", "This is a USVString");
checkRequestInit({toString: () => "hi!"}, "text/plain;charset=UTF-8", "hi!");
// Ensure test does not time out in case of missing URLSearchParams support.
if (window.URLSearchParams) {
......
......@@ -276,11 +276,13 @@ void RequestInit::SetUpBody(ExecutionContext* context,
content_type_ =
AtomicString("application/x-www-form-urlencoded;charset=UTF-8");
body_ = new FormDataBytesConsumer(context, std::move(form_data));
} else if (v8_body->IsString()) {
} else {
String string = NativeValueTraits<IDLUSVString>::NativeValue(
isolate, v8_body, exception_state);
if (exception_state.HadException())
return;
content_type_ = "text/plain;charset=UTF-8";
body_ =
new FormDataBytesConsumer(NativeValueTraits<IDLUSVString>::NativeValue(
isolate, v8_body, exception_state));
body_ = new FormDataBytesConsumer(string);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment