Skip to content

Commit

Permalink
* Fixed some unsafe for(... in ...) loops that do not take extensions to
Browse files Browse the repository at this point in the history
  built-in type prototypes into account (which shop up in such loops).
  Added .hasOwnProperty checks there, also replaced parameter iteration
  in commands.js to a for-loop with a counter, rather than for-in.
* Added `close` method to WebSQL interface
  • Loading branch information
zefhemel committed Jul 12, 2010
1 parent 73849ce commit 702a56b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions mysql/commands.js
Expand Up @@ -115,7 +115,10 @@ function cmd(handlers)
// mixin all handlers // mixin all handlers
for (h in handlers) for (h in handlers)
{ {
this[h] = handlers[h]; if(handlers.hasOwnProperty(h))
{
this[h] = handlers[h];
}
} }


// delegate to private EventEmitter member // delegate to private EventEmitter member
Expand Down Expand Up @@ -371,15 +374,15 @@ function execute(sql, parameters)
// todo: set types only on first call // todo: set types only on first call
packet.add('\u0001'); packet.add('\u0001');
// todo: add numeric/datetime serialisers // todo: add numeric/datetime serialisers
for (var p in parameters) for (var i = 0; i < parameters.length; i++)
{ {
if (parameters[p] != null) if (parameters[i] != null)
packet.int2(types.MYSQL_TYPE_VAR_STRING); packet.int2(types.MYSQL_TYPE_VAR_STRING);
} }
for (var p in parameters) for (var i = 0; i < parameters.length; i++)
{ {
if (parameters[p] != null) if (parameters[i] != null)
packet.lcstring(parameters[p].toString()); packet.lcstring(parameters[i].toString());
} }
} }
this.write( packet ); this.write( packet );
Expand Down
7 changes: 5 additions & 2 deletions mysql/constants.js
Expand Up @@ -84,6 +84,9 @@ exports.type_names = {};


for (var tname in exports.types) for (var tname in exports.types)
{ {
var type = exports.types[tname]; if(exports.types.hasOwnProperty(tname) )
exports.type_names[type] = tname; {
var type = exports.types[tname];
exports.type_names[type] = tname;
}
} }
1 change: 1 addition & 0 deletions mysql/websql.js
Expand Up @@ -55,5 +55,6 @@ exports.openDatabase = function(db, user, password)
commit.sql = t.clean ? "COMMIT" : "ROLLBACK" commit.sql = t.clean ? "COMMIT" : "ROLLBACK"
}); });
} }
webdb.close = function() { connection.close(); };
return webdb; return webdb;
} }

0 comments on commit 702a56b

Please sign in to comment.