Bug 1401236 - Don't reread already loaded data in `JSONFile#load`. r?Paolo draft
authorKit Cambridge <kit@yakshaving.ninja>
Tue, 19 Sep 2017 09:59:27 -0700
changeset 667056 83b224667e81fba2c3dc53fcdb319d838a4c0ac5
parent 659873 c959327c6b75cd4930a6ea087583c38b805e7524
child 732286 752ba3b011780b3a076b978017208ea9ac90b413
push id80601
push userbmo:kit@mozilla.com
push dateTue, 19 Sep 2017 17:01:54 +0000
reviewersPaolo
bugs1401236
milestone57.0a1
Bug 1401236 - Don't reread already loaded data in `JSONFile#load`. r?Paolo 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;