mediawiki.storage: Catch exceptions on window.localStorage property access
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 24 Oct 2016 23:00:45 +0000 (00:00 +0100)
committerGilles <gdubuc@wikimedia.org>
Tue, 25 Oct 2016 13:28:38 +0000 (13:28 +0000)
Follows-up 430a0d3984, which created a private property that stored a
reference to the localStorage object outside the get and set methods.

Where previously it was used directly, and as such, covered by
the try/catch around getItem and setItem calls.

Bug: T148998
Change-Id: Ibe75408913d4ffbf1791e1a6470296b29f809185

resources/src/mediawiki/mediawiki.storage.js

index cb62fbf..a9d17ff 100644 (file)
         */
        mw.storage = {
 
-               localStorage: window.localStorage,
+               localStorage: ( function () {
+                       // Catch exceptions to avoid fatal in Chrome's "Block data storage" mode
+                       // which throws when accessing the localStorage property itself, as opposed
+                       // to the standard behaviour of throwing on getItem/setItem. (T148998)
+                       try {
+                               return window.localStorage;
+                       } catch ( e ) {}
+               }() ),
 
                /**
                 * Retrieve value from device storage.