Bug 1401236 - Don't reread already loaded data in `JSONFile#load`. r?Gijs draft
authorKit Cambridge <kit@yakshaving.ninja>
Tue, 19 Sep 2017 09:59:27 -0700
changeset 667057 4befe71b082cd9755bc7a77068e4db4ef6e5c765
parent 659873 c959327c6b75cd4930a6ea087583c38b805e7524
child 732287 657d57a672034241eb3d41e07a1ad3ff3f67ee12
push id80602
push userbmo:kit@mozilla.com
push dateTue, 19 Sep 2017 17:02:42 +0000
reviewersGijs
bugs1401236
milestone57.0a1
Bug 1401236 - Don't reread already loaded data in `JSONFile#load`. r?Gijs MozReview-Commit-ID: AHD5G453GHM
toolkit/modules/JSONFile.jsm
--- a/toolkit/modules/JSONFile.jsm
+++ b/toolkit/modules/JSONFile.jsm
@@ -174,16 +174,20 @@ JSONFile.prototype = {
    * Loads persistent data from the file to memory.
    *
    * @return {Promise}
    * @resolves When the operation finished successfully.
    * @rejects JavaScript exception when dataPostProcessor fails. It never fails
    *          if there is no dataPostProcessor.
    */
   async load() {
+    if (this.dataReady) {
+      return;
+    }
+
     let data = {};
 
     try {
       let bytes = await OS.File.read(this.path, this._options);
 
       // If synchronous loading happened in the meantime, exit now.
       if (this.dataReady) {
         return;