Fix rageshake

aka. Module Variables Are Not Global Variables pt. 319
pull/21833/head
David Baker 2018-04-20 14:06:09 +01:00
parent 1aadaa3cc5
commit 3ea5fc9185
1 changed files with 18 additions and 21 deletions

View File

@ -395,9 +395,6 @@ function selectQuery(store, keyRange, resultMapper) {
} }
let store = null;
let logger = null;
let initPromise = null;
module.exports = { module.exports = {
/** /**
@ -406,11 +403,11 @@ module.exports = {
* @return {Promise} Resolves when set up. * @return {Promise} Resolves when set up.
*/ */
init: function() { init: function() {
if (initPromise) { if (global.mx_rage_initPromise) {
return initPromise; return global.mx_rage_initPromise;
} }
logger = new ConsoleLogger(); global.mx_rage_logger = new ConsoleLogger();
logger.monkeyPatch(window.console); global.mx_rage_logger.monkeyPatch(window.console);
// just *accessing* indexedDB throws an exception in firefox with // just *accessing* indexedDB throws an exception in firefox with
// indexeddb disabled. // indexeddb disabled.
@ -420,19 +417,19 @@ module.exports = {
} catch(e) {} } catch(e) {}
if (indexedDB) { if (indexedDB) {
store = new IndexedDBLogStore(indexedDB, logger); global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger);
initPromise = store.connect(); global.mx_rage_initPromise = global.mx_rage_store.connect();
return initPromise; return global.mx_rage_initPromise;
} }
initPromise = Promise.resolve(); global.mx_rage_initPromise = Promise.resolve();
return initPromise; return global.mx_rage_initPromise;
}, },
flush: function() { flush: function() {
if (!store) { if (!global.mx_rage_store) {
return; return;
} }
store.flush(); global.mx_rage_store.flush();
}, },
/** /**
@ -440,10 +437,10 @@ module.exports = {
* @return Promise Resolves if cleaned logs. * @return Promise Resolves if cleaned logs.
*/ */
cleanup: async function() { cleanup: async function() {
if (!store) { if (!global.mx_rage_store) {
return; return;
} }
await store.consume(); await global.mx_rage_store.consume();
}, },
/** /**
@ -452,21 +449,21 @@ module.exports = {
* @return {Array<{lines: string, id, string}>} list of log data * @return {Array<{lines: string, id, string}>} list of log data
*/ */
getLogsForReport: async function() { getLogsForReport: async function() {
if (!logger) { if (!global.mx_rage_logger) {
throw new Error( throw new Error(
"No console logger, did you forget to call init()?" "No console logger, did you forget to call init()?"
); );
} }
// If in incognito mode, store is null, but we still want bug report // If in incognito mode, store is null, but we still want bug report
// sending to work going off the in-memory console logs. // sending to work going off the in-memory console logs.
if (store) { if (global.mx_rage_store) {
// flush most recent logs // flush most recent logs
await store.flush(); await global.mx_rage_store.flush();
return await store.consume(); return await global.mx_rage_store.consume();
} }
else { else {
return [{ return [{
lines: logger.flush(true), lines: global.mx_rage_logger.flush(true),
id: "-", id: "-",
}]; }];
} }