Bug 951766 - Reintroduce mozContact.init method with a deprecation warning. r=julienw sr=sicking a=1.3+
authorReuben Morais <reuben.morais@gmail.com>
Tue, 21 Jan 2014 16:09:43 -0200
changeset 175912 52e00136eb5c34b70a6f2de8143019592c9c8bbb
parent 175911 72af78a81714f6ae121b871186ec66e5ca2a3377
child 175913 509aafb4f3b234650d5ab20d4c21f6b015990181
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjulienw, sicking, 1
bugs951766
milestone28.0a2
Bug 951766 - Reintroduce mozContact.init method with a deprecation warning. r=julienw sr=sicking a=1.3+
dom/bindings/Bindings.conf
dom/contacts/ContactManager.js
dom/contacts/tests/test_contacts_basics2.html
dom/webidl/Contacts.webidl
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -772,16 +772,22 @@ DOMInterfaces = {
     'nativeType': 'nsDOMMouseScrollEvent',
 },
 
 'MozCanvasPrintState': {
     'headerFile': 'mozilla/dom/HTMLCanvasElement.h',
     'nativeType': 'mozilla::dom::HTMLCanvasPrintState',
 },
 
+'mozContact': {
+    'binaryNames': {
+        'init': 'init_ctor',
+    },
+},
+
 'MozChannel': [
 {
     'nativeType': 'nsIChannel',
     'notflattened': True
 },
 {
     'workers': True,
 }],
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -196,16 +196,18 @@ const PROPERTIES = [
   "name", "honorificPrefix", "givenName", "additionalName", "familyName",
   "honorificSuffix", "nickname", "photo", "category", "org", "jobTitle",
   "bday", "note", "anniversary", "sex", "genderIdentity", "key"
 ];
 const ADDRESS_PROPERTIES = ["adr"];
 const FIELD_PROPERTIES = ["email", "url", "impp"];
 const TELFIELD_PROPERTIES = ["tel"];
 
+let mozContactInitWarned = false;
+
 function Contact() { }
 
 Contact.prototype = {
   // We need to create the content interfaces in these setters, otherwise when
   // we return these objects (e.g. from a find call), the values in the array
   // will be COW's, and content cannot see the properties.
   set email(aEmail) {
     this._email = aEmail;
@@ -298,16 +300,27 @@ Contact.prototype = {
     this.note =            aProp.note;
     this.impp =            aProp.impp;
     this.anniversary =     aProp.anniversary;
     this.sex =             aProp.sex;
     this.genderIdentity =  aProp.genderIdentity;
     this.key =             aProp.key;
   },
 
+  init_ctor: function(aProp) {
+    // init is deprecated, warn once in the console if it's used
+    if (!mozContactInitWarned) {
+      mozContactInitWarned = true;
+      Cu.reportError("mozContact.init is DEPRECATED. Use the mozContact constructor instead. " +
+                     "See https://developer.mozilla.org/docs/WebAPI/Contacts for details.");
+    }
+
+    this.__init(aProp);
+  },
+
   setMetadata: function(aId, aPublished, aUpdated) {
     this.id = aId;
     if (aPublished) {
       this.published = aPublished;
     }
     if (aUpdated) {
       this.updated = aUpdated;
     }
--- a/dom/contacts/tests/test_contacts_basics2.html
+++ b/dom/contacts/tests/test_contacts_basics2.html
@@ -716,16 +716,48 @@ var steps = [
     }
     testArrayProp("email");
     testArrayProp("adr");
     testArrayProp("tel");
     testArrayProp("impp");
     testArrayProp("url");
     next();
   },
+  function() {
+    ok(true, "mozContact.init deprecation message");
+    var c = new mozContact();
+    SimpleTest.monitorConsole(next, [
+      { errorMessage: "mozContact.init is DEPRECATED. Use the mozContact constructor instead. " +
+                      "See https://developer.mozilla.org/docs/WebAPI/Contacts for details." }
+    ], /* forbidUnexpectedMsgs */ true);
+    c.init({name: ["Bar"]});
+    c.init({name: ["Bar"]});
+    SimpleTest.endMonitorConsole();
+  },
+  function() {
+    ok(true, "mozContact.init works as expected");
+    var c = new mozContact({name: ["Foo"]});
+    c.init({name: ["Bar"]});
+    ise(c.name[0], "Bar", "Same name");
+    next();
+  },
+  function() {
+    ok(true, "mozContact.init without parameters");
+    var c = new mozContact({name: ["Foo"]});
+    c.init();
+    next();
+  },
+  function() {
+    ok(true, "mozContact.init resets properties");
+    var c = new mozContact({jobTitle: ["Software Engineer"]});
+    c.init({nickname: ["Jobless Johnny"]});
+    ise(c.nickname[0], "Jobless Johnny", "Same nickname");
+    ok(!c.jobTitle, "jobTitle is not set");
+    next();
+  },
   function () {
     ok(true, "all done!\n");
     SimpleTest.finish();
   }
 ];
 
 function next() {
   ok(true, "Begin!");
--- a/dom/webidl/Contacts.webidl
+++ b/dom/webidl/Contacts.webidl
@@ -138,16 +138,18 @@ interface mozContact {
            attribute object?      honorificSuffix;
            attribute object?      nickname;
            attribute object?      category;
            attribute object?      org;
            attribute object?      jobTitle;
            attribute object?      note;
            attribute object?      key;
 
+  void init(optional ContactProperties properties);
+
   [ChromeOnly]
   void setMetadata(DOMString id, Date? published, Date? updated);
 
   object toJSON();
 };
 
 dictionary ContactFindSortOptions {
   DOMString sortBy;                    // "givenName" or "familyName"