Fix array check for node-webkit
authorIvo Georgiev <ivo@linvo.org>
Tue, 15 Jan 2013 02:55:01 +0000 (02:55 +0000)
committerIvo Georgiev <ivo@linvo.org>
Tue, 15 Jan 2013 02:55:01 +0000 (02:55 +0000)
This seems to be a very weird bug, but when using ejdb with node-webkit, .constructor === Array
returns false for actual arrays. This is because node-webkit runs ejdb as a nodeĀ 
module in a different JavaScript context (WebKit context), so there are actually
two unique objects that represent any constructor (one of each scope). So instead
of comparing if .constructor references to the same object as "Array", we just check
if the name of the constructor is "Array".

node/ejdb.js

index 0a780ea..fb54cdc 100644 (file)
@@ -163,7 +163,7 @@ EJDB.prototype.save = function(cname, jsarr, opts, cb) {
     if (!jsarr) {
         return [];
     }
-    if (jsarr.constructor !== Array) {
+    if (! (jsarr.constructor.name == "Array")) {
         jsarr = [jsarr];
     }
     if (typeof opts == "function") {