Bug 1270357 Expose PYTHON from build config to test r?kmag draft
authorAndrew Swan <aswan@mozilla.com>
Fri, 20 May 2016 15:28:05 -0700
changeset 369246 79e24f10ab589d31e3a0f89ac6624b3029606aa0
parent 368448 947c6b8e19ef5290658d86edd545f37f3713749b
child 369247 2f55b496853b3d6c20e4d93ddf146c78895b0569
push id18808
push useraswan@mozilla.com
push dateFri, 20 May 2016 22:31:14 +0000
reviewerskmag
bugs1270357
milestone49.0a1
Bug 1270357 Expose PYTHON from build config to test r?kmag MozReview-Commit-ID: 1fPAdlgxeC0
.eslintignore
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/moz.build
toolkit/components/extensions/test/mochitest/test_constants.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -209,16 +209,17 @@ toolkit/components/osfile/**
 # External code:
 toolkit/components/microformats/test/**
 toolkit/components/reader/Readability.js
 toolkit/components/reader/JSDOMParser.js
 
 # Uses preprocessing
 toolkit/content/widgets/videocontrols.xml
 toolkit/content/widgets/wizard.xml
+toolkit/components/extensions/test/mochitest/test_constants.js
 toolkit/components/jsdownloads/src/DownloadIntegration.jsm
 toolkit/components/search/nsSearchService.js
 toolkit/components/url-classifier/**
 toolkit/components/urlformatter/nsURLFormatter.js
 toolkit/identity/FirefoxAccounts.jsm
 toolkit/modules/AppConstants.jsm
 toolkit/mozapps/downloads/nsHelperAppDlg.js
 toolkit/mozapps/extensions/internal/AddonConstants.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -143,16 +143,17 @@ let gContextId = 0;
 class BaseContext {
   constructor(extensionId) {
     this.onClose = new Set();
     this.checkedLastError = false;
     this._lastError = null;
     this.contextId = ++gContextId;
     this.unloaded = false;
     this.extensionId = extensionId;
+    this.sandbox = null;
   }
 
   get cloneScope() {
     throw new Error("Not implemented");
   }
 
   get principal() {
     throw new Error("Not implemented");
@@ -341,16 +342,30 @@ class BaseContext {
             } else {
               this.runSafeWithoutClone(reject, this.normalizeError(value));
             }
           });
       });
     }
   }
 
+  // Safely do JSON.stringify() on data coming from an extension.
+  // This calls JSON.stringify() in a sandbox that has the same origin
+  // as the extension so that things like wrapped natives and toJSON()
+  // method get handled properly.
+  jsonStringify(data) {
+    if (this.jsonSandbox == null) {
+      this.jsonSandbox = new Cu.Sandbox(this.cloneScope, {sameZoneAs: this.cloneScope});
+//      this.jsonSandbox = new Cu.Sandbox(this.principal, {sameZoneAs: this.cloneScope});
+//      this.jsonSandbox = new Cu.Sandbox(this.principal, {wantXrays: false});
+    }
+
+    return Cu.waiveXrays(this.jsonSandbox.JSON).stringify(data);
+  }
+
   unload() {
     this.unloaded = true;
 
     MessageChannel.abortResponses({
       extensionId: this.extensionId,
       contextId: this.contextId,
     });
 
--- a/toolkit/components/extensions/moz.build
+++ b/toolkit/components/extensions/moz.build
@@ -17,8 +17,14 @@ EXTRA_JS_MODULES += [
 
 DIRS += ['schemas']
 
 JAR_MANIFESTS += ['jar.mn']
 
 MOCHITEST_MANIFESTS += ['test/mochitest/mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['test/mochitest/chrome.ini']
 XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini']
+
+DEFINES['PYTHON'] = CONFIG['PYTHON']
+OBJDIR_PP_FILES._tests.testing.mochitest.chrome.toolkit.components.extensions.test.mochitest += [
+    'test/mochitest/test_constants.js',
+]
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_constants.js
@@ -0,0 +1,5 @@
+#filter substitution
+
+"use strict";
+
+this.PYTHON = String.raw`@PYTHON@`;