Bug 1381687: Store and transfer schema JSON in structured clone blobs. r=aswan (not a CLOSED TREE)
authorKris Maglione <maglione.k@gmail.com>
Mon, 17 Jul 2017 15:33:54 -0700
changeset 418637 7066bee0381d62764ba8fc55aa4270eb5a241b20
parent 418636 718e6989c87212cee3b2eb445f9f9982e23e2c39
child 418638 8b89d684f633977acdd317654d040a86ddef466b
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1381687
milestone56.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 1381687: Store and transfer schema JSON in structured clone blobs. r=aswan (not a CLOSED TREE) MozReview-Commit-ID: FMSbSB1hC3F
toolkit/components/extensions/Schemas.jsm
--- a/toolkit/components/extensions/Schemas.jsm
+++ b/toolkit/components/extensions/Schemas.jsm
@@ -62,16 +62,22 @@ function readJSON(url) {
         resolve(JSON.parse(text));
       } catch (e) {
         reject(e);
       }
     });
   });
 }
 
+async function readJSONAndBlobbify(url) {
+  let json = await readJSON(url);
+
+  return new StructuredCloneHolder(json);
+}
+
 /**
  * Defines a lazy getter for the given property on the given object. Any
  * security wrappers are waived on the object before the property is
  * defined, and the getter and setter methods are wrapped for the target
  * scope.
  *
  * The given getter function is guaranteed to be called only once, even
  * if the target scope retrieves the wrapped getter from the property
@@ -2625,19 +2631,19 @@ this.Schemas = {
     this._needFlush = true;
 
     Object.defineProperty(this, "rootNamespace", {
       enumerable: true,
       configurable: true,
       value: new Namespace("", []),
     });
 
-    for (let json of this.schemaJSON.values()) {
+    for (let blob of this.schemaJSON.values()) {
       try {
-        this.loadSchema(json);
+        this.loadSchema(blob.deserialize(global));
       } catch (e) {
         Cu.reportError(e);
       }
     }
 
     return this.rootNamespace;
   },
 
@@ -2654,39 +2660,39 @@ this.Schemas = {
       this._loadCachedSchemasPromise = StartupCache.schemas.getAll().then(results => {
         return results;
       });
     }
 
     return this._loadCachedSchemasPromise;
   },
 
-  addSchema(url, json) {
-    this.schemaJSON.set(url, json);
+  addSchema(url, schema) {
+    this.schemaJSON.set(url, schema);
 
     let data = Services.ppmm.initialProcessData;
     data["Extension:Schemas"] = this.schemaJSON;
 
-    Services.ppmm.broadcastAsyncMessage("Schema:Add", {url, schema: json});
+    Services.ppmm.broadcastAsyncMessage("Schema:Add", {url, schema});
 
     this.flushSchemas();
   },
 
   async load(url) {
     if (!isParentProcess) {
       return;
     }
 
     let schemaCache = await this.loadCachedSchemas();
 
-    let json = (schemaCache.get(url) ||
-                await StartupCache.schemas.get(url, readJSON));
+    let blob = (schemaCache.get(url) ||
+                await StartupCache.schemas.get(url, readJSONAndBlobbify));
 
     if (!this.schemaJSON.has(url)) {
-      this.addSchema(url, json);
+      this.addSchema(url, blob);
     }
   },
 
   unload(url) {
     this.schemaJSON.delete(url);
 
     let data = Services.ppmm.initialProcessData;
     data["Extension:Schemas"] = this.schemaJSON;