зеркало из https://github.com/mozilla/gecko-dev.git
Bug 661582: XHR.response should return a Blob, not a File. r=sicking
This commit is contained in:
Родитель
5d3956e4f1
Коммит
941e3135b3
|
@ -1620,9 +1620,21 @@ void nsXMLHttpRequest::CreateResponseBlob(nsIRequest *request)
|
|||
if (cc) {
|
||||
cc->GetCacheToken(getter_AddRefs(cacheToken));
|
||||
}
|
||||
mResponseBlob = new nsDOMFile(file,
|
||||
NS_ConvertASCIItoUTF16(contentType),
|
||||
cacheToken);
|
||||
|
||||
NS_ConvertASCIItoUTF16 wideContentType(contentType);
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> blob =
|
||||
new nsDOMFile(file, wideContentType, cacheToken);
|
||||
|
||||
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
|
||||
// The response blob here should not be a File object, it should only
|
||||
// be a Blob. Unfortunately, because nsDOMFile has grown through
|
||||
// accretion over the years and is in dangerous need of a refactoring,
|
||||
// slicing it is the easiest way to get there ...
|
||||
PRUint64 size = 0;
|
||||
blob->GetSize(&size);
|
||||
blob->MozSlice(0, size, wideContentType, 2, getter_AddRefs(mResponseBlob));
|
||||
|
||||
mResponseBody.Truncate();
|
||||
mResponseBodyUnicode.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
|
@ -1893,9 +1905,20 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
|
|||
void *blobData = PR_Malloc(blobLen);
|
||||
if (blobData) {
|
||||
memcpy(blobData, mResponseBody.BeginReading(), blobLen);
|
||||
mResponseBlob =
|
||||
|
||||
NS_ConvertASCIItoUTF16 wideContentType(contentType);
|
||||
nsCOMPtr<nsIDOMBlob> blob =
|
||||
new nsDOMMemoryFile(blobData, blobLen, EmptyString(),
|
||||
NS_ConvertASCIItoUTF16(contentType));
|
||||
wideContentType);
|
||||
|
||||
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
|
||||
// The response blob here should not be a File object, it should only
|
||||
// be a Blob. Unfortunately, because nsDOMFile has grown through
|
||||
// accretion over the years and is in dangerous need of a refactoring,
|
||||
// slicing it is the easiest way to get there ...
|
||||
blob->MozSlice(0, blobLen, wideContentType,
|
||||
2, getter_AddRefs(mResponseBlob));
|
||||
|
||||
mResponseBody.Truncate();
|
||||
}
|
||||
NS_ASSERTION(mResponseBodyUnicode.IsVoid(),
|
||||
|
|
|
@ -160,6 +160,8 @@ checkResponseTextAccessThrows(xhr);
|
|||
checkResponseXMLAccessThrows(xhr);
|
||||
b = xhr.response;
|
||||
ok(b, "should have a non-null blob");
|
||||
ok(b instanceof Blob, "should be a Blob");
|
||||
ok(!(b instanceof File), "should not be a File");
|
||||
is(b.size, "hello pass\n".length, "wrong blob size");
|
||||
|
||||
var fr = new FileReader();
|
||||
|
|
Загрузка…
Ссылка в новой задаче