Permalink
Browse files

JSON.parse(null) throws illegal access error on Android 2.3. Added re…

…levant checks in adapter/dom.js
  • Loading branch information...
1 parent 4c1ed3a commit 5bf6280e8d46f5575978c0b65e475e31ffe62370 @neebz neebz committed Apr 5, 2012
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/adapters/dom.js
View
@@ -18,7 +18,10 @@ Lawnchair.adapter('dom', (function() {
key: name + '._index_',
// returns the index
all: function() {
- var a = JSON.parse(storage.getItem(this.key))
+ var a = storage.getItem(this.key)
+ if (a) {
+ a = JSON.parse(a)
+ }
if (a === null) storage.setItem(this.key, JSON.stringify([])) // lazy init
return JSON.parse(storage.getItem(this.key))
},
@@ -102,17 +105,21 @@ Lawnchair.adapter('dom', (function() {
var r = []
for (var i = 0, l = key.length; i < l; i++) {
var k = this.name + '.' + key[i]
- , obj = JSON.parse(storage.getItem(k))
+ var obj = storage.getItem(k)
if (obj) {
+ obj = JSON.parse(obj)
obj.key = key[i]
r.push(obj)
}
}
if (callback) this.lambda(callback).call(this, r)
} else {
var k = this.name + '.' + key
- , obj = JSON.parse(storage.getItem(k))
- if (obj) obj.key = key
+ var obj = storage.getItem(k)
+ if (obj) {
+ obj = JSON.parse(obj)
+ obj.key = key
+ }
if (callback) this.lambda(callback).call(this, obj)
}
return this

0 comments on commit 5bf6280

Please sign in to comment.