Catch exceptions thrown by localStorage.getItem

Bug: T94695
Change-Id: I7fd7c4776a55de24d702babb291faf3208c8d0af
This commit is contained in:
Gilles Dubuc 2015-04-02 14:15:24 +02:00
parent f7ee2790ca
commit 5bd02e8cc1
3 changed files with 19 additions and 7 deletions

View file

@ -65,7 +65,11 @@
CP.getFromLocalStorage = function ( key, fallback ) {
var value = null;
if ( this.localStorage ) {
try {
value = this.localStorage.getItem( key );
} catch ( e ) {
mw.log( 'Failed to fetch item ' + key + ' from localStorage', e );
}
}
if ( value === null && fallback !== undefined ) {
value = fallback;

View file

@ -25,12 +25,16 @@
// If the user disabled MediaViewer in his preferences, we do not set up click handling.
// This is loaded before user JS so we cannot check wgMediaViewer.
try {
if (
mw.config.get( 'wgMediaViewerOnClick' ) !== true
|| mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false
) {
return;
}
} catch ( e ) { // localStorage.getItem can throw exceptions
mw.log( 'Could not check value of wgMediaViewerOnClick in localStorage' );
}
$document.on( 'click.mmv-head', 'a.image', function ( e ) {
// Do not interfere with non-left clicks or if modifier keys are pressed.

View file

@ -138,7 +138,11 @@
MPSP.initialize = function () {
try {
this.hasOpenedMetadata = !this.localStorage || this.localStorage.getItem( 'mmv.hasOpenedMetadata' );
} catch ( e ) { // localStorage.getItem can throw exceptions
this.hasOpenedMetadata = true;
}
};
/**