Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: d2223be1ea
...
compare: 01ac4c6473
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
20 build/gazel.js
@@ -8,6 +8,10 @@ var exists = function (obj) {
return typeof obj !== 'undefined' && obj != null;
};
+var isInt = function(n) {
+ return !isNaN(n) && (n % 1 == 0);
+};
+
window.indexedDB = window.indexedDB
|| window.mozIndexedDB
|| window.msIndexedDB
@@ -350,6 +354,12 @@ Client.prototype.incrby = function(key, increment, callback) {
return;
}
+
+ if(!isInt(val)) {
+ self.handleError('ERROR: Cannot increment a non-integer value.');
+
+ return;
+ }
var value = val + increment;
var req = os.put(value, key);
@@ -396,10 +406,7 @@ Client.prototype.del = function() {
var os = tx.objectStore(gazel.osName),
left = keys.length,
- deleted = 0,
- exit = function() {
- cb.call(self, deleted);
- };
+ deleted = 0;
while(keys.length > 0) {
@@ -414,13 +421,10 @@ Client.prototype.del = function() {
if(e.target.result) deleted++;
if(left === 0)
- exit();
+ cb.call(self, deleted);
};
})();
-
}
-
-
});
}, callback);
View
2  build/gazel.min.js
@@ -1 +1 @@
-((function(){function f(a,b){for(b=a="";a++<36;b+=a*51&52?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):"-");return b}function i(){this.chain=[],this.inMulti=!1,this.returned=[],this.trans=e.create(h,!0),this.transMap=e.create(g,!0),this.events=e.create(g,!0)}function l(b,c){if(j){b(j);return}if(k){setTimeout(function(){l(b,c)},100);return}k=!0;var d=window.indexedDB.open(a.dbName,a.version);d.onupgradeneeded=function(b){var c=b.target.result;c.objectStoreNames.contains(a.osName)||c.createObjectStore(a.osName)};var e;e=d.onsuccess=function(f){var g=f.target.result;if(g.setVersion&&Number(g.version)!==a.version){var h=g.setVersion(String(a.version));h.onsuccess=function(a){var b={};b.target={},b.target.result=a.target.result.db,d.onupgradeneeded(b),e(b);return},h.onerror=c,h.onfailure=c,h.onblocked=c;return}j=g,k=!1,b(j)},d.onerror=c}"use strict";var a=a||{},b=function(a){return typeof a!="undefined"&&a!=null};window.indexedDB=window.indexedDB||window.mozIndexedDB||window.msIndexedDB||window.webkitIndexedDB||window.oIndexedDB,window.IDBTransaction=window.IDBTransaction||window.webkitIDBTransaction;var c=Array.prototype.slice,d=Array.prototype.splice,e=Object.create(null);e.create=function(a,b,c){if(typeof b!="undefined"||typeof c!="undefined"||a instanceof Array){typeof b=="boolean"&&(c=b,b=undefined),a instanceof Array||(a=[a]);var d={};for(var e in b)d[e]={value:b[e],writable:!0,enumerable:!0,configurable:!0};var f,g={},h=a.pop();do{var i=a.pop();if(i){var j={};for(var e in h)j[e]=h[e],g[e]=Object.getOwnPropertyDescriptor(j,e);h=Object.create(i,g)}}while(a.length>0);f=Object.create(h,d);if(c){var k=Array.prototype.slice.call(arguments).slice(typeof b=="undefined"?2:3);f.init.apply(f,k)}return f}return Object.create(a)},typeof exports!="undefined"&&(exports.create=e.create);var g=e.create(Object.prototype,{init:function(){return this.items={},this},prop:function(a){return":"+a},get:function(a,b){var c=this.prop(a),d=this.items;return d.hasOwnProperty(c)?d[c]:b},set:function(a,b){var c=this.prop(a);return this.items[c]=b,b},count:function(){return Object.keys(this.items).length},has:function(a){var b=this.prop(a);return this.items.hasOwnProperty(b)},del:function(a){var b=this.prop(a),c=this.items;c.hasOwnProperty(b)&&delete c[b]},keys:function(){return Object.keys(this.items).map(function(a){return a.substring(1)})}}),h=e.create(g,{add:function(){var a=f();return this.set(a,undefined),a},abortAll:function(){var a=this,b=a.keys();b.forEach(function(b){var c=a.get(b);c.abort(),a.del(b)})},pull:function(b,c,d){var e=this.get(c);return e||(e=b.transaction([a.osName],d),e.onerror=onerror,this.set(c,e)),e}});i.prototype={register:function(a,b,d){if(this.inMulti){var e=this.transMap.get(a);e||(e=this.trans.add(),this.transMap.set(a,e)),this.chain.push({uuid:e,action:b});return}var f=this,e=f.trans.add();b(e,function(){var a=c.call(arguments);f.trans.del(e),(d||function(){}).apply(null,a)})},flush:function(){var a=c.call(arguments)||[];this.returned.push(a);if(this.chain.length===0){this.complete();return}var b=this.chain.shift();b.action.call(this,b.uuid,this.flush)},multi:function(){return this.chain=[],this.inMulti=!0,this},exec:function(a){this.inMulti=!1,this.complete=function(){var b=this,c=this.returned;this.complete=null,this.chain=null,this.returned=[],this.transMap.keys().forEach(function(a){var c=b.transMap.get(a);b.trans.del(c)}),this.transMap=e.create(g,!0),a(c)};var b=this.chain.shift();b.action.call(this,b.uuid,this.flush)},on:function(a,b){var c=this.events.get(a);c||(c=[],this.events.set(a,c)),c.push(b)}},i.prototype.discard=function(){this.trans.abortAll()},i.prototype.handleError=function(){var a=Array.prototype.slice.call(arguments),b=this.events.get("error")||[];b.forEach(function(b){b.apply(null,a)})},i.prototype.get=function(b,c){var d=this;return this.register("read",function(c,e){l(function(f){var g=d.trans.pull(f,c,IDBTransaction.READ),h=g.objectStore(a.osName).get(b);h.onerror=d.handleError.bind(d),h.onsuccess=function(a){e.call(d,a.target.result)}},d.handleError.bind(d))},c),this},i.prototype.set=function(b,c,d){var e=this;return this.register("write",function(d,f){l(function(g){var h=e.trans.pull(g,d,IDBTransaction.READ_WRITE),i=h.objectStore(a.osName).put(c,b);i.onerror=e.handleError.bind(e),i.onsuccess=function(a){var c=a.target.result===b?"OK":"ERR";f.call(e,c)}},e.handleError.bind(e))},d),this},i.prototype.incrby=function(c,d,e){var f=this;return this.register("write",function(e,g){l(function(h){var i=f.trans.pull(h,e,IDBTransaction.READ_WRITE),j=i.objectStore(a.osName);(function k(a){if(!b(a)){var e=j.get(c);e.onerror=f.handleError.bind(f),e.onsuccess=function(a){k(typeof a.target.result=="undefined"?0:a.target.result)};return}var h=a+d,e=j.put(h,c);e.onerror=f.handleError.bind(f),e.onsuccess=function(a){var b=a.target.result===c?h:"ERR";g.call(f,b)}})()},f.handleError.bind(f))},e),this},i.prototype.incr=function(a,b){return this.incrby(a,1,b)},i.prototype.decrby=function(a,b,c){return this.incrby(a,-b,c)},i.prototype.decr=function(a,b){return this.incrby(a,-1,b)},i.prototype.del=function(){var b=this,d=c.call(arguments),e=d[d.length>0?d.length-1:0];typeof e!="function"?e=undefined:d.splice(d.length-1);var f=d;return this.register("write",function(c,d){l(function(e){var g=b.trans.pull(e,c,IDBTransaction.READ_WRITE),h=g.objectStore(a.osName),i=f.length,j=0,k=function(){d.call(b,j)};while(f.length>0)(function(){var a=f.shift(),c=h.delete(a);c.onerror=b.handleError.bind(b),c.onsuccess=function(a){i--,a.target.result&&j++,i===0&&k()}})()})},e),this},a.print=function(){var a=Array.prototype.slice.call(arguments);if(a.length===0)return;var b=a[0]instanceof Array?a[0]:[a[0]];b.forEach(function(a){console.log(a)})},a.version=1,a.dbName="gazeldb",a.osName="gazelos",a.compatible=b(window.indexedDB)&&b(window.IDBTransaction),a.createClient=function(){return new i},this.gazel=a;var j,k=!1})).call(this);
+((function(){function g(a,b){for(b=a="";a++<36;b+=a*51&52?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):"-");return b}function j(){this.chain=[],this.inMulti=!1,this.returned=[],this.trans=f.create(i,!0),this.transMap=f.create(h,!0),this.events=f.create(h,!0)}function m(b,c){if(k){b(k);return}if(l){setTimeout(function(){m(b,c)},100);return}l=!0;var d=window.indexedDB.open(a.dbName,a.version);d.onupgradeneeded=function(b){var c=b.target.result;c.objectStoreNames.contains(a.osName)||c.createObjectStore(a.osName)};var e;e=d.onsuccess=function(f){var g=f.target.result;if(g.setVersion&&Number(g.version)!==a.version){var h=g.setVersion(String(a.version));h.onsuccess=function(a){var b={};b.target={},b.target.result=a.target.result.db,d.onupgradeneeded(b),e(b);return},h.onerror=c,h.onfailure=c,h.onblocked=c;return}k=g,l=!1,b(k)},d.onerror=c}"use strict";var a=a||{},b=function(a){return typeof a!="undefined"&&a!=null},c=function(a){return!isNaN(a)&&a%1==0};window.indexedDB=window.indexedDB||window.mozIndexedDB||window.msIndexedDB||window.webkitIndexedDB||window.oIndexedDB,window.IDBTransaction=window.IDBTransaction||window.webkitIDBTransaction;var d=Array.prototype.slice,e=Array.prototype.splice,f=Object.create(null);f.create=function(a,b,c){if(typeof b!="undefined"||typeof c!="undefined"||a instanceof Array){typeof b=="boolean"&&(c=b,b=undefined),a instanceof Array||(a=[a]);var d={};for(var e in b)d[e]={value:b[e],writable:!0,enumerable:!0,configurable:!0};var f,g={},h=a.pop();do{var i=a.pop();if(i){var j={};for(var e in h)j[e]=h[e],g[e]=Object.getOwnPropertyDescriptor(j,e);h=Object.create(i,g)}}while(a.length>0);f=Object.create(h,d);if(c){var k=Array.prototype.slice.call(arguments).slice(typeof b=="undefined"?2:3);f.init.apply(f,k)}return f}return Object.create(a)},typeof exports!="undefined"&&(exports.create=f.create);var h=f.create(Object.prototype,{init:function(){return this.items={},this},prop:function(a){return":"+a},get:function(a,b){var c=this.prop(a),d=this.items;return d.hasOwnProperty(c)?d[c]:b},set:function(a,b){var c=this.prop(a);return this.items[c]=b,b},count:function(){return Object.keys(this.items).length},has:function(a){var b=this.prop(a);return this.items.hasOwnProperty(b)},del:function(a){var b=this.prop(a),c=this.items;c.hasOwnProperty(b)&&delete c[b]},keys:function(){return Object.keys(this.items).map(function(a){return a.substring(1)})}}),i=f.create(h,{add:function(){var a=g();return this.set(a,undefined),a},abortAll:function(){var a=this,b=a.keys();b.forEach(function(b){var c=a.get(b);c.abort(),a.del(b)})},pull:function(b,c,d){var e=this.get(c);return e||(e=b.transaction([a.osName],d),e.onerror=onerror,this.set(c,e)),e}});j.prototype={register:function(a,b,c){if(this.inMulti){var e=this.transMap.get(a);e||(e=this.trans.add(),this.transMap.set(a,e)),this.chain.push({uuid:e,action:b});return}var f=this,e=f.trans.add();b(e,function(){var a=d.call(arguments);f.trans.del(e),(c||function(){}).apply(null,a)})},flush:function(){var a=d.call(arguments)||[];this.returned.push(a);if(this.chain.length===0){this.complete();return}var b=this.chain.shift();b.action.call(this,b.uuid,this.flush)},multi:function(){return this.chain=[],this.inMulti=!0,this},exec:function(a){this.inMulti=!1,this.complete=function(){var b=this,c=this.returned;this.complete=null,this.chain=null,this.returned=[],this.transMap.keys().forEach(function(a){var c=b.transMap.get(a);b.trans.del(c)}),this.transMap=f.create(h,!0),a(c)};var b=this.chain.shift();b.action.call(this,b.uuid,this.flush)},on:function(a,b){var c=this.events.get(a);c||(c=[],this.events.set(a,c)),c.push(b)}},j.prototype.discard=function(){this.trans.abortAll()},j.prototype.handleError=function(){var a=Array.prototype.slice.call(arguments),b=this.events.get("error")||[];b.forEach(function(b){b.apply(null,a)})},j.prototype.get=function(b,c){var d=this;return this.register("read",function(c,e){m(function(f){var g=d.trans.pull(f,c,IDBTransaction.READ),h=g.objectStore(a.osName).get(b);h.onerror=d.handleError.bind(d),h.onsuccess=function(a){e.call(d,a.target.result)}},d.handleError.bind(d))},c),this},j.prototype.set=function(b,c,d){var e=this;return this.register("write",function(d,f){m(function(g){var h=e.trans.pull(g,d,IDBTransaction.READ_WRITE),i=h.objectStore(a.osName).put(c,b);i.onerror=e.handleError.bind(e),i.onsuccess=function(a){var c=a.target.result===b?"OK":"ERR";f.call(e,c)}},e.handleError.bind(e))},d),this},j.prototype.incrby=function(d,e,f){var g=this;return this.register("write",function(f,h){m(function(i){var j=g.trans.pull(i,f,IDBTransaction.READ_WRITE),k=j.objectStore(a.osName);(function l(a){if(!b(a)){var f=k.get(d);f.onerror=g.handleError.bind(g),f.onsuccess=function(a){l(typeof a.target.result=="undefined"?0:a.target.result)};return}if(!c(a)){g.handleError("ERROR: Cannot increment a non-integer value.");return}var i=a+e,f=k.put(i,d);f.onerror=g.handleError.bind(g),f.onsuccess=function(a){var b=a.target.result===d?i:"ERR";h.call(g,b)}})()},g.handleError.bind(g))},f),this},j.prototype.incr=function(a,b){return this.incrby(a,1,b)},j.prototype.decrby=function(a,b,c){return this.incrby(a,-b,c)},j.prototype.decr=function(a,b){return this.incrby(a,-1,b)},j.prototype.del=function(){var b=this,c=d.call(arguments),e=c[c.length>0?c.length-1:0];typeof e!="function"?e=undefined:c.splice(c.length-1);var f=c;return this.register("write",function(c,d){m(function(e){var g=b.trans.pull(e,c,IDBTransaction.READ_WRITE),h=g.objectStore(a.osName),i=f.length,j=0;while(f.length>0)(function(){var a=f.shift(),c=h.delete(a);c.onerror=b.handleError.bind(b),c.onsuccess=function(a){i--,a.target.result&&j++,i===0&&d.call(b,j)}})()})},e),this},a.print=function(){var a=Array.prototype.slice.call(arguments);if(a.length===0)return;var b=a[0]instanceof Array?a[0]:[a[0]];b.forEach(function(a){console.log(a)})},a.version=1,a.dbName="gazeldb",a.osName="gazelos",a.compatible=b(window.indexedDB)&&b(window.IDBTransaction),a.createClient=function(){return new j},this.gazel=a;var k,l=!1})).call(this);
View
10 src/del.js
@@ -17,10 +17,7 @@ Client.prototype.del = function() {
var os = tx.objectStore(gazel.osName),
left = keys.length,
- deleted = 0,
- exit = function() {
- cb.call(self, deleted);
- };
+ deleted = 0;
while(keys.length > 0) {
@@ -35,13 +32,10 @@ Client.prototype.del = function() {
if(e.target.result) deleted++;
if(left === 0)
- exit();
+ cb.call(self, deleted);
};
})();
-
}
-
-
});
}, callback);
View
6 src/incr.js
@@ -17,6 +17,12 @@ Client.prototype.incrby = function(key, increment, callback) {
return;
}
+
+ if(!isInt(val)) {
+ self.handleError('ERROR: Cannot increment a non-integer value.');
+
+ return;
+ }
var value = val + increment;
var req = os.put(value, key);
View
4 src/setup.js
@@ -4,6 +4,10 @@ var exists = function (obj) {
return typeof obj !== 'undefined' && obj != null;
};
+var isInt = function(n) {
+ return !isNaN(n) && (n % 1 == 0);
+};
+
window.indexedDB = window.indexedDB
|| window.mozIndexedDB
|| window.msIndexedDB
View
14 test/incr.js
@@ -56,14 +56,22 @@ describe('Incr/Decr', function() {
});
it('incr should set value to 1 if value not existant', function(done) {
- client.incr('notexists', function(res) {
- done(assert.equal(res, 1));
+ client.del('notexists', function(resp) {
+ client.incr('notexists', function(res) {
+ done(assert.equal(res, 1));
+ });
});
});
it('should return error if incrementing string', function(done) {
+ var errClient = gazel.createClient();
+
+ errClient.on('error', function(msg) {
+ done(assert.ok(true));
+ });
+
set('foo', 'bar', function() {
- client.incr('foo', function(res) {
+ errClient.incr('foo', function(res) {
done(assert.ok(false, 'We should not get here.'));
});
});

No commit comments for this range

Something went wrong with that request. Please try again.