diff --git a/dom/localstorage/ActorsParent.cpp b/dom/localstorage/ActorsParent.cpp index 0332c1908b3a..d5c189d29be8 100644 --- a/dom/localstorage/ActorsParent.cpp +++ b/dom/localstorage/ActorsParent.cpp @@ -7539,6 +7539,7 @@ void PrepareDatastoreOp::GetResponse(LSRequestResponse& aResponse) { LSRequestPrepareDatastoreResponse prepareDatastoreResponse; prepareDatastoreResponse.databaseChildEndpoint() = std::move(childEndpoint); + prepareDatastoreResponse.invalidated() = mInvalidated; aResponse = std::move(prepareDatastoreResponse); } diff --git a/dom/localstorage/LSObject.cpp b/dom/localstorage/LSObject.cpp index 5460e85d7914..0c75da06f73c 100644 --- a/dom/localstorage/LSObject.cpp +++ b/dom/localstorage/LSObject.cpp @@ -946,6 +946,11 @@ nsresult LSObject::EnsureDatabase() { glean::ls_preparelsdatabase::processing_time.StopAndAccumulate( std::move(latencyTimerId)); + if (prepareDatastoreResponse.invalidated()) { + database->RequestAllowToClose(); + return NS_ERROR_ABORT; + } + mDatabase = std::move(database); return NS_OK; diff --git a/dom/localstorage/PBackgroundLSRequest.ipdl b/dom/localstorage/PBackgroundLSRequest.ipdl index fd498639883a..f17ba3500fe6 100644 --- a/dom/localstorage/PBackgroundLSRequest.ipdl +++ b/dom/localstorage/PBackgroundLSRequest.ipdl @@ -18,6 +18,7 @@ struct LSRequestPreloadDatastoreResponse struct LSRequestPrepareDatastoreResponse { Endpoint databaseChildEndpoint; + bool invalidated; }; struct LSRequestPrepareObserverResponse diff --git a/dom/localstorage/test/unit/slowDatabaseInitialization_child.js b/dom/localstorage/test/unit/slowDatabaseInitialization_child.js index f20d38b53ab5..b526afdccef7 100644 --- a/dom/localstorage/test/unit/slowDatabaseInitialization_child.js +++ b/dom/localstorage/test/unit/slowDatabaseInitialization_child.js @@ -16,6 +16,11 @@ add_task(async function testSteps() { const storage = LocalStorageUtils.createStorage(principal); - // XXX This should throw! - storage.getItem("foo"); + try { + storage.getItem("foo"); + ok(false, "Should have thrown"); + } catch (e) { + ok(true, "Should have thrown"); + Assert.strictEqual(e.result, Cr.NS_ERROR_ABORT, "Threw right result code"); + } });