commit 40ee7faa991c2375d42f8152e4ebe642fb2ca33d
parent e08316caef6c9d264b2e002c0ee16b30fe7e6256
Author: Adam Vandolder <avandolder@mozilla.com>
Date: Thu, 16 Oct 2025 14:29:42 +0000
Bug 1994558 - Check for HasActiveDocument before getting state in NavigationHistoryEntry::GetState. r=dom-core,farre
Differential Revision: https://phabricator.services.mozilla.com/D268801
Diffstat:
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/dom/navigation/NavigationDestination.cpp b/dom/navigation/NavigationDestination.cpp
@@ -90,6 +90,7 @@ void NavigationDestination::GetState(JSContext* aCx,
// the best we can do is just re-throw the NS_ERROR_DOM_DATA_CLONE_ERR. When
// nsStructuredCloneContainer::DeserializeToJsval throws better exceptions
// this should too.
+ // See also: NavigationHistoryEntry::GetState
aRv.Throw(rv);
return;
}
diff --git a/dom/navigation/NavigationHistoryEntry.cpp b/dom/navigation/NavigationHistoryEntry.cpp
@@ -107,18 +107,24 @@ bool NavigationHistoryEntry::SameDocument() const {
void NavigationHistoryEntry::GetState(JSContext* aCx,
JS::MutableHandle<JS::Value> aResult,
ErrorResult& aRv) const {
- if (!mSHInfo) {
+ // Step 1
+ aResult.setUndefined();
+ if (!HasActiveDocument()) {
return;
}
+
+ // Step 2
RefPtr<nsIStructuredCloneContainer> state = mSHInfo->GetNavigationAPIState();
if (!state) {
- aResult.setUndefined();
return;
}
-
nsresult rv = state->DeserializeToJsval(aCx, aResult);
if (NS_FAILED(rv)) {
- // TODO change this to specific exception
+ // nsStructuredCloneContainer::DeserializeToJsval suppresses exceptions, so
+ // the best we can do is just re-throw the NS_ERROR_DOM_DATA_CLONE_ERR. When
+ // nsStructuredCloneContainer::DeserializeToJsval throws better exceptions
+ // this should too.
+ // See also: NavigationDestination::GetState
aRv.Throw(rv);
}
}