# HG changeset patch # User Atul Varma # Date 1239730830 25200 # Node ID 3fd3aacf33fbf5fe1c6bf1c6a7b79944e1b51101 # Parent f54c719b118d0497ee2406bac15c857199b38a21 Test suite now passes on Safari. diff -r f54c719b118d -r 3fd3aacf33fb browser-couch.js --- a/browser-couch.js Tue Apr 14 10:22:28 2009 -0700 +++ b/browser-couch.js Tue Apr 14 10:40:30 2009 -0700 @@ -34,6 +34,15 @@ * * ***** END LICENSE BLOCK ***** */ +function isArray(value) { + // Taken from "Remedial Javascript" by Douglas Crockford: + // http://javascript.crockford.com/remedial.html + + return (typeof value.length === 'number' && + !(value.propertyIsEnumerable('length')) && + typeof value.splice === 'function'); +} + var ModuleLoader = { LIBS: {JSON: "json2.js"}, @@ -42,7 +51,7 @@ var i = 0; var lastLib = ""; - if (libs.constructor.name != "Array") + if (!isArray(libs)) libs = [libs]; function loadNextLib() { @@ -91,7 +100,7 @@ if (typeof(obj) == "object") { var copy; - if (obj.constructor.name == "Array") + if (isArray(obj)) copy = new Array(); else copy = new Object(); @@ -204,7 +213,7 @@ dict[key] = value; }; - this.delete = function Dictionary_delete(key) { + this.remove = function Dictionary_delete(key) { delete dict[key]; // TODO: If we're in JS 1.6 and have Array.indexOf(), we @@ -250,7 +259,7 @@ }; this.put = function DB_put(document, cb) { - if (document.constructor.name == "Array") { + if (isArray(document)) { for (var i = 0; i < document.length; i++) dict.set(document[i].id, document[i]); } else diff -r f54c719b118d -r 3fd3aacf33fb tests.js --- a/tests.js Tue Apr 14 10:22:28 2009 -0700 +++ b/tests.js Tue Apr 14 10:40:30 2009 -0700 @@ -52,7 +52,7 @@ self.assertEqual(dict.has('foo'), true); self.assertEqual(dict.has('bar'), true); self.assertEqual(dict.has('spatula'), false); - dict.delete('bar'); + dict.remove('bar'); self.assertEqual(dict.getKeys().length, 1); self.assertEqual(dict.has('foo'), true); },