Skip to content
Snippets Groups Projects
Commit e53ade9a authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Merge pull request #1549 from mozilla/issue1546-kpi-storage

@ozten - Nice work on the cleanup.  What if we created one logger that we could use to universally log these sorts of things?  If we consolidated all of the logging into one module, we could add/remove/turn on or off functionality we use for logging.

For the removed "delete" statement, it is safer to use localStorage.removeItem.  I forgot which browser was giving us problems with that, in the end I wrote a load of unit tests and did a browser comparison blog post (http://www.shanetomlinson.com/2012/localstorage-bugs-inconsistent-removeitem-delete/) - the trouble with delete came from IE8.  

In IE8, if the item you are trying to call delete on is not already in localStorage, it will throw an exception.  IE8 does not have this problem with localStorage.removeItem.

r+ - Merging.

close #1546
parents 6d2ce002 8168451f
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*globals BrowserID: true, console: true */
BrowserID.Storage = (function() {
"use strict";
......@@ -25,6 +27,11 @@ BrowserID.Storage = (function() {
};
}
// temporary, replace with helpers.log if storage uses elog long term...
function elog (msg) {
if (window.console && console.error) console.error(msg);
}
function prepareDeps() {
if (!jwcrypto) {
jwcrypto = require("./jwcrypto");
......@@ -271,7 +278,7 @@ BrowserID.Storage = (function() {
lastUpdated = Date.parse(userInfo.updated);
if (!validState(currentState)) throw "corrupt/outdated";
if (NaN === lastUpdated) throw "corrupt/outdated";
if (isNaN(lastUpdated)) throw "corrupt/outdated";
}
} catch(e) {
currentState = undefined;
......@@ -409,7 +416,7 @@ BrowserID.Storage = (function() {
try {
return storage.interactionData ? JSON.parse(storage.interactionData)[0] : {};
} catch(e) {
if (window.console && console.error) console.error(e);
elog(e);
return {};
}
}
......@@ -420,7 +427,7 @@ BrowserID.Storage = (function() {
id = JSON.parse(storage.interactionData);
id[0] = data;
} catch(e) {
if (window.console && console.error) console.error(e);
elog(e);
id = [ data ];
}
storage.interactionData = JSON.stringify(id);
......@@ -439,8 +446,8 @@ BrowserID.Storage = (function() {
try {
storage.interactionData = JSON.stringify([]);
} catch(e) {
delete storage.interactionData;
if (window.console && console.error) console.error(e);
storage.removeItem("interactionData");
elog(e);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment