зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1109574 - Check for null body before setting bodyUsed in Request constructor. r=bkelly
--HG-- extra : transplant_source : %07%B8%B0%D1%ED%D4%C6N%09%09%86%04g%BD%ECs%B2%C6%09%18
This commit is contained in:
Родитель
b33db7c618
Коммит
992f9b1a98
|
@ -58,12 +58,17 @@ Request::Constructor(const GlobalObject& aGlobal,
|
|||
|
||||
if (aInput.IsRequest()) {
|
||||
nsRefPtr<Request> inputReq = &aInput.GetAsRequest();
|
||||
if (inputReq->BodyUsed()) {
|
||||
aRv.ThrowTypeError(MSG_REQUEST_BODY_CONSUMED_ERROR);
|
||||
return nullptr;
|
||||
nsCOMPtr<nsIInputStream> body;
|
||||
inputReq->GetBody(getter_AddRefs(body));
|
||||
if (body) {
|
||||
if (inputReq->BodyUsed()) {
|
||||
aRv.ThrowTypeError(MSG_REQUEST_BODY_CONSUMED_ERROR);
|
||||
return nullptr;
|
||||
} else {
|
||||
inputReq->SetBodyUsed();
|
||||
}
|
||||
}
|
||||
|
||||
inputReq->SetBodyUsed();
|
||||
request = inputReq->GetInternalRequest();
|
||||
} else {
|
||||
request = new InternalRequest();
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
function ok(a, msg) {
|
||||
dump("OK: " + !!a + " => " + a + " " + msg + "\n");
|
||||
postMessage({type: 'status', status: !!a, msg: a + ": " + msg });
|
||||
}
|
||||
|
||||
function is(a, b, msg) {
|
||||
dump("IS: " + (a===b) + " => " + a + " | " + b + " " + msg + "\n");
|
||||
postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
|
||||
}
|
||||
|
||||
|
@ -69,6 +67,16 @@ function testSimpleUrlParse() {
|
|||
is(req.url, (new URL("/file.html", self.location.href)).href, "URL parser should be used to resolve Request URL");
|
||||
}
|
||||
|
||||
// Bug 1109574 - Passing a Request with null body should keep bodyUsed unset.
|
||||
function testBug1109574() {
|
||||
var r1 = new Request("");
|
||||
is(r1.bodyUsed, false, "Initial value of bodyUsed should be false");
|
||||
var r2 = new Request(r1);
|
||||
is(r1.bodyUsed, false, "Request with null body should not have bodyUsed set");
|
||||
// This should succeed.
|
||||
var r3 = new Request(r1);
|
||||
}
|
||||
|
||||
function testMethod() {
|
||||
var allowed = ["delete", "get", "head", "options", "post", "put"];
|
||||
for (var i = 0; i < allowed.length; ++i) {
|
||||
|
@ -205,6 +213,7 @@ onmessage = function() {
|
|||
testSimpleUrlParse();
|
||||
testUrlFragment();
|
||||
testMethod();
|
||||
testBug1109574();
|
||||
|
||||
Promise.resolve()
|
||||
.then(testBodyCreation)
|
||||
|
|
Загрузка…
Ссылка в новой задаче