Skip to content

Commit

Permalink
(#1068) - cache websql dbs
Browse files Browse the repository at this point in the history
Safari 7 starts throwing DOM Exception 11 if
we open up too many db handles, which crashes
our unit tests. Caching them fixes that.
  • Loading branch information
nolanlawson committed Mar 25, 2014
1 parent c041875 commit 16ab53a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/adapters/websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function quote(str) {
return "'" + str + "'";
}

var cachedDbs = {};

var openDB = utils.getArguments(function (args) {
if (typeof global !== 'undefined') {
if (global.navigator && global.navigator.sqlitePlugin &&
Expand All @@ -17,7 +19,11 @@ var openDB = utils.getArguments(function (args) {
return global.sqlitePlugin.openDatabase
.apply(global.sqlitePlugin, args);
} else {
return global.openDatabase.apply(global, args);
var db = cachedDbs[args[0]];
if (!db) {
db = cachedDbs[args[0]] = global.openDatabase.apply(global, args);
}
return db;
}
}
});
Expand Down

0 comments on commit 16ab53a

Please sign in to comment.