Bug 1270357 Expose PYTHON from build config to test r?kmag
MozReview-Commit-ID: 1fPAdlgxeC0
--- 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@`;