Backed out changeset 133c9084af25 (bug 1793736) for causing failures at browser_navigationPreload_read_after_respondWith.js.

This commit is contained in:
Butkovits Atila 2022-11-21 19:49:41 +02:00
parent b284155a5d
commit bf0a7fa012
7 changed files with 54 additions and 64 deletions

View file

@ -6,7 +6,6 @@
#include "Fetch.h" #include "Fetch.h"
#include "js/RootingAPI.h"
#include "js/Value.h" #include "js/Value.h"
#include "mozilla/CycleCollectedJSContext.h" #include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
@ -55,18 +54,15 @@ namespace mozilla::dom {
namespace { namespace {
void AbortStream(JSContext* aCx, ReadableStream* aReadableStream, void AbortStream(JSContext* aCx, ReadableStream* aReadableStream,
ErrorResult& aRv, JS::Handle<JS::Value> aReasonDetails) { ErrorResult& aRv) {
if (aReadableStream->State() != ReadableStream::ReaderState::Readable) { if (aReadableStream->State() != ReadableStream::ReaderState::Readable) {
return; return;
} }
JS::Rooted<JS::Value> value(aCx, aReasonDetails); RefPtr<DOMException> e = DOMException::Create(NS_ERROR_DOM_ABORT_ERR);
JS::Rooted<JS::Value> value(aCx);
if (aReasonDetails.isUndefined()) { if (!GetOrCreateDOMReflector(aCx, e, &value)) {
RefPtr<DOMException> e = DOMException::Create(NS_ERROR_DOM_ABORT_ERR); return;
if (!GetOrCreateDOMReflector(aCx, e, &value)) {
return;
}
} }
ReadableStreamError(aCx, aReadableStream, value, aRv); ReadableStreamError(aCx, aReadableStream, value, aRv);
@ -284,8 +280,7 @@ class WorkerFetchResolver final : public FetchDriverObserver {
void OnResponseAvailableInternal( void OnResponseAvailableInternal(
SafeRefPtr<InternalResponse> aResponse) override; SafeRefPtr<InternalResponse> aResponse) override;
void OnResponseEnd(FetchDriverObserver::EndReason aReason, void OnResponseEnd(FetchDriverObserver::EndReason aReason) override;
JS::Handle<JS::Value> aReasonDetails) override;
bool NeedOnDataAvailable() override; bool NeedOnDataAvailable() override;
@ -361,14 +356,9 @@ class MainThreadFetchResolver final : public FetchDriverObserver {
void SetLoadGroup(nsILoadGroup* aLoadGroup) { mLoadGroup = aLoadGroup; } void SetLoadGroup(nsILoadGroup* aLoadGroup) { mLoadGroup = aLoadGroup; }
void OnResponseEnd(FetchDriverObserver::EndReason aReason, void OnResponseEnd(FetchDriverObserver::EndReason aReason) override {
JS::Handle<JS::Value> aReasonDetails) override {
if (aReason == eAborted) { if (aReason == eAborted) {
if (!aReasonDetails.isUndefined()) { mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
mPromise->MaybeReject(aReasonDetails);
} else {
mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}
} }
mFetchObserver = nullptr; mFetchObserver = nullptr;
@ -521,14 +511,8 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
if (signalImpl && signalImpl->Aborted()) { if (signalImpl && signalImpl->Aborted()) {
// Already aborted signal rejects immediately. // Already aborted signal rejects immediately.
JS::Rooted<JS::Value> reason(cx, signalImpl->RawReason()); aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
if (reason.get().isUndefined()) { return nullptr;
aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
return nullptr;
}
p->MaybeReject(reason);
return p.forget();
} }
JS::Realm* realm = JS::GetCurrentRealmOrNull(cx); JS::Realm* realm = JS::GetCurrentRealmOrNull(cx);
@ -881,8 +865,8 @@ void WorkerFetchResolver::OnDataAvailable() {
Unused << r->Dispatch(); Unused << r->Dispatch();
} }
void WorkerFetchResolver::OnResponseEnd(FetchDriverObserver::EndReason aReason, void WorkerFetchResolver::OnResponseEnd(
JS::Handle<JS::Value> aReasonDetails) { FetchDriverObserver::EndReason aReason) {
AssertIsOnMainThread(); AssertIsOnMainThread();
MutexAutoLock lock(mPromiseProxy->Lock()); MutexAutoLock lock(mPromiseProxy->Lock());
if (mPromiseProxy->CleanedUp()) { if (mPromiseProxy->CleanedUp()) {
@ -891,8 +875,6 @@ void WorkerFetchResolver::OnResponseEnd(FetchDriverObserver::EndReason aReason,
FlushConsoleReport(); FlushConsoleReport();
Unused << aReasonDetails;
RefPtr<WorkerFetchResponseEndRunnable> r = new WorkerFetchResponseEndRunnable( RefPtr<WorkerFetchResponseEndRunnable> r = new WorkerFetchResponseEndRunnable(
mPromiseProxy->GetWorkerPrivate(), this, aReason); mPromiseProxy->GetWorkerPrivate(), this, aReason);
@ -1211,20 +1193,9 @@ already_AddRefed<Promise> FetchBody<Derived>::ConsumeBody(
RefPtr<AbortSignalImpl> signalImpl = RefPtr<AbortSignalImpl> signalImpl =
DerivedClass()->GetSignalImplToConsumeBody(); DerivedClass()->GetSignalImplToConsumeBody();
if (signalImpl && signalImpl->Aborted()) { if (signalImpl && signalImpl->Aborted()) {
JS::Rooted<JS::Value> abortReason(aCx, signalImpl->RawReason()); aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
return nullptr;
if (abortReason.get().isUndefined()) {
aRv.Throw(NS_ERROR_DOM_ABORT_ERR);
return nullptr;
}
nsCOMPtr<nsIGlobalObject> go = DerivedClass()->GetParentObject();
RefPtr<Promise> promise = Promise::Create(go, aRv);
promise->MaybeReject(abortReason);
return promise.forget();
} }
bool bodyUsed = GetBodyUsed(aRv); bool bodyUsed = GetBodyUsed(aRv);
@ -1369,8 +1340,7 @@ void FetchBody<Derived>::SetReadableStreamBody(JSContext* aCx,
bool aborted = signalImpl->Aborted(); bool aborted = signalImpl->Aborted();
if (aborted) { if (aborted) {
IgnoredErrorResult result; IgnoredErrorResult result;
JS::Rooted<JS::Value> abortReason(aCx, signalImpl->RawReason()); AbortStream(aCx, mReadableStreamBody, result);
AbortStream(aCx, mReadableStreamBody, result, abortReason);
if (NS_WARN_IF(result.Failed())) { if (NS_WARN_IF(result.Failed())) {
return; return;
} }
@ -1425,8 +1395,7 @@ already_AddRefed<ReadableStream> FetchBody<Derived>::GetBody(JSContext* aCx,
RefPtr<AbortSignalImpl> signalImpl = DerivedClass()->GetSignalImpl(); RefPtr<AbortSignalImpl> signalImpl = DerivedClass()->GetSignalImpl();
if (signalImpl) { if (signalImpl) {
if (signalImpl->Aborted()) { if (signalImpl->Aborted()) {
JS::Rooted<JS::Value> abortReason(aCx, signalImpl->RawReason()); AbortStream(aCx, body, aRv);
AbortStream(aCx, body, aRv, abortReason);
if (NS_WARN_IF(aRv.Failed())) { if (NS_WARN_IF(aRv.Failed())) {
return nullptr; return nullptr;
} }
@ -1530,9 +1499,7 @@ void FetchBody<Derived>::RunAbortAlgorithm() {
RefPtr<ReadableStream> body(mReadableStreamBody); RefPtr<ReadableStream> body(mReadableStreamBody);
IgnoredErrorResult result; IgnoredErrorResult result;
AbortStream(cx, body, result);
JS::Rooted<JS::Value> abortReason(cx, Signal()->RawReason());
AbortStream(cx, body, result, abortReason);
} }
template void FetchBody<Request>::RunAbortAlgorithm(); template void FetchBody<Request>::RunAbortAlgorithm();

View file

@ -4,7 +4,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "js/Value.h"
#include "mozilla/DebugOnly.h" #include "mozilla/DebugOnly.h"
#include "mozilla/dom/FetchDriver.h" #include "mozilla/dom/FetchDriver.h"
@ -589,7 +588,7 @@ nsresult FetchDriver::HttpFetch(
secFlags |= nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS; secFlags |= nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS;
} }
// This handles the use credentials flag in "HTTP // This is handles the use credentials flag in "HTTP
// network or cache fetch" in the spec and decides whether to transmit // network or cache fetch" in the spec and decides whether to transmit
// cookies and other identifying information. // cookies and other identifying information.
if (mRequest->GetCredentialsMode() == RequestCredentials::Include) { if (mRequest->GetCredentialsMode() == RequestCredentials::Include) {
@ -932,8 +931,7 @@ void FetchDriver::FailWithNetworkError(nsresult rv) {
// mObserver could be null after OnResponseAvailable(). // mObserver could be null after OnResponseAvailable().
if (mObserver) { if (mObserver) {
mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking, mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking);
JS::UndefinedHandleValue);
mObserver = nullptr; mObserver = nullptr;
} }
@ -1462,8 +1460,7 @@ void FetchDriver::FinishOnStopRequest(
} }
if (mObserver) { if (mObserver) {
mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking, mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking);
JS::UndefinedHandleValue);
mObserver = nullptr; mObserver = nullptr;
} }
@ -1637,8 +1634,7 @@ void FetchDriver::RunAbortAlgorithm() {
#ifdef DEBUG #ifdef DEBUG
mResponseAvailableCalled = true; mResponseAvailableCalled = true;
#endif #endif
JS::Rooted<JS::Value> reason(RootingCx(), Signal()->RawReason()); mObserver->OnResponseEnd(FetchDriverObserver::eAborted);
mObserver->OnResponseEnd(FetchDriverObserver::eAborted, reason);
mObserver = nullptr; mObserver = nullptr;
} }

View file

@ -59,8 +59,7 @@ class FetchDriverObserver {
eByNetworking, eByNetworking,
}; };
virtual void OnResponseEnd(EndReason aReason, virtual void OnResponseEnd(EndReason aReason){};
JS::Handle<JS::Value> aReasonDetails){};
nsIConsoleReportCollector* GetReporter() const { return mReporter; } nsIConsoleReportCollector* GetReporter() const { return mReporter; }

View file

@ -208,8 +208,7 @@ void FetchService::FetchInstance::Cancel() {
} }
void FetchService::FetchInstance::OnResponseEnd( void FetchService::FetchInstance::OnResponseEnd(
FetchDriverObserver::EndReason aReason, FetchDriverObserver::EndReason aReason) {
JS::Handle<JS::Value> aReasonDetails) {
FETCH_LOG(("FetchInstance::OnResponseEnd [%p]", this)); FETCH_LOG(("FetchInstance::OnResponseEnd [%p]", this));
if (aReason == eAborted) { if (aReason == eAborted) {
FETCH_LOG(("FetchInstance::OnResponseEnd end with eAborted")); FETCH_LOG(("FetchInstance::OnResponseEnd end with eAborted"));

View file

@ -116,8 +116,7 @@ class FetchService final : public nsIObserver {
void Cancel(); void Cancel();
/* FetchDriverObserver interface */ /* FetchDriverObserver interface */
void OnResponseEnd(FetchDriverObserver::EndReason aReason, void OnResponseEnd(FetchDriverObserver::EndReason aReason) override;
JS::Handle<JS::Value> aReasonDetails) override;
void OnResponseAvailableInternal( void OnResponseAvailableInternal(
SafeRefPtr<InternalResponse> aResponse) override; SafeRefPtr<InternalResponse> aResponse) override;
bool NeedOnDataAvailable() override; bool NeedOnDataAvailable() override;

View file

@ -13,6 +13,12 @@
expected: expected:
if (os == "linux") and not fission: [PASS, FAIL] if (os == "linux") and not fission: [PASS, FAIL]
[Aborting rejects with abort reason]
expected: FAIL
[Signal on request object should also have abort reason]
expected: FAIL
[general.any.html] [general.any.html]
[Stream will not error if body is empty. It's closed with an empty queue before it errors.] [Stream will not error if body is empty. It's closed with an empty queue before it errors.]
@ -25,6 +31,12 @@
expected: expected:
if (os == "linux") and debug and not fission and not swgl: [PASS, FAIL] if (os == "linux") and debug and not fission and not swgl: [PASS, FAIL]
[Aborting rejects with abort reason]
expected: FAIL
[Signal on request object should also have abort reason]
expected: FAIL
[general.any.sharedworker.html] [general.any.sharedworker.html]
[Stream will not error if body is empty. It's closed with an empty queue before it errors.] [Stream will not error if body is empty. It's closed with an empty queue before it errors.]
@ -38,6 +50,12 @@
if (os == "linux") and not swgl and fission and not debug: [PASS, FAIL] if (os == "linux") and not swgl and fission and not debug: [PASS, FAIL]
if (os == "linux") and not swgl and not fission and debug: [PASS, FAIL] if (os == "linux") and not swgl and not fission and debug: [PASS, FAIL]
[Aborting rejects with abort reason]
expected: FAIL
[Signal on request object should also have abort reason]
expected: FAIL
[Stream errors once aborted, after reading. Underlying connection closed.] [Stream errors once aborted, after reading. Underlying connection closed.]
expected: expected:
if (os == "linux") and debug and not fission and not swgl: [PASS, FAIL] if (os == "linux") and debug and not fission and not swgl: [PASS, FAIL]
@ -61,3 +79,9 @@
expected: expected:
if (os == "linux") and not swgl and not fission and not debug: [PASS, FAIL] if (os == "linux") and not swgl and not fission and not debug: [PASS, FAIL]
if (os == "linux") and swgl: [PASS, FAIL] if (os == "linux") and swgl: [PASS, FAIL]
[Aborting rejects with abort reason]
expected: FAIL
[Signal on request object should also have abort reason]
expected: FAIL

View file

@ -1,7 +1,13 @@
[serviceworker-intercepted.https.html] [serviceworker-intercepted.https.html]
expected: TIMEOUT expected: TIMEOUT
[fetch() rejects with abort reason]
expected: FAIL
[Service Worker can observe the fetch abort and associated abort reason] [Service Worker can observe the fetch abort and associated abort reason]
expected: TIMEOUT expected: TIMEOUT
[Abort reason serialization happens on abort] [Abort reason serialization happens on abort]
expected: NOTRUN expected: NOTRUN
[fetch() response body has abort reason]
expected: FAIL