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

View file

@ -25,11 +25,15 @@
// If the user disabled MediaViewer in his preferences, we do not set up click handling. // 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. // This is loaded before user JS so we cannot check wgMediaViewer.
if ( try {
mw.config.get( 'wgMediaViewerOnClick' ) !== true if (
|| mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false mw.config.get( 'wgMediaViewerOnClick' ) !== true
) { || mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false
return; ) {
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 ) { $document.on( 'click.mmv-head', 'a.image', function ( e ) {

View file

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