Bug 1478787: Rebuild stale SharedMap on Has() call. r=erahm
authorKris Maglione <maglione.k@gmail.com>
Thu, 26 Jul 2018 13:23:54 -0700
changeset 530910 8068f2c5ad489441277268b53e337a5b1de790d0
parent 530909 a5c14dc63aa6449d97c1a73918b7b6fbf33735c0
child 530911 5fc15e9a69ec1824ff41b0ddcbb7743cf88ca309
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1478787
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1478787: Rebuild stale SharedMap on Has() call. r=erahm MozReview-Commit-ID: 5aFVBNQW4QR Differential Revision: https://phabricator.services.mozilla.com/D29398
dom/ipc/SharedMap.cpp
dom/ipc/tests/test_sharedMap.js
--- a/dom/ipc/SharedMap.cpp
+++ b/dom/ipc/SharedMap.cpp
@@ -40,16 +40,17 @@ SharedMap::SharedMap() : DOMEventTargetH
 SharedMap::SharedMap(nsIGlobalObject* aGlobal, const FileDescriptor& aMapFile,
                      size_t aMapSize, nsTArray<RefPtr<BlobImpl>>&& aBlobs)
     : DOMEventTargetHelper(aGlobal), mBlobImpls(std::move(aBlobs)) {
   mMapFile.reset(new FileDescriptor(aMapFile));
   mMapSize = aMapSize;
 }
 
 bool SharedMap::Has(const nsACString& aName) {
+  Unused << MaybeRebuild();
   return mEntries.Contains(aName);
 }
 
 void SharedMap::Get(JSContext* aCx, const nsACString& aName,
                     JS::MutableHandleValue aRetVal, ErrorResult& aRv) {
   auto res = MaybeRebuild();
   if (res.isErr()) {
     aRv.Throw(res.unwrapErr());
--- a/dom/ipc/tests/test_sharedMap.js
+++ b/dom/ipc/tests/test_sharedMap.js
@@ -21,16 +21,20 @@ async function readBlob(key, sharedData 
   await ExtensionUtils.promiseEvent(reader, "loadend");
   return reader.result;
 }
 
 function getKey(key, sharedData = Services.cpmm.sharedData) {
   return sharedData.get(key);
 }
 
+function hasKey(key, sharedData = Services.cpmm.sharedData) {
+  return sharedData.has(key);
+}
+
 function getContents(sharedMap = Services.cpmm.sharedData) {
   return {
     keys: Array.from(sharedMap.keys()),
     values: Array.from(sharedMap.values()),
     entries: Array.from(sharedMap.entries()),
     getValues: Array.from(sharedMap.keys(),
                           key => sharedMap.get(key)),
   };
@@ -193,16 +197,25 @@ add_task(async function test_sharedMap()
   checkContentMaps(oldExpected, true);
 
   info("Wait for an idle timeout. Check that changes are now visible in all children");
 
   await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
 
   checkParentMap(expected);
   await checkContentMaps(expected);
+
+  // Test that has() rebuilds map after a flush.
+  sharedData.set("grick", true);
+  sharedData.flush();
+  equal(await contentPage.spawn("grick", hasKey), true, "has() should see key after flush");
+
+  sharedData.set("grack", true);
+  sharedData.flush();
+  equal(await contentPage.spawn("gruck", hasKey), false, "has() should return false for nonexistent key");
 });
 
 add_task(async function test_blobs() {
   let {sharedData} = Services.ppmm;
 
   let text = [
     "The quick brown fox jumps over the lazy dog",
     "Lorem ipsum dolor sit amet, consectetur adipiscing elit",