Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const { utils: Cu } = Components; |
michael@0 | 6 | const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); |
michael@0 | 7 | const LoaderModule = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader; |
michael@0 | 8 | const { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {}); |
michael@0 | 9 | let { |
michael@0 | 10 | Loader, main, Module, Require, unload |
michael@0 | 11 | } = LoaderModule; |
michael@0 | 12 | |
michael@0 | 13 | let CURRENT_DIR = gTestPath.replace(/\/[^\/]*\.js$/,'/'); |
michael@0 | 14 | let loaders = []; |
michael@0 | 15 | |
michael@0 | 16 | // All tests are asynchronous. |
michael@0 | 17 | waitForExplicitFinish(); |
michael@0 | 18 | |
michael@0 | 19 | let gEnableLogging = Services.prefs.getBoolPref("devtools.debugger.log"); |
michael@0 | 20 | Services.prefs.setBoolPref("devtools.debugger.log", true); |
michael@0 | 21 | |
michael@0 | 22 | registerCleanupFunction(() => { |
michael@0 | 23 | info("finish() was called, cleaning up..."); |
michael@0 | 24 | loaders.forEach(unload); |
michael@0 | 25 | Services.prefs.setBoolPref("devtools.debugger.log", gEnableLogging); |
michael@0 | 26 | }); |
michael@0 | 27 | |
michael@0 | 28 | function makePaths (root) { |
michael@0 | 29 | return { |
michael@0 | 30 | './': CURRENT_DIR, |
michael@0 | 31 | '': 'resource://gre/modules/commonjs/' |
michael@0 | 32 | }; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | function makeLoader (options) { |
michael@0 | 36 | let { paths, globals } = options || {}; |
michael@0 | 37 | |
michael@0 | 38 | // We have to have `console` as a global, otherwise |
michael@0 | 39 | // many SDK modules will fail |
michael@0 | 40 | // bug 961252 |
michael@0 | 41 | let globalDefaults = { |
michael@0 | 42 | console: console |
michael@0 | 43 | }; |
michael@0 | 44 | |
michael@0 | 45 | let loader = Loader({ |
michael@0 | 46 | paths: paths || makePaths(), |
michael@0 | 47 | globals: extend({}, globalDefaults, globals) || null, |
michael@0 | 48 | modules: { |
michael@0 | 49 | // Needed because sdk/ modules reference utilities in |
michael@0 | 50 | // `toolkit/loader`, until Bug 961194 is completed |
michael@0 | 51 | 'toolkit/loader': LoaderModule |
michael@0 | 52 | }, |
michael@0 | 53 | // We need rootURI due to `sdk/self` (or are using native loader) |
michael@0 | 54 | // which overloads with pseudo modules |
michael@0 | 55 | // bug 961245 |
michael@0 | 56 | rootURI: CURRENT_DIR, |
michael@0 | 57 | // We also need metadata dummy object |
michael@0 | 58 | // bug 961245 |
michael@0 | 59 | metadata: {} |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | loaders.push(loader); |
michael@0 | 63 | return loader; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function isUUID (string) { |
michael@0 | 67 | return /^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/.test(string); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function extend (...objs) { |
michael@0 | 71 | if (objs.length === 0 || objs.length === 1) |
michael@0 | 72 | return objs[0] || {}; |
michael@0 | 73 | |
michael@0 | 74 | for (let i = objs.length; i > 1; i--) { |
michael@0 | 75 | for (var prop in objs[i - 1]) |
michael@0 | 76 | objs[0][prop] = objs[i - 1][prop]; |
michael@0 | 77 | } |
michael@0 | 78 | return objs[0]; |
michael@0 | 79 | } |