Bug 932763 - Setting mozContact's array properties to an empty array should work. r=gwagner
☠☠ backed out by 9ca5613535ab ☠ ☠
authorReuben Morais <reuben.morais@gmail.com>
Wed, 30 Oct 2013 18:22:16 -0200
changeset 152823 3e4f6dd35a2bf542c406310045d0453fc56781fd
parent 152822 55ffdfba3d1b3616f94ebde62f069722aa0f0c8b
child 152824 b1941b03d0a6fd6b64987870c1fa150d0f0d9309
push id35628
push userryanvm@gmail.com
push dateThu, 31 Oct 2013 02:42:21 +0000
treeherdermozilla-inbound@888fa8b299ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs932763
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 932763 - Setting mozContact's array properties to an empty array should work. r=gwagner
dom/contacts/ContactManager.js
dom/contacts/tests/test_contacts_basics.html
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -171,28 +171,28 @@ function validateArrayField(data, create
     get: function(target, name) {
       if (name === "__exposedProps__") {
         return ArrayPropertyExposedPropsProxy;
       }
       return target[name];
     }
   };
 
-  if (data) {
-    data = Array.isArray(data) ? data : [data];
-    let filtered = [];
-    for (let i = 0, n = data.length; i < n; ++i) {
+  if (data === null || data === undefined) {
+    return undefined;
+  }
+
+  data = Array.isArray(data) ? data : [data];
+  let filtered = [];
+  for (let i = 0, n = data.length; i < n; ++i) {
+    if (data[i]) {
       filtered.push(createCb(data[i]));
     }
-    if (filtered.length === 0) {
-      return undefined;
-    }
-    return new Proxy(filtered, ArrayPropertyHandler);
   }
-  return undefined;
+  return new Proxy(filtered, ArrayPropertyHandler);
 }
 
 // We need this to create a copy of the mozContact object in ContactManager.save
 // Keep in sync with the interfaces.
 const PROPERTIES = [
   "name", "honorificPrefix", "givenName", "additionalName", "familyName",
   "honorificSuffix", "nickname", "photo", "category", "org", "jobTitle",
   "bday", "note", "anniversary", "sex", "genderIdentity", "key"
--- a/dom/contacts/tests/test_contacts_basics.html
+++ b/dom/contacts/tests/test_contacts_basics.html
@@ -1663,16 +1663,32 @@ var steps = [
     const FIELDS = ["email","url","adr","tel","impp"];
     createResult1 = new mozContact();
     for (var prop of FIELDS) {
       createResult1[prop] = {type: ["foo"]};
       ok(Array.isArray(createResult1[prop]), prop + " is array");
     }
     next();
   },
+  function() {
+    ok(true, "Setting array properties to an empty array should work");
+    var c = new mozContact();
+    function testArrayProp(prop) {
+      is(c[prop], null, "property is initially null");
+      c[prop] = [];
+      ok(Array.isArray(c[prop]), "property is an array after setting");
+      is(c[prop].length, 0, "property has length 0 after setting");
+    }
+    testArrayProp("email");
+    testArrayProp("adr");
+    testArrayProp("tel");
+    testArrayProp("impp");
+    testArrayProp("url");
+    next();
+  },
   function () {
     ok(true, "all done!\n");
     clearTemps();
 
     SimpleTest.finish();
   }
 ];