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 ) {
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 ) {
value = fallback;

View file

@ -25,11 +25,15 @@
// 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.
if (
mw.config.get( 'wgMediaViewerOnClick' ) !== true
|| mw.user.isAnon() && window.localStorage && localStorage.getItem( 'wgMediaViewerOnClick' ) === false
) {
return;
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 ) {

View file

@ -138,7 +138,11 @@
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;
}
};
/**