Skip to content

Commit 0db0a0a

Browse files
authored
Rollup merge of rust-lang#81964 - lovasoa:patch-1, r=GuillaumeGomez
Fix documentation not showing on localStorage error Fixes rust-lang#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()
2 parents 9e4c98d + 16f0ccd commit 0db0a0a

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src/librustdoc/html/static/storage.js

+8-23
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,20 @@ function hasOwnProperty(obj, property) {
8989
return Object.prototype.hasOwnProperty.call(obj, property);
9090
}
9191

92-
function usableLocalStorage() {
93-
// Check if the browser supports localStorage at all:
94-
if (typeof Storage === "undefined") {
95-
return false;
96-
}
97-
// Check if we can access it; this access will fail if the browser
98-
// preferences deny access to localStorage, e.g., to prevent storage of
99-
// "cookies" (or cookie-likes, as is the case here).
100-
try {
101-
return window.localStorage !== null && window.localStorage !== undefined;
102-
} catch(err) {
103-
// Storage is supported, but browser preferences deny access to it.
104-
return false;
105-
}
106-
}
107-
10892
function updateLocalStorage(name, value) {
109-
if (usableLocalStorage()) {
110-
localStorage[name] = value;
111-
} else {
112-
// No Web Storage support so we do nothing
93+
try {
94+
window.localStorage.setItem(name, value);
95+
} catch(e) {
96+
// localStorage is not accessible, do nothing
11397
}
11498
}
11599

116100
function getCurrentValue(name) {
117-
if (usableLocalStorage() && localStorage[name] !== undefined) {
118-
return localStorage[name];
101+
try {
102+
return window.localStorage.getItem(name);
103+
} catch(e) {
104+
return null;
119105
}
120-
return null;
121106
}
122107

123108
function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {

0 commit comments

Comments
 (0)