Bug 1896475 - Make BodyConsumer::ConsumeType an enum class. r=saschanaz

Differential Revision: https://phabricator.services.mozilla.com/D210635
This commit is contained in:
Tom Schuster 2024-05-22 17:47:59 +00:00
Родитель 16a1e721b2
Коммит 3be41a4970
5 изменённых файлов: 29 добавлений и 29 удалений

Просмотреть файл

@ -498,7 +498,7 @@ void BodyConsumer::BeginConsumeBodyMainThread(ThreadSafeWorkerRef* aWorkerRef) {
return;
}
if (mConsumeType == CONSUME_BLOB) {
if (mConsumeType == ConsumeType::Blob) {
nsresult rv;
// If we're trying to consume a blob, and the request was for a blob URI,
@ -547,7 +547,7 @@ void BodyConsumer::BeginConsumeBodyMainThread(ThreadSafeWorkerRef* aWorkerRef) {
new ConsumeBodyDoneObserver(this, aWorkerRef);
nsCOMPtr<nsIStreamListener> listener;
if (mConsumeType == CONSUME_BLOB) {
if (mConsumeType == ConsumeType::Blob) {
listener = new MutableBlobStreamListener(mBlobStorageType, mBodyMimeType, p,
mMainThreadEventTarget);
} else {
@ -703,7 +703,7 @@ void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
ErrorResult error;
switch (mConsumeType) {
case CONSUME_ARRAYBUFFER: {
case ConsumeType::ArrayBuffer: {
JS::Rooted<JSObject*> arrayBuffer(cx);
BodyUtil::ConsumeArrayBuffer(cx, &arrayBuffer, aResultLength,
std::move(resultPtr), error);
@ -716,11 +716,11 @@ void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
}
break;
}
case CONSUME_BLOB: {
case ConsumeType::Blob: {
MOZ_CRASH("This should not happen.");
break;
}
case CONSUME_FORMDATA: {
case ConsumeType::FormData: {
nsCString data;
data.Adopt(reinterpret_cast<char*>(resultPtr.release()), aResultLength);
@ -731,13 +731,13 @@ void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
}
break;
}
case CONSUME_TEXT:
case ConsumeType::Text:
// fall through handles early exit.
case CONSUME_JSON: {
case ConsumeType::JSON: {
nsString decoded;
if (NS_SUCCEEDED(
BodyUtil::ConsumeText(aResultLength, resultPtr.get(), decoded))) {
if (mConsumeType == CONSUME_TEXT) {
if (mConsumeType == ConsumeType::Text) {
localPromise->MaybeResolve(decoded);
} else {
JS::Rooted<JS::Value> json(cx);
@ -762,7 +762,7 @@ void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
void BodyConsumer::ContinueConsumeBlobBody(BlobImpl* aBlobImpl,
bool aShuttingDown) {
AssertIsOnTargetThread();
MOZ_ASSERT(mConsumeType == CONSUME_BLOB);
MOZ_ASSERT(mConsumeType == ConsumeType::Blob);
if (mBodyConsumed) {
return;

Просмотреть файл

@ -29,12 +29,12 @@ class BodyConsumer final : public nsIObserver,
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
enum ConsumeType {
CONSUME_ARRAYBUFFER,
CONSUME_BLOB,
CONSUME_FORMDATA,
CONSUME_JSON,
CONSUME_TEXT,
enum class ConsumeType {
ArrayBuffer,
Blob,
FormData,
JSON,
Text,
};
/**
@ -48,15 +48,15 @@ class BodyConsumer final : public nsIObserver,
* @param aSignalImpl an AbortSignal object. Optional.
* @param aType the consume type.
* @param aBodyBlobURISpec this is used only if the consume type is
* CONSUME_BLOB. Optional.
* ConsumeType::Blob. Optional.
* @param aBodyLocalPath local path in case the blob is created from a local
* file. Used only by CONSUME_BLOB. Optional.
* @param aBodyMimeType the mime-type for blob. Used only by CONSUME_BLOB.
* Optional.
* file. Used only by ConsumeType::Blob. Optional.
* @param aBodyMimeType the mime-type for blob. Used only by
* ConsumeType::Blob. Optional.
* @param aMixedCaseMimeType is needed to get mixed case multipart
* boundary value to FormDataParser.
* @param aBlobStorageType Blobs can be saved in temporary file. This is the
* type of blob storage to use. Used only by CONSUME_BLOB.
* type of blob storage to use. Used only by ConsumeType::Blob.
* @param aRv An ErrorResult.
*/
static already_AddRefed<Promise> Create(

Просмотреть файл

@ -69,8 +69,8 @@ RefPtr<TPromise> FetchJSONStructure(Request* aRequest) {
// Parse the body into JSON, which must be done async
IgnoredErrorResult error;
RefPtr<Promise> jsonPromise = response->ConsumeBody(
aCx, BodyConsumer::ConsumeType::CONSUME_JSON, error);
RefPtr<Promise> jsonPromise =
response->ConsumeBody(aCx, BodyConsumer::ConsumeType::Blob, error);
if (NS_WARN_IF(error.Failed())) {
resultPromise->Reject(NS_ERROR_FAILURE, __func__);
return;

Просмотреть файл

@ -150,23 +150,23 @@ class FetchBody : public FetchBodyBase, public AbortFollower {
bool BodyUsed() const;
already_AddRefed<Promise> ArrayBuffer(JSContext* aCx, ErrorResult& aRv) {
return ConsumeBody(aCx, BodyConsumer::CONSUME_ARRAYBUFFER, aRv);
return ConsumeBody(aCx, BodyConsumer::ConsumeType::ArrayBuffer, aRv);
}
already_AddRefed<Promise> Blob(JSContext* aCx, ErrorResult& aRv) {
return ConsumeBody(aCx, BodyConsumer::CONSUME_BLOB, aRv);
return ConsumeBody(aCx, BodyConsumer::ConsumeType::Blob, aRv);
}
already_AddRefed<Promise> FormData(JSContext* aCx, ErrorResult& aRv) {
return ConsumeBody(aCx, BodyConsumer::CONSUME_FORMDATA, aRv);
return ConsumeBody(aCx, BodyConsumer::ConsumeType::FormData, aRv);
}
already_AddRefed<Promise> Json(JSContext* aCx, ErrorResult& aRv) {
return ConsumeBody(aCx, BodyConsumer::CONSUME_JSON, aRv);
return ConsumeBody(aCx, BodyConsumer::ConsumeType::JSON, aRv);
}
already_AddRefed<Promise> Text(JSContext* aCx, ErrorResult& aRv) {
return ConsumeBody(aCx, BodyConsumer::CONSUME_TEXT, aRv);
return ConsumeBody(aCx, BodyConsumer::ConsumeType::Text, aRv);
}
already_AddRefed<ReadableStream> GetBody(JSContext* aCx, ErrorResult& aRv);

Просмотреть файл

@ -257,11 +257,11 @@ size_t BindingJSObjectMallocBytes(Blob* aBlob) {
}
already_AddRefed<Promise> Blob::Text(ErrorResult& aRv) const {
return ConsumeBody(BodyConsumer::CONSUME_TEXT, aRv);
return ConsumeBody(BodyConsumer::ConsumeType::Text, aRv);
}
already_AddRefed<Promise> Blob::ArrayBuffer(ErrorResult& aRv) const {
return ConsumeBody(BodyConsumer::CONSUME_ARRAYBUFFER, aRv);
return ConsumeBody(BodyConsumer::ConsumeType::ArrayBuffer, aRv);
}
already_AddRefed<Promise> Blob::ConsumeBody(