Bug 783057 - Expose find results via XPCOM. r=gwagner
authorBobby Holley <bobbyholley@gmail.com>
Fri, 17 Aug 2012 09:50:19 -0700
changeset 102660 6d1deb480cfd2b07da11cc98115dc53e3e91c04f
parent 102659 76a7b5eea991f929c85e7fb1c5d084b684a76cc4
child 102661 0a70fc2d7d251c83b94b8399dde24865a00d71d8
push id23301
push userryanvm@gmail.com
push dateSat, 18 Aug 2012 02:17:26 +0000
treeherdermozilla-central@812ea773f166 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner
bugs783057
milestone17.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 783057 - Expose find results via XPCOM. r=gwagner
dom/contacts/ContactManager.js
--- a/dom/contacts/ContactManager.js
+++ b/dom/contacts/ContactManager.js
@@ -147,17 +147,20 @@ ContactFindOptions.prototype = {
 }
 
 //Contact
 
 const CONTACT_CONTRACTID = "@mozilla.org/contact;1";
 const CONTACT_CID        = Components.ID("{da0f7040-388b-11e1-b86c-0800200c9a66}");
 const nsIDOMContact      = Components.interfaces.nsIDOMContact;
 
-function Contact() { debug("Contact constr: "); };
+// The wrappedJSObject magic here allows callers to get at the underlying JS object
+// of the XPCOM component. We use this below to modify properties that are read-only
+// per-idl. See https://developer.mozilla.org/en-US/docs/wrappedJSObject.
+function Contact() { debug("Contact constr: "); this.wrappedJSObject = this; };
 
 Contact.prototype = {
   
   init: function init(aProp) {
     // Accept non-array strings for DOMString[] properties and convert them.
     function _create(aField) {   
       if (Array.isArray(aField)) {
         for (let i = 0; i < aField.length; i++) {
@@ -314,19 +317,19 @@ ContactManager.prototype = {
     aNewContact.id = aRecord.id;
     aNewContact.published = aRecord.published;
     aNewContact.updated = aRecord.updated;
   },
 
   _convertContactsArray: function(aContacts) {
     let contacts = new Array();
     for (let i in aContacts) {
-      let newContact = new Contact();
+      let newContact = Components.classes['@mozilla.org/contact;1'].createInstance();
       newContact.init(aContacts[i].properties);
-      this._setMetaData(newContact, aContacts[i]);
+      this._setMetaData(newContact.wrappedJSObject, aContacts[i]);
       contacts.push(newContact);
     }
     return contacts;
   },
 
   receiveMessage: function(aMessage) {
     debug("Contactmanager::receiveMessage: " + aMessage.name);
     let msg = aMessage.json;