Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
7ef3c902
Commit
7ef3c902
authored
Jun 27, 2017
by
Robert Knight
Committed by
GitHub
Jun 27, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #464 from tilgovi/fix-localstorage-access-error
Use fallback when local storage throws
parents
2605fce9
60a37459
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
local-storage.js
src/sidebar/local-storage.js
+6
-5
local-storage-test.js
src/sidebar/test/local-storage-test.js
+21
-1
No files found.
src/sidebar/local-storage.js
View file @
7ef3c902
...
@@ -28,14 +28,15 @@ class InMemoryStorage {
...
@@ -28,14 +28,15 @@ class InMemoryStorage {
*/
*/
// @ngInject
// @ngInject
function
localStorage
(
$window
)
{
function
localStorage
(
$window
)
{
var
storage
=
$window
.
localStorage
;
let
storage
;
let
testKey
=
'hypothesis.testKey'
;
try
{
try
{
// Test whether we can read/write localStorage.
// Test whether we can read/write localStorage.
var
key
=
'hypothesis.testKey'
;
storage
=
$window
.
localStorage
;
$window
.
localStorage
.
setItem
(
key
,
k
ey
);
$window
.
localStorage
.
setItem
(
testKey
,
testK
ey
);
$window
.
localStorage
.
getItem
(
k
ey
);
$window
.
localStorage
.
getItem
(
testK
ey
);
$window
.
localStorage
.
removeItem
(
k
ey
);
$window
.
localStorage
.
removeItem
(
testK
ey
);
}
catch
(
e
)
{
}
catch
(
e
)
{
storage
=
new
InMemoryStorage
();
storage
=
new
InMemoryStorage
();
}
}
...
...
src/sidebar/test/local-storage-test.js
View file @
7ef3c902
'use strict'
;
'use strict'
;
var
angular
=
require
(
'angular'
);
var
angular
=
require
(
'angular'
);
var
service
=
require
(
'../local-storage'
);
describe
(
'sidebar.localStorage'
,
()
=>
{
describe
(
'sidebar.localStorage'
,
()
=>
{
var
fakeWindow
;
var
fakeWindow
;
before
(()
=>
before
(()
=>
angular
.
module
(
'h'
,
[])
angular
.
module
(
'h'
,
[])
.
service
(
'localStorage'
,
require
(
'../local-storage'
)
)
.
service
(
'localStorage'
,
service
)
);
);
context
(
'when accessing localStorage throws an Error'
,
()
=>
{
it
(
'returns the fallback implementation'
,
()
=>
{
var
badWindow
=
{};
var
fakeWindow
=
{};
Object
.
defineProperty
(
badWindow
,
'localStorage'
,
{
get
:
()
=>
{
throw
Error
(
'denied'
);
},
});
var
prototypes
=
[
badWindow
,
fakeWindow
]
.
map
(
service
)
.
map
(
Object
.
getPrototypeOf
)
;
assert
.
strictEqual
(
prototypes
[
0
],
prototypes
[
1
]);
});
});
context
(
'when browser localStorage is *not* accessible'
,
()
=>
{
context
(
'when browser localStorage is *not* accessible'
,
()
=>
{
var
localStorage
=
null
;
var
localStorage
=
null
;
var
key
=
null
;
var
key
=
null
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment