diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2021-02-12 19:32:13 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-12 19:32:13 +0900 |
| commit | 0f47e192bdab877786b909988e3d7ac1eede2373 (patch) | |
| tree | b0e4d3ef8282befe0def0840c187d92a3a56e980 | |
| parent | 0b7fc80e45294db1374b06aa8e56e55612797cf2 (diff) | |
| parent | 16f0ccda86b7cce1b2cfb7b6bcdef42e3e76dfbc (diff) | |
Rollup merge of #81964 - lovasoa:patch-1, r=GuillaumeGomez
Fix documentation not showing on localStorage error Fixes https://github.com/rust-lang/rust/issues/81928 The [documentation for setItem](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem) specifies: > developers should make sure to always catch possible exceptions from setItem()
| -rw-r--r-- | src/librustdoc/html/static/storage.js | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js index 9c5ac1625af..a50ed5b662b 100644 --- a/src/librustdoc/html/static/storage.js +++ b/src/librustdoc/html/static/storage.js @@ -89,35 +89,20 @@ function hasOwnProperty(obj, property) { return Object.prototype.hasOwnProperty.call(obj, property); } -function usableLocalStorage() { - // Check if the browser supports localStorage at all: - if (typeof Storage === "undefined") { - return false; - } - // Check if we can access it; this access will fail if the browser - // preferences deny access to localStorage, e.g., to prevent storage of - // "cookies" (or cookie-likes, as is the case here). - try { - return window.localStorage !== null && window.localStorage !== undefined; - } catch(err) { - // Storage is supported, but browser preferences deny access to it. - return false; - } -} - function updateLocalStorage(name, value) { - if (usableLocalStorage()) { - localStorage[name] = value; - } else { - // No Web Storage support so we do nothing + try { + window.localStorage.setItem(name, value); + } catch(e) { + // localStorage is not accessible, do nothing } } function getCurrentValue(name) { - if (usableLocalStorage() && localStorage[name] !== undefined) { - return localStorage[name]; + try { + return window.localStorage.getItem(name); + } catch(e) { + return null; } - return null; } function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { |
