Created
May 16, 2013 04:55
-
-
Save reuben/5589498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* This Source Code Form is subject to the terms of the Mozilla Public | |
| * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
| * You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| "use strict"; | |
| const DEBUG = true; | |
| function debug(s) { dump("-*- ContactManager: " + s + "\n"); } | |
| const Cc = Components.classes; | |
| const Ci = Components.interfaces; | |
| const Cu = Components.utils; | |
| Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | |
| Cu.import("resource://gre/modules/Services.jsm"); | |
| Cu.import("resource://gre/modules/DOMRequestHelper.jsm"); | |
| XPCOMUtils.defineLazyGetter(Services, "DOMRequest", function() { | |
| return Cc["@mozilla.org/dom/dom-request-service;1"].getService(Ci.nsIDOMRequestService); | |
| }); | |
| XPCOMUtils.defineLazyServiceGetter(this, "pm", | |
| "@mozilla.org/permissionmanager;1", | |
| "nsIPermissionManager"); | |
| XPCOMUtils.defineLazyServiceGetter(this, "cpmm", | |
| "@mozilla.org/childprocessmessagemanager;1", | |
| "nsIMessageSender"); | |
| const CONTACTS_SENDMORE_MINIMUM = 5; | |
| function ContactAddress() { } | |
| ContactAddress.prototype = { | |
| __init: function(aType, aStreetAddress, aLocality, aRegion, aPostalCode, aCountryName, aPref) { | |
| this.type = aType; | |
| this.streetAddress = aStreetAddress; | |
| this.locality = aLocality; | |
| this.region = aRegion; | |
| this.postalCode = aPostalCode; | |
| this.countryName = aCountryName; | |
| this.pref = aPref; | |
| }, | |
| toJSON: function() { | |
| return { | |
| type: this.type, | |
| streetAddress: this.streetAddress, | |
| locality: this.locality, | |
| region: this.region, | |
| postalCode: this.postalCode, | |
| countryName: this.countryName, | |
| pref: this.pref | |
| }; | |
| }, | |
| classID: Components.ID("{c5d6eb73-a079-4a9f-8cd5-618194f73b30}"), | |
| contractID: "@mozilla.org/contactAddress;1", | |
| classDescription: "ContactAddress", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]) | |
| }; | |
| function ContactField() { } | |
| ContactField.prototype = { | |
| __init: function(aType, aValue, aPref) { | |
| this.type = aType; | |
| this.value = aValue; | |
| this.pref = aPref; | |
| }, | |
| toJSON: function() { | |
| return { | |
| type: this.type, | |
| value: this.value, | |
| pref: this.pref | |
| }; | |
| }, | |
| classID: Components.ID("{e2cb19c0-e4aa-11e1-9b23-0800200c9a66}"), | |
| contractID: "@mozilla.org/contactField;1", | |
| classDescription: "ContactField", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]) | |
| }; | |
| function ContactTelField() { | |
| ContactField.call(this); | |
| } | |
| ContactTelField.prototype = { | |
| __init: function(aType, aValue, aCarrier, aPref) { | |
| ContactField.prototype.__init.call(this, aType, aValue, aPref); | |
| this.carrier = aCarrier; | |
| }, | |
| toJSON: function() { | |
| return { | |
| type: this.type, | |
| value: this.value, | |
| carrier: this.carrier, | |
| pref: this.pref | |
| }; | |
| }, | |
| classID: Components.ID("{ed0ab260-e4aa-11e1-9b23-0800200c9a66}"), | |
| contractID: "@mozilla.org/contactTelField;1", | |
| classDescription: "ContactTelField", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]) | |
| }; | |
| function ContactFindSortOptions () { } | |
| ContactFindSortOptions.prototype = { | |
| classID: Components.ID("{cb008c06-3bf8-495c-8865-f9ca1673a1e1}"), | |
| contractID: "@mozilla.org/contactFindSortOptions;1", | |
| classDescription: "ContactFindSortOptions", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]) | |
| }; | |
| function ContactFindOptions() { } | |
| ContactFindOptions.prototype = { | |
| classID: Components.ID("{e31daea0-0cb6-11e1-be50-0800200c9a66}"), | |
| contractID: "@mozilla.org/contactFindOptions;1", | |
| classDescription: "ContactFindSortOptions", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]) | |
| }; | |
| function Contact() { } | |
| Contact.prototype = { | |
| init: function(aWindow) { | |
| this._window = aWindow; | |
| }, | |
| set email(aEmail) { | |
| if (aEmail) { | |
| this._email = []; | |
| for (let email of aEmail) { | |
| let obj = new this._window.ContactField(email.type, email.value, email.pref); | |
| this._email.push(obj); | |
| } | |
| } else { | |
| this._email = null; | |
| } | |
| debug("set email"); | |
| }, | |
| get email() { | |
| return this._email; | |
| }, | |
| set impp(aImpp) { | |
| if (aImpp) { | |
| this._impp = []; | |
| for (let impp of aImpp) { | |
| let obj = new this._window.ContactField(impp.type, impp.value, impp.pref); | |
| this._impp.push(obj); | |
| } | |
| } else { | |
| this._impp = null; | |
| } | |
| debug("set impp"); | |
| }, | |
| get impp() { | |
| return this._impp; | |
| }, | |
| __init: function(aProp, aMetadata) { | |
| debug("Contact.init: " + JSON.stringify(aProp)); | |
| this.name = aProp.name; | |
| this.honorificPrefix = aProp.honorificPrefix; | |
| this.givenName = aProp.givenName; | |
| this.additionalName = aProp.additionalName; | |
| this.familyName = aProp.familyName; | |
| this.honorificSuffix = aProp.honorificSuffix; | |
| this.nickname = aProp.nickname; | |
| debug("impp: " + JSON.stringify(aProp.impp)); | |
| this.email = aProp.email; | |
| this.photo = aProp.photo; | |
| this.category = aProp.category; | |
| if (aProp.adr) { | |
| this.adr = []; | |
| for (let adr of aProp.adr) { | |
| let obj = new this._window.ContactAddress(adr.type, adr.streetAddress, adr.locality, adr.region, | |
| adr.postalCode, adr.countryName, adr.pref); | |
| this.adr.push(obj); | |
| } | |
| } else { | |
| this.adr = null; | |
| } | |
| if (aProp.tel) { | |
| this.tel = []; | |
| for (let tel of aProp.tel) { | |
| let obj = new this._window.ContactTelField(tel.type, tel.value, tel.carrier, tel.pref); | |
| this.tel.push(obj); | |
| } | |
| } else { | |
| this.tel = null; | |
| } | |
| this.org = aProp.org; | |
| this.jobTitle = aProp.jobTitle; | |
| this.bday = aProp.bday; | |
| this.note = aProp.note; | |
| if (aProp.url) { | |
| this.url = []; | |
| for (let url of aProp.url) { | |
| let obj = new this._window.ContactField(url.type, url.value, url.pref); | |
| this.url.push(obj); | |
| } | |
| } else { | |
| this.url = null; | |
| } | |
| this.anniversary = aProp.anniversary; | |
| this.sex = (aProp.sex !== "null") ? aProp.sex : null; | |
| this.genderIdentity = (aProp.genderIdentity !== "null") ? aProp.genderIdentity : null; | |
| if (aMetadata) { | |
| debug("published: " + aMetadata.published); | |
| this.id = aMetadata.id; | |
| this.published = aMetadata.published; | |
| this.updated = aMetadata.updated; | |
| } | |
| }, | |
| setMetadata: function(id, published, updated) { | |
| if (id) | |
| this.id = id; | |
| if (published) | |
| this.published = published; | |
| if (updated) | |
| this.updated = updated; | |
| }, | |
| toJSON: function() { | |
| return { | |
| id: this.id, | |
| published: this.published, | |
| updated: this.updated, | |
| name: this.name, | |
| honorificPrefix: this.honorificPrefix, | |
| givenName: this.givenName, | |
| additionalName: this.additionalName, | |
| familyName: this.familyName, | |
| honorificSuffix: this.honorificSuffix, | |
| nickname: this.nickname, | |
| email: this.email, | |
| photo: this.photo, | |
| url: this.url, | |
| category: this.category, | |
| adr: this.adr, | |
| tel: this.tel, | |
| org: this.org, | |
| jobTitle: this.jobTitle, | |
| bday: this.bday, | |
| note: this.note, | |
| impp: this.impp, | |
| anniversary: this.anniversary, | |
| sex: this.sex, | |
| genderIdentity: this.genderIdentity | |
| }; | |
| }, | |
| classID: Components.ID("{72a5ee28-81d8-4af8-90b3-ae935396cc66}"), | |
| contractID: "@mozilla.org/contact;1", | |
| classDescription: "Contact", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer, Ci.nsISupports]) | |
| }; | |
| function ContactManager() { } | |
| ContactManager.prototype = { | |
| __proto__: DOMRequestIpcHelper.prototype, | |
| _oncontactchange: null, | |
| set oncontactchange(aCallback) { | |
| this._oncontactchange = aCallback; | |
| }, | |
| get oncontactchange() { | |
| return this._oncontactchange; | |
| }, | |
| _convertContact: function(aContact) { | |
| return new this._window.mozContact(aContact, {id: aContact.id, | |
| published: aContact.published, | |
| updated: aContact.updated}); | |
| }, | |
| _convertContacts: function(aContacts) { | |
| let contacts = []; | |
| for (let i in aContacts) { | |
| contacts.push(this._convertContact(aContacts[i])); | |
| } | |
| return contacts; | |
| }, | |
| _fireSuccessOrDone: function(aCursor, aResult) { | |
| if (aResult === null) { | |
| Services.DOMRequest.fireDone(aCursor); | |
| } else { | |
| Services.DOMRequest.fireSuccess(aCursor, aResult); | |
| } | |
| }, | |
| _pushArray: function(aArr1, aArr2) { | |
| aArr1.push.apply(aArr1, aArr2); | |
| }, | |
| receiveMessage: function(aMessage) { | |
| if (DEBUG) debug("receiveMessage: " + aMessage.name); | |
| let msg = aMessage.json; | |
| let contacts = msg.contacts; | |
| let req; | |
| switch (aMessage.name) { | |
| case "Contacts:Find:Return:OK": | |
| req = this.getRequest(msg.requestID); | |
| if (req) { | |
| debug("got result: " + JSON.stringify(contacts)); | |
| let result = this._convertContacts(contacts); | |
| Services.DOMRequest.fireSuccess(req.request, result); | |
| } else { | |
| if (DEBUG) debug("no request stored!" + msg.requestID); | |
| } | |
| break; | |
| case "Contacts:GetAll:Next": | |
| let data = this.getRequest(msg.cursorId); | |
| if (!data) { | |
| break; | |
| } | |
| let result = contacts ? this._convertContacts(contacts) : [null]; | |
| if (data.waitingForNext) { | |
| if (DEBUG) debug("cursor waiting for contact, sending"); | |
| data.waitingForNext = false; | |
| let contact = result.shift(); | |
| this._pushArray(data.cachedContacts, result); | |
| this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact)); | |
| if (!contact) { | |
| this.removeRequest(msg.cursorId); | |
| } | |
| } else { | |
| if (DEBUG) debug("cursor not waiting, saving"); | |
| this._pushArray(data.cachedContacts, result); | |
| } | |
| break; | |
| case "Contact:Save:Return:OK": | |
| case "Contacts:Clear:Return:OK": | |
| case "Contact:Remove:Return:OK": | |
| req = this.getRequest(msg.requestID); | |
| if (req) | |
| Services.DOMRequest.fireSuccess(req.request, null); | |
| break; | |
| case "Contacts:Find:Return:KO": | |
| case "Contact:Save:Return:KO": | |
| case "Contact:Remove:Return:KO": | |
| case "Contacts:Clear:Return:KO": | |
| req = this.getRequest(msg.requestID); | |
| if (req) | |
| Services.DOMRequest.fireError(req.request, msg.errorMsg); | |
| break; | |
| case "PermissionPromptHelper:AskPermission:OK": | |
| if (DEBUG) debug("id: " + msg.requestID); | |
| req = this.getRequest(msg.requestID); | |
| if (!req) { | |
| break; | |
| } | |
| if (msg.result === Ci.nsIPermissionManager.ALLOW_ACTION) { | |
| req.allow(); | |
| } else { | |
| req.cancel(); | |
| } | |
| break; | |
| case "Contact:Changed": | |
| // Fire oncontactchange event | |
| if (DEBUG) debug("Contacts:ContactChanged: " + msg.contactID + ", " + msg.reason); | |
| if (this._oncontactchange) { | |
| let event = new this._window.MozContactChangeEvent("contactchanged", { | |
| contactID: msg.contactID, | |
| reason: msg.reason | |
| }); | |
| if (this._oncontactchange) { | |
| this._oncontactchange(event); | |
| } | |
| } | |
| break; | |
| case "Contacts:Revision": | |
| if (DEBUG) debug("new revision: " + msg.revision); | |
| req = this.getRequest(msg.requestID); | |
| if (req) { | |
| Services.DOMRequest.fireSuccess(req, msg.revision); | |
| } | |
| break; | |
| default: | |
| if (DEBUG) debug("Wrong message: " + aMessage.name); | |
| } | |
| this.removeRequest(msg.requestID); | |
| }, | |
| askPermission: function(aAccess, aRequest, aAllowCallback, aCancelCallback) { | |
| if (DEBUG) debug("askPermission for contacts"); | |
| let access; | |
| switch(aAccess) { | |
| case "create": | |
| access = "create"; | |
| break; | |
| case "update": | |
| case "remove": | |
| access = "write"; | |
| break; | |
| case "find": | |
| case "listen": | |
| case "revision": | |
| access = "read"; | |
| break; | |
| default: | |
| access = "unknown"; | |
| } | |
| // Shortcut for ALLOW_ACTION so we avoid a parent roundtrip | |
| let type = "contacts-" + access; | |
| let permValue = | |
| pm.testExactPermissionFromPrincipal(this._window.document.nodePrincipal, type); | |
| if (permValue === Ci.nsIPermissionManager.ALLOW_ACTION) { | |
| aAllowCallback(); | |
| return; | |
| } | |
| let requestID = this.getRequestId({ | |
| request: aRequest, | |
| allow: function() { | |
| aAllowCallback(); | |
| }.bind(this), | |
| cancel : function() { | |
| if (aCancelCallback) { | |
| aCancelCallback(); | |
| } else if (aRequest) { | |
| Services.DOMRequest.fireError(aRequest, "Not Allowed"); | |
| } | |
| }.bind(this) | |
| }); | |
| debug("sending askPermission"); | |
| let principal = this._window.document.nodePrincipal; | |
| cpmm.sendAsyncMessage("PermissionPromptHelper:AskPermission", { | |
| type: "contacts", | |
| access: access, | |
| requestID: requestID, | |
| origin: principal.origin, | |
| appID: principal.appId, | |
| browserFlag: principal.isInBrowserElement | |
| }); | |
| }, | |
| save: function(aContact) { | |
| let request; | |
| if (DEBUG) debug("save: " + JSON.stringify(aContact) + " :" + aContact.id); | |
| let reason; | |
| if (aContact.id === "undefined") { | |
| // for example {25c00f01-90e5-c545-b4d4-21E2ddbab9e0} becomes | |
| // 25c00f0190e5c545b4d421E2ddbab9e0 | |
| aContact.setMetadata(this._getRandomId().replace(/[{}-]/g, "")); | |
| reason = "create"; | |
| } else { | |
| reason = "update"; | |
| } | |
| if (DEBUG) debug("send: " + JSON.stringify(aContact)); | |
| request = this.createRequest(); | |
| let options = { contact: aContact, reason: reason }; | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contact:Save", {requestID: this.getRequestId({request: request, reason: reason}), options: options}); | |
| }.bind(this); | |
| this.askPermission(reason, request, allowCallback); | |
| return request; | |
| }, | |
| find: function(aOptions) { | |
| if (DEBUG) debug("find! " + JSON.stringify(aOptions)); | |
| let request = this.createRequest(); | |
| let options = { findOptions: aOptions }; | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contacts:Find", {requestID: this.getRequestId({request: request, reason: "find"}), options: options}); | |
| }.bind(this); | |
| this.askPermission("find", request, allowCallback); | |
| return request; | |
| }, | |
| createCursor: function() { | |
| let data = { | |
| cursor: Services.DOMRequest.createCursor(this._window, function() { | |
| this.handleContinue(id); | |
| }.bind(this)), | |
| cachedContacts: [], | |
| waitingForNext: true | |
| }; | |
| let id = this.getRequestId(data); | |
| if (DEBUG) debug("saved cursor id: " + id); | |
| return [id, data.cursor]; | |
| }, | |
| getAll: function(aOptions) { | |
| if (DEBUG) debug("getAll: " + JSON.stringify(aOptions)); | |
| let [cursorId, cursor] = this.createCursor(); | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contacts:GetAll", { | |
| cursorId: cursorId, findOptions: aOptions}); | |
| }.bind(this); | |
| this.askPermission("find", cursor, allowCallback); | |
| return cursor; | |
| }, | |
| nextTick: function(aCallback) { | |
| Services.tm.currentThread.dispatch(aCallback, Ci.nsIThread.DISPATCH_NORMAL); | |
| }, | |
| handleContinue: function(aCursorId) { | |
| if (DEBUG) debug("handleContinue: " + aCursorId); | |
| let data = this.getRequest(aCursorId); | |
| if (data.cachedContacts.length > 0) { | |
| if (DEBUG) debug("contact in cache"); | |
| let contact = data.cachedContacts.shift(); | |
| this.nextTick(this._fireSuccessOrDone.bind(this, data.cursor, contact)); | |
| if (!contact) { | |
| this.removeRequest(aCursorId); | |
| } else if (data.cachedContacts.length === CONTACTS_SENDMORE_MINIMUM) { | |
| cpmm.sendAsyncMessage("Contacts:GetAll:SendNow", { cursorId: aCursorId }); | |
| } | |
| } else { | |
| if (DEBUG) debug("waiting for contact"); | |
| data.waitingForNext = true; | |
| } | |
| }, | |
| remove: function(aRecord) { | |
| let request; | |
| request = this.createRequest(); | |
| let options = { id: aRecord.id }; | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contact:Remove", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options}); | |
| }.bind(this); | |
| this.askPermission("remove", request, allowCallback); | |
| return request; | |
| }, | |
| clear: function() { | |
| if (DEBUG) debug("clear"); | |
| let request; | |
| request = this.createRequest(); | |
| let options = {}; | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contacts:Clear", {requestID: this.getRequestId({request: request, reason: "remove"}), options: options}); | |
| }.bind(this); | |
| this.askPermission("remove", request, allowCallback); | |
| return request; | |
| }, | |
| getRevision: function() { | |
| let request = this.createRequest(); | |
| let allowCallback = function() { | |
| cpmm.sendAsyncMessage("Contacts:GetRevision", { | |
| requestID: this.getRequestId(request) | |
| }); | |
| }.bind(this); | |
| let cancelCallback = function() { | |
| Services.DOMRequest.fireError(request); | |
| }; | |
| this.askPermission("revision", request, allowCallback, cancelCallback); | |
| return request; | |
| }, | |
| init: function(aWindow) { | |
| this.initHelper(aWindow, ["Contacts:Find:Return:OK", "Contacts:Find:Return:KO", | |
| "Contacts:Clear:Return:OK", "Contacts:Clear:Return:KO", | |
| "Contact:Save:Return:OK", "Contact:Save:Return:KO", | |
| "Contact:Remove:Return:OK", "Contact:Remove:Return:KO", | |
| "Contact:Changed", | |
| "PermissionPromptHelper:AskPermission:OK", | |
| "Contacts:GetAll:Next", | |
| "Contacts:Revision"]); | |
| cpmm.sendAsyncMessage("Contacts:RegisterForMessages"); | |
| }, | |
| // Called from DOMRequestIpcHelper | |
| uninit: function() { | |
| if (DEBUG) debug("uninit call"); | |
| if (this._oncontactchange) { | |
| this._oncontactchange = null; | |
| } | |
| }, | |
| classID: Components.ID("{1d70322b-f11b-4f19-9586-7bf291f212aa}"), | |
| contractID: "@mozilla.org/contactManager;1", | |
| classDescription: "ContactManager", | |
| QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer, Ci.nsISupports]) | |
| }; | |
| this.NSGetFactory = XPCOMUtils.generateNSGetFactory( | |
| [Contact, ContactManager, ContactAddress, ContactField, ContactTelField, ContactFindSortOptions, ContactFindOptions]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
| /* This Source Code Form is subject to the terms of the Mozilla Public | |
| * License, v. 2.0. If a copy of the MPL was not distributed with this file, | |
| * You can obtain one at http://mozilla.org/MPL/2.0/. | |
| */ | |
| dictionary ContactAddressInitializer { | |
| sequence<DOMString>? type; | |
| DOMString? streetAddress; | |
| DOMString? locality; | |
| DOMString? region; | |
| DOMString? postalCode; | |
| DOMString? countryName; | |
| boolean? pref; | |
| }; | |
| [Constructor(sequence<DOMString> type, DOMString streetAddress, DOMString locality, DOMString region, DOMString postalCode, DOMString countryName, boolean pref), | |
| JSImplementation="@mozilla.org/contactAddress;1"] | |
| interface ContactAddress { | |
| attribute any type; | |
| attribute DOMString streetAddress; | |
| attribute DOMString locality; | |
| attribute DOMString region; | |
| attribute DOMString postalCode; | |
| attribute DOMString countryName; | |
| attribute boolean pref; | |
| object toJSON(); | |
| }; | |
| dictionary ContactFieldInitializer { | |
| sequence<DOMString>? type; | |
| DOMString? value; | |
| boolean? pref; | |
| }; | |
| [Constructor(sequence<DOMString> type, DOMString value, boolean pref), | |
| JSImplementation="@mozilla.org/contactField;1"] | |
| interface ContactField { | |
| attribute any type; | |
| attribute DOMString? value; | |
| attribute boolean? pref; | |
| object toJSON(); | |
| }; | |
| dictionary ContactTelFieldInitializer : ContactFieldInitializer { | |
| DOMString? carrier; | |
| }; | |
| [Constructor(sequence<DOMString> type, DOMString value, DOMString carrier, boolean pref), | |
| JSImplementation="@mozilla.org/contactTelField;1"] | |
| interface ContactTelField : ContactField { | |
| attribute DOMString? carrier; | |
| object toJSON(); | |
| }; | |
| dictionary ContactProperties { | |
| any bday; | |
| any anniversary; | |
| DOMString? sex; | |
| DOMString? genderIdentity; | |
| sequence<Blob>? photo; | |
| sequence<ContactAddressInitializer>? adr; | |
| sequence<ContactFieldInitializer>? email; | |
| sequence<ContactFieldInitializer>? url; | |
| sequence<ContactFieldInitializer>? impp; | |
| sequence<ContactTelFieldInitializer>? tel; | |
| sequence<DOMString>? name; | |
| sequence<DOMString>? honorificPrefix; | |
| sequence<DOMString>? givenName; | |
| sequence<DOMString>? additionalName; | |
| sequence<DOMString>? familyName; | |
| sequence<DOMString>? honorificSuffix; | |
| sequence<DOMString>? nickname; | |
| sequence<DOMString>? category; | |
| sequence<DOMString>? org; | |
| sequence<DOMString>? jobTitle; | |
| sequence<DOMString>? note; | |
| }; | |
| dictionary ContactMetadata { | |
| DOMString id; | |
| any published; | |
| any updated; | |
| }; | |
| [Constructor(optional ContactProperties properties, optional ContactMetadata metadata), | |
| JSImplementation="@mozilla.org/contact;1"] | |
| interface mozContact { | |
| attribute DOMString id; | |
| readonly attribute any published; | |
| readonly attribute any updated; | |
| attribute any bday; | |
| attribute any anniversary; | |
| attribute DOMString sex; | |
| attribute DOMString genderIdentity; | |
| attribute any photo; | |
| attribute any adr; | |
| attribute any email; | |
| attribute any url; | |
| attribute any impp; | |
| attribute any tel; | |
| attribute any name; | |
| attribute any honorificPrefix; | |
| attribute any givenName; | |
| attribute any additionalName; | |
| attribute any familyName; | |
| attribute any honorificSuffix; | |
| attribute any nickname; | |
| attribute any category; | |
| attribute any org; | |
| attribute any jobTitle; | |
| attribute any note; | |
| void setMetadata(DOMString id, optional any published, optional any updated); | |
| object toJSON(); | |
| }; | |
| dictionary ContactFindSortOptions { | |
| DOMString sortBy; // "givenName" or "familyName" | |
| DOMString sortOrder = "ascending"; // e.g. "descending" | |
| }; | |
| dictionary ContactFindOptions : ContactFindSortOptions { | |
| DOMString filterValue; // e.g. "Tom" | |
| DOMString filterOp; // e.g. "contains" | |
| any filterBy; // e.g. ["givenName", "nickname"] | |
| unsigned long filterLimit; | |
| }; | |
| [NoInterfaceObject, NavigatorProperty="mozContacts", | |
| JSImplementation="@mozilla.org/contactManager;1"] | |
| interface ContactManager : EventTarget { | |
| DOMRequest find(optional ContactFindOptions options); | |
| DOMCursor getAll(optional ContactFindSortOptions options); | |
| DOMRequest clear(); | |
| DOMRequest save(mozContact contact); | |
| DOMRequest remove(mozContact contact); | |
| DOMRequest getSimContacts(DOMString type); | |
| attribute EventHandler oncontactchange; | |
| DOMRequest getRevision(); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* THIS FILE IS AUTOGENERATED - DO NOT EDIT */ | |
| #include "AccessCheck.h" | |
| #include "ContactsBinding.h" | |
| #include "DOMCursorBinding.h" | |
| #include "DOMRequestBinding.h" | |
| #include "EventHandlerBinding.h" | |
| #include "EventTargetBinding.h" | |
| #include "FileReaderSyncBinding.h" | |
| #include "PrimitiveConversions.h" | |
| #include "XPCQuickStubs.h" | |
| #include "XPCWrapper.h" | |
| #include "mozilla/dom/BindingUtils.h" | |
| #include "mozilla/dom/DOMCursor.h" | |
| #include "mozilla/dom/DOMRequest.h" | |
| #include "mozilla/dom/Nullable.h" | |
| #include "nsContentUtils.h" | |
| #include "nsDOMQS.h" | |
| #include "nsIDOMGlobalPropertyInitializer.h" | |
| using namespace mozilla::dom; | |
| namespace mozilla { | |
| namespace dom { | |
| bool ContactAddressInitializer::initedIds = false; | |
| jsid ContactAddressInitializer::countryName_id = JSID_VOID; | |
| jsid ContactAddressInitializer::locality_id = JSID_VOID; | |
| jsid ContactAddressInitializer::postalCode_id = JSID_VOID; | |
| jsid ContactAddressInitializer::pref_id = JSID_VOID; | |
| jsid ContactAddressInitializer::region_id = JSID_VOID; | |
| jsid ContactAddressInitializer::streetAddress_id = JSID_VOID; | |
| jsid ContactAddressInitializer::type_id = JSID_VOID; | |
| bool | |
| ContactAddressInitializer::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, countryName_id, "countryName") || | |
| !InternJSString(cx, locality_id, "locality") || | |
| !InternJSString(cx, postalCode_id, "postalCode") || | |
| !InternJSString(cx, pref_id, "pref") || | |
| !InternJSString(cx, region_id, "region") || | |
| !InternJSString(cx, streetAddress_id, "streetAddress") || | |
| !InternJSString(cx, type_id, "type")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactAddressInitializer::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), countryName_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mCountryName.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), countryName_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mCountryName.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), locality_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mLocality.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), locality_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mLocality.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), postalCode_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mPostalCode.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), postalCode_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mPostalCode.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), pref_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mPref.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), pref_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isNullOrUndefined()) { | |
| (mPref.Value()).SetNull(); | |
| } else if (!ValueToPrimitive<bool, eDefault>(cx, temp, &(mPref.Value()).SetValue())) { | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), region_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mRegion.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), region_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mRegion.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), streetAddress_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mStreetAddress.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), streetAddress_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mStreetAddress.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), type_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mType.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), type_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mType.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mType.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactAddressInitializer::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactAddressInitializer::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); | |
| if (!obj) { | |
| return false; | |
| } | |
| *vp = JS::ObjectValue(*obj); | |
| if (mCountryName.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mCountryName.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, countryName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mLocality.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mLocality.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, locality_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mPostalCode.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mPostalCode.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, postalCode_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mPref.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<bool>& currentValue = mPref.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, pref_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| temp = BOOLEAN_TO_JSVAL(currentValue.Value()); | |
| if (!JS_DefinePropertyById(cx, obj, pref_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mRegion.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mRegion.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, region_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mStreetAddress.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mStreetAddress.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, streetAddress_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mType.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mType.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, type_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, type_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| bool ContactFieldInitializer::initedIds = false; | |
| jsid ContactFieldInitializer::pref_id = JSID_VOID; | |
| jsid ContactFieldInitializer::type_id = JSID_VOID; | |
| jsid ContactFieldInitializer::value_id = JSID_VOID; | |
| bool | |
| ContactFieldInitializer::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, pref_id, "pref") || | |
| !InternJSString(cx, type_id, "type") || | |
| !InternJSString(cx, value_id, "value")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactFieldInitializer::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), pref_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mPref.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), pref_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isNullOrUndefined()) { | |
| (mPref.Value()).SetNull(); | |
| } else if (!ValueToPrimitive<bool, eDefault>(cx, temp, &(mPref.Value()).SetValue())) { | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), type_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mType.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), type_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mType.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mType.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), value_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mValue.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), value_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mValue.Value()) = str; | |
| } | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactFieldInitializer::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactFieldInitializer::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); | |
| if (!obj) { | |
| return false; | |
| } | |
| *vp = JS::ObjectValue(*obj); | |
| if (mPref.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<bool>& currentValue = mPref.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, pref_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| temp = BOOLEAN_TO_JSVAL(currentValue.Value()); | |
| if (!JS_DefinePropertyById(cx, obj, pref_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mType.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mType.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, type_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, type_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mValue.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mValue.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, value_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| bool ContactFindSortOptions::initedIds = false; | |
| jsid ContactFindSortOptions::sortBy_id = JSID_VOID; | |
| jsid ContactFindSortOptions::sortOrder_id = JSID_VOID; | |
| bool | |
| ContactFindSortOptions::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, sortBy_id, "sortBy") || | |
| !InternJSString(cx, sortOrder_id, "sortOrder")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactFindSortOptions::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), sortBy_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mSortBy.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), sortBy_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| (mSortBy.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), sortOrder_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| if (!JS_GetPropertyById(cx, &val.toObject(), sortOrder_id, temp.address())) { | |
| return false; | |
| } | |
| } | |
| { | |
| FakeDependentString str; | |
| if (found) { | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| } else { | |
| static const PRUnichar data[] = { 'a', 's', 'c', 'e', 'n', 'd', 'i', 'n', 'g', 0 }; | |
| str.SetData(data, ArrayLength(data) - 1); | |
| } | |
| mSortOrder = str; | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactFindSortOptions::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactFindSortOptions::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); | |
| if (!obj) { | |
| return false; | |
| } | |
| *vp = JS::ObjectValue(*obj); | |
| if (mSortBy.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mSortBy.Value(); | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, sortBy_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mSortOrder; | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, sortOrder_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| return true; | |
| } | |
| bool ContactMetadata::initedIds = false; | |
| jsid ContactMetadata::id_id = JSID_VOID; | |
| jsid ContactMetadata::published_id = JSID_VOID; | |
| jsid ContactMetadata::updated_id = JSID_VOID; | |
| bool | |
| ContactMetadata::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, id_id, "id") || | |
| !InternJSString(cx, published_id, "published") || | |
| !InternJSString(cx, updated_id, "updated")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactMetadata::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), id_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mId.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), id_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| (mId.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), published_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mPublished.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), published_id, temp.address())) { | |
| return false; | |
| } | |
| (mPublished.Value()).construct(cx, temp); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), updated_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mUpdated.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), updated_id, temp.address())) { | |
| return false; | |
| } | |
| (mUpdated.Value()).construct(cx, temp); | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactMetadata::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactMetadata::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); | |
| if (!obj) { | |
| return false; | |
| } | |
| *vp = JS::ObjectValue(*obj); | |
| if (mId.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mId.Value(); | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, id_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mPublished.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const LazyRootedValue& currentValue = mPublished.Value(); | |
| temp = currentValue; | |
| if (!MaybeWrapValue(cx, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, published_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mUpdated.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const LazyRootedValue& currentValue = mUpdated.Value(); | |
| temp = currentValue; | |
| if (!MaybeWrapValue(cx, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, updated_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| bool ContactFindOptions::initedIds = false; | |
| jsid ContactFindOptions::filterBy_id = JSID_VOID; | |
| jsid ContactFindOptions::filterLimit_id = JSID_VOID; | |
| jsid ContactFindOptions::filterOp_id = JSID_VOID; | |
| jsid ContactFindOptions::filterValue_id = JSID_VOID; | |
| bool | |
| ContactFindOptions::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, filterBy_id, "filterBy") || | |
| !InternJSString(cx, filterLimit_id, "filterLimit") || | |
| !InternJSString(cx, filterOp_id, "filterOp") || | |
| !InternJSString(cx, filterValue_id, "filterValue")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactFindOptions::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| // Per spec, we init the parent's members first | |
| if (!ContactFindSortOptions::Init(cx, val)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), filterBy_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mFilterBy.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), filterBy_id, temp.address())) { | |
| return false; | |
| } | |
| (mFilterBy.Value()).construct(cx, temp); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), filterLimit_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mFilterLimit.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), filterLimit_id, temp.address())) { | |
| return false; | |
| } | |
| if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp, &(mFilterLimit.Value()))) { | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), filterOp_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mFilterOp.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), filterOp_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| (mFilterOp.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), filterValue_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mFilterValue.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), filterValue_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| (mFilterValue.Value()) = str; | |
| } | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactFindOptions::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactFindOptions::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| // Per spec, we define the parent's members first | |
| if (!ContactFindSortOptions::ToObject(cx, parentObject, vp)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, &vp->toObject()); | |
| if (mFilterBy.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const LazyRootedValue& currentValue = mFilterBy.Value(); | |
| temp = currentValue; | |
| if (!MaybeWrapValue(cx, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, filterBy_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mFilterLimit.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const uint32_t& currentValue = mFilterLimit.Value(); | |
| temp = UINT_TO_JSVAL(currentValue); | |
| if (!JS_DefinePropertyById(cx, obj, filterLimit_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mFilterOp.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mFilterOp.Value(); | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, filterOp_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mFilterValue.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mFilterValue.Value(); | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, filterValue_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| bool ContactTelFieldInitializer::initedIds = false; | |
| jsid ContactTelFieldInitializer::carrier_id = JSID_VOID; | |
| bool | |
| ContactTelFieldInitializer::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, carrier_id, "carrier")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactTelFieldInitializer::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| // Per spec, we init the parent's members first | |
| if (!ContactFieldInitializer::Init(cx, val)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), carrier_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mCarrier.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), carrier_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mCarrier.Value()) = str; | |
| } | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactTelFieldInitializer::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactTelFieldInitializer::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| // Per spec, we define the parent's members first | |
| if (!ContactFieldInitializer::ToObject(cx, parentObject, vp)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, &vp->toObject()); | |
| if (mCarrier.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mCarrier.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, carrier_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| bool ContactProperties::initedIds = false; | |
| jsid ContactProperties::additionalName_id = JSID_VOID; | |
| jsid ContactProperties::adr_id = JSID_VOID; | |
| jsid ContactProperties::anniversary_id = JSID_VOID; | |
| jsid ContactProperties::bday_id = JSID_VOID; | |
| jsid ContactProperties::category_id = JSID_VOID; | |
| jsid ContactProperties::email_id = JSID_VOID; | |
| jsid ContactProperties::familyName_id = JSID_VOID; | |
| jsid ContactProperties::genderIdentity_id = JSID_VOID; | |
| jsid ContactProperties::givenName_id = JSID_VOID; | |
| jsid ContactProperties::honorificPrefix_id = JSID_VOID; | |
| jsid ContactProperties::honorificSuffix_id = JSID_VOID; | |
| jsid ContactProperties::impp_id = JSID_VOID; | |
| jsid ContactProperties::jobTitle_id = JSID_VOID; | |
| jsid ContactProperties::name_id = JSID_VOID; | |
| jsid ContactProperties::nickname_id = JSID_VOID; | |
| jsid ContactProperties::note_id = JSID_VOID; | |
| jsid ContactProperties::org_id = JSID_VOID; | |
| jsid ContactProperties::photo_id = JSID_VOID; | |
| jsid ContactProperties::sex_id = JSID_VOID; | |
| jsid ContactProperties::tel_id = JSID_VOID; | |
| jsid ContactProperties::url_id = JSID_VOID; | |
| bool | |
| ContactProperties::InitIds(JSContext* cx) | |
| { | |
| MOZ_ASSERT(!initedIds); | |
| if (!InternJSString(cx, additionalName_id, "additionalName") || | |
| !InternJSString(cx, adr_id, "adr") || | |
| !InternJSString(cx, anniversary_id, "anniversary") || | |
| !InternJSString(cx, bday_id, "bday") || | |
| !InternJSString(cx, category_id, "category") || | |
| !InternJSString(cx, email_id, "email") || | |
| !InternJSString(cx, familyName_id, "familyName") || | |
| !InternJSString(cx, genderIdentity_id, "genderIdentity") || | |
| !InternJSString(cx, givenName_id, "givenName") || | |
| !InternJSString(cx, honorificPrefix_id, "honorificPrefix") || | |
| !InternJSString(cx, honorificSuffix_id, "honorificSuffix") || | |
| !InternJSString(cx, impp_id, "impp") || | |
| !InternJSString(cx, jobTitle_id, "jobTitle") || | |
| !InternJSString(cx, name_id, "name") || | |
| !InternJSString(cx, nickname_id, "nickname") || | |
| !InternJSString(cx, note_id, "note") || | |
| !InternJSString(cx, org_id, "org") || | |
| !InternJSString(cx, photo_id, "photo") || | |
| !InternJSString(cx, sex_id, "sex") || | |
| !InternJSString(cx, tel_id, "tel") || | |
| !InternJSString(cx, url_id, "url")) { | |
| return false; | |
| } | |
| initedIds = true; | |
| return true; | |
| } | |
| bool | |
| ContactProperties::Init(JSContext* cx, JS::Handle<JS::Value> val) | |
| { | |
| // Passing a null JSContext is OK only if we're initing from null, | |
| // Since in that case we will not have to do any property gets | |
| MOZ_ASSERT_IF(!cx, val.isNull()); | |
| if (cx && !initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JSBool found; | |
| JS::Rooted<JS::Value> temp(cx); | |
| bool isNull = val.isNullOrUndefined(); | |
| if (!IsConvertibleToDictionary(cx, val)) { | |
| return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), additionalName_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mAdditionalName.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), additionalName_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mAdditionalName.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mAdditionalName.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), adr_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mAdr.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), adr_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<ContactAddressInitializer > &arr = (mAdr.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| ContactAddressInitializer& slot = *arr.AppendElement(); | |
| if (!slot.Init(cx, temp)) { | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mAdr.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), anniversary_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mAnniversary.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), anniversary_id, temp.address())) { | |
| return false; | |
| } | |
| (mAnniversary.Value()).construct(cx, temp); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), bday_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mBday.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), bday_id, temp.address())) { | |
| return false; | |
| } | |
| (mBday.Value()).construct(cx, temp); | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), category_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mCategory.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), category_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mCategory.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mCategory.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), email_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mEmail.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), email_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<ContactFieldInitializer > &arr = (mEmail.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| ContactFieldInitializer& slot = *arr.AppendElement(); | |
| if (!slot.Init(cx, temp)) { | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mEmail.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), familyName_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mFamilyName.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), familyName_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mFamilyName.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mFamilyName.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), genderIdentity_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mGenderIdentity.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), genderIdentity_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mGenderIdentity.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), givenName_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mGivenName.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), givenName_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mGivenName.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mGivenName.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), honorificPrefix_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mHonorificPrefix.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), honorificPrefix_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mHonorificPrefix.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mHonorificPrefix.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), honorificSuffix_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mHonorificSuffix.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), honorificSuffix_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mHonorificSuffix.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mHonorificSuffix.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), impp_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mImpp.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), impp_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<ContactFieldInitializer > &arr = (mImpp.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| ContactFieldInitializer& slot = *arr.AppendElement(); | |
| if (!slot.Init(cx, temp)) { | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mImpp.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), jobTitle_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mJobTitle.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), jobTitle_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mJobTitle.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mJobTitle.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), name_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mName.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), name_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mName.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mName.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), nickname_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mNickname.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), nickname_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mNickname.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mNickname.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), note_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mNote.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), note_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mNote.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mNote.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), org_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mOrg.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), org_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsString > &arr = (mOrg.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mOrg.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), photo_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mPhoto.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), photo_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<nsRefPtr<nsIDOMBlob> > &arr = (mPhoto.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsRefPtr<nsIDOMBlob>& slot = *arr.AppendElement(); | |
| if (temp.isObject()) { | |
| nsRefPtr<nsIDOMBlob> tempHolder; | |
| JS::Rooted<JS::Value> tmpVal(cx, temp); | |
| nsIDOMBlob* tmp; | |
| if (NS_FAILED(xpc_qsUnwrapArg<nsIDOMBlob>(cx, temp, &tmp, static_cast<nsIDOMBlob**>(getter_AddRefs(tempHolder)), tmpVal.address()))) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Blob");return false; | |
| } | |
| MOZ_ASSERT(tmp); | |
| slot = tmp; | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mPhoto.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), sex_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mSex.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), sex_id, temp.address())) { | |
| return false; | |
| } | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eNull, eNull, str)) { | |
| return false; | |
| } | |
| (mSex.Value()) = str; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), tel_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mTel.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), tel_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<ContactTelFieldInitializer > &arr = (mTel.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| ContactTelFieldInitializer& slot = *arr.AppendElement(); | |
| if (!slot.Init(cx, temp)) { | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mTel.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| if (isNull) { | |
| found = false; | |
| } else if (!JS_HasPropertyById(cx, &val.toObject(), url_id, &found)) { | |
| return false; | |
| } | |
| if (found) { | |
| mUrl.Construct(); | |
| if (!JS_GetPropertyById(cx, &val.toObject(), url_id, temp.address())) { | |
| return false; | |
| } | |
| if (temp.isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &temp.toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| Sequence<ContactFieldInitializer > &arr = (mUrl.Value()).SetValue(); | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| ContactFieldInitializer& slot = *arr.AppendElement(); | |
| if (!slot.Init(cx, temp)) { | |
| return false; | |
| } | |
| } | |
| } else if (temp.isNullOrUndefined()) { | |
| (mUrl.Value()).SetNull(); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| bool | |
| ContactProperties::Init(const nsAString& aJSON) | |
| { | |
| AutoSafeJSContext cx; | |
| JSAutoRequest ar(cx); | |
| JS::Rooted<JS::Value> json(cx); | |
| bool ok = ParseJSON(cx, aJSON, &json); | |
| NS_ENSURE_TRUE(ok, false); | |
| return Init(cx, json); | |
| } | |
| bool | |
| ContactProperties::ToObject(JSContext* cx, JS::Handle<JSObject*> parentObject, JS::Value *vp) const | |
| { | |
| if (!initedIds && !InitIds(cx)) { | |
| return false; | |
| } | |
| JS::Rooted<JSObject*> obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); | |
| if (!obj) { | |
| return false; | |
| } | |
| *vp = JS::ObjectValue(*obj); | |
| if (mAdditionalName.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mAdditionalName.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, additionalName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, additionalName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mAdr.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<ContactAddressInitializer > >& currentValue = mAdr.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, adr_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!currentValue.Value()[sequenceIdx0].ToObject(cx, returnArray, tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, adr_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mAnniversary.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const LazyRootedValue& currentValue = mAnniversary.Value(); | |
| temp = currentValue; | |
| if (!MaybeWrapValue(cx, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, anniversary_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mBday.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const LazyRootedValue& currentValue = mBday.Value(); | |
| temp = currentValue; | |
| if (!MaybeWrapValue(cx, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, bday_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mCategory.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mCategory.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, category_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, category_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mEmail.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<ContactFieldInitializer > >& currentValue = mEmail.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, email_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!currentValue.Value()[sequenceIdx0].ToObject(cx, returnArray, tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, email_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mFamilyName.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mFamilyName.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, familyName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, familyName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mGenderIdentity.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mGenderIdentity.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, genderIdentity_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mGivenName.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mGivenName.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, givenName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, givenName_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mHonorificPrefix.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mHonorificPrefix.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, honorificPrefix_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, honorificPrefix_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mHonorificSuffix.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mHonorificSuffix.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, honorificSuffix_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, honorificSuffix_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mImpp.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<ContactFieldInitializer > >& currentValue = mImpp.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, impp_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!currentValue.Value()[sequenceIdx0].ToObject(cx, returnArray, tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, impp_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mJobTitle.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mJobTitle.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, jobTitle_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, jobTitle_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mName.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mName.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, name_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, name_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mNickname.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mNickname.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, nickname_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, nickname_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mNote.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mNote.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, note_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, note_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mOrg.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsString > >& currentValue = mOrg.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, org_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, org_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mPhoto.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<nsRefPtr<nsIDOMBlob> > >& currentValue = mPhoto.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, photo_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!WrapObject(cx, returnArray, currentValue.Value()[sequenceIdx0], tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, photo_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mSex.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const nsString& currentValue = mSex.Value(); | |
| if (!xpc::StringToJsval(cx, currentValue, temp.address())) { | |
| return false; | |
| } | |
| if (!JS_DefinePropertyById(cx, obj, sex_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mTel.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<ContactTelFieldInitializer > >& currentValue = mTel.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, tel_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!currentValue.Value()[sequenceIdx0].ToObject(cx, returnArray, tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, tel_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| if (mUrl.WasPassed()) { | |
| do { | |
| // block for our 'break' successCode and scope for 'temp' and 'currentValue' | |
| JS::Rooted<JS::Value> temp(cx); | |
| const Nullable<Sequence<ContactFieldInitializer > >& currentValue = mUrl.Value(); | |
| if (currentValue.IsNull()) { | |
| temp = JSVAL_NULL; | |
| if (!JS_DefinePropertyById(cx, obj, url_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } | |
| uint32_t length = currentValue.Value().Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| return false; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!currentValue.Value()[sequenceIdx0].ToObject(cx, returnArray, tmp.address())) { | |
| return false; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| } | |
| } | |
| temp = JS::ObjectValue(*returnArray); | |
| if (!JS_DefinePropertyById(cx, obj, url_id, temp, nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| return false; | |
| } | |
| break; | |
| } while(0); | |
| } | |
| return true; | |
| } | |
| namespace ContactAddressBinding { | |
| static bool | |
| get_type(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetType(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "type"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_type(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetType(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "type"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo type_getterinfo = { | |
| (JSJitPropertyOp)get_type, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo type_setterinfo = { | |
| (JSJitPropertyOp)set_type, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_streetAddress(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetStreetAddress(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "streetAddress"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_streetAddress(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetStreetAddress(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "streetAddress"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo streetAddress_getterinfo = { | |
| (JSJitPropertyOp)get_streetAddress, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo streetAddress_setterinfo = { | |
| (JSJitPropertyOp)set_streetAddress, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_locality(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetLocality(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "locality"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_locality(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetLocality(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "locality"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo locality_getterinfo = { | |
| (JSJitPropertyOp)get_locality, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo locality_setterinfo = { | |
| (JSJitPropertyOp)set_locality, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_region(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetRegion(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "region"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_region(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetRegion(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "region"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo region_getterinfo = { | |
| (JSJitPropertyOp)get_region, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo region_setterinfo = { | |
| (JSJitPropertyOp)set_region, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_postalCode(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetPostalCode(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "postalCode"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_postalCode(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetPostalCode(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "postalCode"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo postalCode_getterinfo = { | |
| (JSJitPropertyOp)get_postalCode, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo postalCode_setterinfo = { | |
| (JSJitPropertyOp)set_postalCode, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_countryName(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetCountryName(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "countryName"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_countryName(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetCountryName(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "countryName"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo countryName_getterinfo = { | |
| (JSJitPropertyOp)get_countryName, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo countryName_setterinfo = { | |
| (JSJitPropertyOp)set_countryName, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_pref(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| bool result; | |
| result = self->GetPref(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "pref"); | |
| } | |
| *vp = BOOLEAN_TO_JSVAL(result); | |
| return true; | |
| } | |
| static bool | |
| set_pref(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, JS::Value* argv) | |
| { | |
| bool arg0; | |
| if (!ValueToPrimitive<bool, eDefault>(cx, argv[0], &arg0)) { | |
| return false; | |
| } | |
| ErrorResult rv; | |
| self->SetPref(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "pref"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo pref_getterinfo = { | |
| (JSJitPropertyOp)get_pref, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_INT32 /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo pref_setterinfo = { | |
| (JSJitPropertyOp)set_pref, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| toJSON(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactAddress* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JSObject* result; | |
| result = self->ToJSON(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "toJSON"); | |
| } | |
| *vp = JS::ObjectValue(*result); | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo toJSON_methodinfo = { | |
| (JSJitPropertyOp)toJSON, | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static JSBool | |
| genericMethod(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactAddress* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactAddress, mozilla::dom::ContactAddress>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactAddress"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Method); | |
| JSJitMethodOp method = (JSJitMethodOp)info->op; | |
| return method(cx, obj, self, argc, vp); | |
| } | |
| static JSBool | |
| genericGetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactAddress* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactAddress, mozilla::dom::ContactAddress>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactAddress"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Getter); | |
| JSJitPropertyOp getter = info->op; | |
| return getter(cx, obj, self, vp); | |
| } | |
| static JSBool | |
| genericSetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactAddress* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactAddress, mozilla::dom::ContactAddress>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactAddress"); | |
| } | |
| } | |
| if (argc == 0) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactAddress attribute setter"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Setter); | |
| JSJitPropertyOp setter = info->op; | |
| if (!setter(cx, obj, self, argv)) { | |
| return false; | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static JSBool | |
| _addProperty(JSContext* cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactAddress>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactAddress* self = UnwrapDOMObject<mozilla::dom::ContactAddress>(obj); | |
| // We don't want to preserve if we don't have a wrapper. | |
| if (self->GetWrapperPreserveColor()) { | |
| nsContentUtils::PreserveWrapper(reinterpret_cast<nsISupports*>(self), self); | |
| } | |
| return true; | |
| } | |
| static void | |
| _finalize(JSFreeOp* fop, JSObject* obj) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactAddress>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactAddress* self = UnwrapDOMObject<mozilla::dom::ContactAddress>(obj); | |
| if (self) { | |
| JSBindingFinalized<mozilla::dom::ContactAddress>::Finalized(self); | |
| ClearWrapper(self, self); | |
| XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); | |
| if (rt) { | |
| rt->DeferredRelease(reinterpret_cast<nsISupports*>(self)); | |
| } else { | |
| NS_RELEASE(self); | |
| } | |
| } | |
| } | |
| static const JSFunctionSpec sMethods_specs[] = { | |
| JS_FNINFO("toJSON", genericMethod, &toJSON_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sMethods[] = { | |
| { true, nullptr, &sMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sMethods_ids[2] = { JSID_VOID }; | |
| static const JSFunctionSpec sChromeMethods_specs[] = { | |
| JS_FNINFO("QueryInterface", QueryInterface, nullptr, 1, 0), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sChromeMethods[] = { | |
| { true, nullptr, &sChromeMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sChromeMethods_ids[2] = { JSID_VOID }; | |
| static const JSPropertySpec sAttributes_specs[] = { | |
| { "type", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &type_getterinfo }, { (JSStrictPropertyOp)genericSetter, &type_setterinfo }}, | |
| { "streetAddress", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &streetAddress_getterinfo }, { (JSStrictPropertyOp)genericSetter, &streetAddress_setterinfo }}, | |
| { "locality", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &locality_getterinfo }, { (JSStrictPropertyOp)genericSetter, &locality_setterinfo }}, | |
| { "region", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, ®ion_getterinfo }, { (JSStrictPropertyOp)genericSetter, ®ion_setterinfo }}, | |
| { "postalCode", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &postalCode_getterinfo }, { (JSStrictPropertyOp)genericSetter, &postalCode_setterinfo }}, | |
| { "countryName", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &countryName_getterinfo }, { (JSStrictPropertyOp)genericSetter, &countryName_setterinfo }}, | |
| { "pref", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &pref_getterinfo }, { (JSStrictPropertyOp)genericSetter, &pref_setterinfo }}, | |
| { 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSPropertySpec> sAttributes[] = { | |
| { true, nullptr, &sAttributes_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sAttributes_ids[8] = { JSID_VOID }; | |
| static const NativeProperties sNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sMethods, sMethods_ids, sMethods_specs, | |
| sAttributes, sAttributes_ids, sAttributes_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| static const NativeProperties sChromeOnlyNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sChromeMethods, sChromeMethods_ids, sChromeMethods_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| const NativePropertyHooks sNativePropertyHooks = { | |
| nullptr, | |
| nullptr, | |
| { &sNativeProperties, &sChromeOnlyNativeProperties }, | |
| prototypes::id::ContactAddress, | |
| constructors::id::ContactAddress, | |
| NULL | |
| }; | |
| static JSBool | |
| _constructor(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); | |
| if (argc < 7) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactAddress.constructor"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| GlobalObject global(cx, obj); | |
| if (global.Failed()) { | |
| return false; | |
| } | |
| AutoSequence<nsString > arg0; | |
| if (argv[0].isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &argv[0].toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| AutoSequence<nsString > &arr = arg0; | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| FakeDependentString arg1_holder; | |
| NonNull<nsAString> arg1; | |
| if (!ConvertJSValueToString(cx, argv[1], &argv[1], eStringify, eStringify, arg1_holder)) { | |
| return false; | |
| } | |
| arg1 = &arg1_holder; | |
| FakeDependentString arg2_holder; | |
| NonNull<nsAString> arg2; | |
| if (!ConvertJSValueToString(cx, argv[2], &argv[2], eStringify, eStringify, arg2_holder)) { | |
| return false; | |
| } | |
| arg2 = &arg2_holder; | |
| FakeDependentString arg3_holder; | |
| NonNull<nsAString> arg3; | |
| if (!ConvertJSValueToString(cx, argv[3], &argv[3], eStringify, eStringify, arg3_holder)) { | |
| return false; | |
| } | |
| arg3 = &arg3_holder; | |
| FakeDependentString arg4_holder; | |
| NonNull<nsAString> arg4; | |
| if (!ConvertJSValueToString(cx, argv[4], &argv[4], eStringify, eStringify, arg4_holder)) { | |
| return false; | |
| } | |
| arg4 = &arg4_holder; | |
| FakeDependentString arg5_holder; | |
| NonNull<nsAString> arg5; | |
| if (!ConvertJSValueToString(cx, argv[5], &argv[5], eStringify, eStringify, arg5_holder)) { | |
| return false; | |
| } | |
| arg5 = &arg5_holder; | |
| bool arg6; | |
| if (!ValueToPrimitive<bool, eDefault>(cx, argv[6], &arg6)) { | |
| return false; | |
| } | |
| Maybe<JSAutoCompartment> ac; | |
| if (xpc::WrapperFactory::IsXrayWrapper(obj)) { | |
| obj = js::CheckedUnwrap(obj); | |
| if (!obj) { | |
| return false; | |
| } | |
| ac.construct(cx, obj); | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::ContactAddress > result; | |
| result = mozilla::dom::ContactAddress::Constructor(global, cx, Constify(arg0), Constify(arg1), Constify(arg2), Constify(arg3), Constify(arg4), Constify(arg5), arg6, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactAddress", "constructor"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static DOMIfaceAndProtoJSClass InterfaceObjectClass = { | |
| { | |
| "Function", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| _constructor, /* call */ | |
| InterfaceHasInstance, /* hasInstance */ | |
| _constructor, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterface, | |
| &sNativePropertyHooks, | |
| "function ContactAddress() {\n [native code]\n}", | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth | |
| }; | |
| static DOMIfaceAndProtoJSClass PrototypeClass = { | |
| { | |
| "ContactAddressPrototype", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| nullptr, /* call */ | |
| nullptr, /* hasInstance */ | |
| nullptr, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterfacePrototype, | |
| &sNativePropertyHooks, | |
| "[object ContactAddressPrototype]", | |
| prototypes::id::ContactAddress, | |
| PrototypeTraits<prototypes::id::ContactAddress>::Depth | |
| }; | |
| void | |
| CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JSObject** protoAndIfaceArray) | |
| { | |
| JS::Rooted<JSObject*> parentProto(aCx, JS_GetObjectPrototype(aCx, aGlobal)); | |
| if (!parentProto) { | |
| return; | |
| } | |
| JS::Rooted<JSObject*> constructorProto(aCx, JS_GetFunctionPrototype(aCx, aGlobal)); | |
| if (!constructorProto) { | |
| return; | |
| } | |
| if (sChromeMethods_ids[0] == JSID_VOID && | |
| (!InitIds(aCx, sChromeMethods, sChromeMethods_ids) || | |
| !InitIds(aCx, sMethods, sMethods_ids) || | |
| !InitIds(aCx, sAttributes, sAttributes_ids))) { | |
| sChromeMethods_ids[0] = JSID_VOID; | |
| return; | |
| } | |
| dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, | |
| &PrototypeClass.mBase, &protoAndIfaceArray[prototypes::id::ContactAddress], | |
| constructorProto, &InterfaceObjectClass.mBase, nullptr, 7, nullptr, | |
| &protoAndIfaceArray[constructors::id::ContactAddress], | |
| &Class.mClass, | |
| &sNativeProperties, | |
| xpc::AccessCheck::isChrome(aGlobal) ? &sChromeOnlyNativeProperties : nullptr, | |
| "ContactAddress"); | |
| } | |
| JSObject* | |
| DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool* aEnabled) | |
| { | |
| *aEnabled = true; | |
| return GetConstructorObject(aCx, aGlobal); | |
| } | |
| DOMJSClass Class = { | |
| { "ContactAddress", | |
| JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(3), | |
| _addProperty, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| _finalize, /* finalize */ | |
| NULL, /* checkAccess */ | |
| nullptr, /* call */ | |
| NULL, /* hasInstance */ | |
| NULL, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| { | |
| { prototypes::id::ContactAddress, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, | |
| true, | |
| &sNativePropertyHooks, | |
| GetParentObject<mozilla::dom::ContactAddress>::Get, | |
| GetProtoObject, | |
| nullptr | |
| } | |
| }; | |
| JSObject* | |
| Wrap(JSContext* aCx, JS::Handle<JSObject*> aScope, mozilla::dom::ContactAddress* aObject, nsWrapperCache* aCache) | |
| { | |
| MOZ_ASSERT(static_cast<mozilla::dom::ContactAddress*>(aObject) == | |
| reinterpret_cast<mozilla::dom::ContactAddress*>(aObject)); | |
| MOZ_ASSERT(ToSupports(aObject) == | |
| reinterpret_cast<nsISupports*>(aObject)); | |
| MOZ_ASSERT(reinterpret_cast<void*>(aObject) != aCache, | |
| "nsISupports must be on our primary inheritance chain"); | |
| JS::Rooted<JSObject*> parent(aCx, | |
| GetRealParentObject(aObject, | |
| WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); | |
| if (!parent) { | |
| return NULL; | |
| } | |
| // That might have ended up wrapping us already, due to the wonders | |
| // of XBL. Check for that, and bail out as needed. Scope so we don't | |
| // collide with the "obj" we declare in CreateBindingJSObject. | |
| { | |
| JSObject* obj = aCache->GetWrapper(); | |
| if (obj) { | |
| return obj; | |
| } | |
| } | |
| JSAutoCompartment ac(aCx, parent); | |
| JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent)); | |
| JS::Handle<JSObject*> proto = GetProtoObject(aCx, global); | |
| if (!proto) { | |
| return NULL; | |
| } | |
| JSObject *obj; | |
| obj = JS_NewObject(aCx, &Class.mBase, proto, parent); | |
| if (!obj) { | |
| return NULL; | |
| } | |
| js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject)); | |
| NS_ADDREF(aObject); | |
| aCache->SetWrapper(obj); | |
| return obj; | |
| } | |
| } // namespace ContactAddressBinding | |
| namespace ContactFieldBinding { | |
| static bool | |
| get_type(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetType(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "type"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_type(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetType(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "type"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo type_getterinfo = { | |
| (JSJitPropertyOp)get_type, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo type_setterinfo = { | |
| (JSJitPropertyOp)set_type, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_value(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetValue(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "value"); | |
| } | |
| if (!xpc::StringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_value(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eNull, eNull, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetValue(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "value"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo value_getterinfo = { | |
| (JSJitPropertyOp)get_value, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo value_setterinfo = { | |
| (JSJitPropertyOp)set_value, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_pref(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| Nullable<bool > result; | |
| result = self->GetPref(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "pref"); | |
| } | |
| if (result.IsNull()) { | |
| *vp = JSVAL_NULL; | |
| return true; | |
| } | |
| *vp = BOOLEAN_TO_JSVAL(result.Value()); | |
| return true; | |
| } | |
| static bool | |
| set_pref(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, JS::Value* argv) | |
| { | |
| Nullable<bool> arg0; | |
| if (argv[0].isNullOrUndefined()) { | |
| arg0.SetNull(); | |
| } else if (!ValueToPrimitive<bool, eDefault>(cx, argv[0], &arg0.SetValue())) { | |
| return false; | |
| } | |
| ErrorResult rv; | |
| self->SetPref(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "pref"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo pref_getterinfo = { | |
| (JSJitPropertyOp)get_pref, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo pref_setterinfo = { | |
| (JSJitPropertyOp)set_pref, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| toJSON(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactField* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JSObject* result; | |
| result = self->ToJSON(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "toJSON"); | |
| } | |
| *vp = JS::ObjectValue(*result); | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo toJSON_methodinfo = { | |
| (JSJitPropertyOp)toJSON, | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static JSBool | |
| genericMethod(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactField, mozilla::dom::ContactField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactField"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Method); | |
| JSJitMethodOp method = (JSJitMethodOp)info->op; | |
| return method(cx, obj, self, argc, vp); | |
| } | |
| static JSBool | |
| genericGetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactField, mozilla::dom::ContactField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactField"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Getter); | |
| JSJitPropertyOp getter = info->op; | |
| return getter(cx, obj, self, vp); | |
| } | |
| static JSBool | |
| genericSetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactField, mozilla::dom::ContactField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactField"); | |
| } | |
| } | |
| if (argc == 0) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactField attribute setter"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Setter); | |
| JSJitPropertyOp setter = info->op; | |
| if (!setter(cx, obj, self, argv)) { | |
| return false; | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static JSBool | |
| _addProperty(JSContext* cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactField>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactField* self = UnwrapDOMObject<mozilla::dom::ContactField>(obj); | |
| // We don't want to preserve if we don't have a wrapper. | |
| if (self->GetWrapperPreserveColor()) { | |
| nsContentUtils::PreserveWrapper(reinterpret_cast<nsISupports*>(self), self); | |
| } | |
| return true; | |
| } | |
| static void | |
| _finalize(JSFreeOp* fop, JSObject* obj) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactField>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactField* self = UnwrapDOMObject<mozilla::dom::ContactField>(obj); | |
| if (self) { | |
| JSBindingFinalized<mozilla::dom::ContactField>::Finalized(self); | |
| ClearWrapper(self, self); | |
| XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); | |
| if (rt) { | |
| rt->DeferredRelease(reinterpret_cast<nsISupports*>(self)); | |
| } else { | |
| NS_RELEASE(self); | |
| } | |
| } | |
| } | |
| static const JSFunctionSpec sMethods_specs[] = { | |
| JS_FNINFO("toJSON", genericMethod, &toJSON_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sMethods[] = { | |
| { true, nullptr, &sMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sMethods_ids[2] = { JSID_VOID }; | |
| static const JSFunctionSpec sChromeMethods_specs[] = { | |
| JS_FNINFO("QueryInterface", QueryInterface, nullptr, 1, 0), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sChromeMethods[] = { | |
| { true, nullptr, &sChromeMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sChromeMethods_ids[2] = { JSID_VOID }; | |
| static const JSPropertySpec sAttributes_specs[] = { | |
| { "type", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &type_getterinfo }, { (JSStrictPropertyOp)genericSetter, &type_setterinfo }}, | |
| { "value", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &value_getterinfo }, { (JSStrictPropertyOp)genericSetter, &value_setterinfo }}, | |
| { "pref", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &pref_getterinfo }, { (JSStrictPropertyOp)genericSetter, &pref_setterinfo }}, | |
| { 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSPropertySpec> sAttributes[] = { | |
| { true, nullptr, &sAttributes_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sAttributes_ids[4] = { JSID_VOID }; | |
| static const NativeProperties sNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sMethods, sMethods_ids, sMethods_specs, | |
| sAttributes, sAttributes_ids, sAttributes_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| static const NativeProperties sChromeOnlyNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sChromeMethods, sChromeMethods_ids, sChromeMethods_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| const NativePropertyHooks sNativePropertyHooks = { | |
| nullptr, | |
| nullptr, | |
| { &sNativeProperties, &sChromeOnlyNativeProperties }, | |
| prototypes::id::ContactField, | |
| constructors::id::ContactField, | |
| NULL | |
| }; | |
| static JSBool | |
| _constructor(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); | |
| if (argc < 3) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactField.constructor"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| GlobalObject global(cx, obj); | |
| if (global.Failed()) { | |
| return false; | |
| } | |
| AutoSequence<nsString > arg0; | |
| if (argv[0].isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &argv[0].toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| AutoSequence<nsString > &arr = arg0; | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| FakeDependentString arg1_holder; | |
| NonNull<nsAString> arg1; | |
| if (!ConvertJSValueToString(cx, argv[1], &argv[1], eStringify, eStringify, arg1_holder)) { | |
| return false; | |
| } | |
| arg1 = &arg1_holder; | |
| bool arg2; | |
| if (!ValueToPrimitive<bool, eDefault>(cx, argv[2], &arg2)) { | |
| return false; | |
| } | |
| Maybe<JSAutoCompartment> ac; | |
| if (xpc::WrapperFactory::IsXrayWrapper(obj)) { | |
| obj = js::CheckedUnwrap(obj); | |
| if (!obj) { | |
| return false; | |
| } | |
| ac.construct(cx, obj); | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::ContactField > result; | |
| result = mozilla::dom::ContactField::Constructor(global, cx, Constify(arg0), Constify(arg1), arg2, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactField", "constructor"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static DOMIfaceAndProtoJSClass InterfaceObjectClass = { | |
| { | |
| "Function", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| _constructor, /* call */ | |
| InterfaceHasInstance, /* hasInstance */ | |
| _constructor, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterface, | |
| &sNativePropertyHooks, | |
| "function ContactField() {\n [native code]\n}", | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth | |
| }; | |
| static DOMIfaceAndProtoJSClass PrototypeClass = { | |
| { | |
| "ContactFieldPrototype", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| nullptr, /* call */ | |
| nullptr, /* hasInstance */ | |
| nullptr, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterfacePrototype, | |
| &sNativePropertyHooks, | |
| "[object ContactFieldPrototype]", | |
| prototypes::id::ContactField, | |
| PrototypeTraits<prototypes::id::ContactField>::Depth | |
| }; | |
| void | |
| CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JSObject** protoAndIfaceArray) | |
| { | |
| JS::Rooted<JSObject*> parentProto(aCx, JS_GetObjectPrototype(aCx, aGlobal)); | |
| if (!parentProto) { | |
| return; | |
| } | |
| JS::Rooted<JSObject*> constructorProto(aCx, JS_GetFunctionPrototype(aCx, aGlobal)); | |
| if (!constructorProto) { | |
| return; | |
| } | |
| if (sChromeMethods_ids[0] == JSID_VOID && | |
| (!InitIds(aCx, sChromeMethods, sChromeMethods_ids) || | |
| !InitIds(aCx, sMethods, sMethods_ids) || | |
| !InitIds(aCx, sAttributes, sAttributes_ids))) { | |
| sChromeMethods_ids[0] = JSID_VOID; | |
| return; | |
| } | |
| dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, | |
| &PrototypeClass.mBase, &protoAndIfaceArray[prototypes::id::ContactField], | |
| constructorProto, &InterfaceObjectClass.mBase, nullptr, 3, nullptr, | |
| &protoAndIfaceArray[constructors::id::ContactField], | |
| &Class.mClass, | |
| &sNativeProperties, | |
| xpc::AccessCheck::isChrome(aGlobal) ? &sChromeOnlyNativeProperties : nullptr, | |
| "ContactField"); | |
| } | |
| JSObject* | |
| DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool* aEnabled) | |
| { | |
| *aEnabled = true; | |
| return GetConstructorObject(aCx, aGlobal); | |
| } | |
| DOMJSClass Class = { | |
| { "ContactField", | |
| JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(3), | |
| _addProperty, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| _finalize, /* finalize */ | |
| NULL, /* checkAccess */ | |
| nullptr, /* call */ | |
| NULL, /* hasInstance */ | |
| NULL, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| { | |
| { prototypes::id::ContactField, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, | |
| true, | |
| &sNativePropertyHooks, | |
| GetParentObject<mozilla::dom::ContactField>::Get, | |
| GetProtoObject, | |
| nullptr | |
| } | |
| }; | |
| JSObject* | |
| Wrap(JSContext* aCx, JS::Handle<JSObject*> aScope, mozilla::dom::ContactField* aObject, nsWrapperCache* aCache) | |
| { | |
| MOZ_ASSERT(static_cast<mozilla::dom::ContactField*>(aObject) == | |
| reinterpret_cast<mozilla::dom::ContactField*>(aObject)); | |
| MOZ_ASSERT(ToSupports(aObject) == | |
| reinterpret_cast<nsISupports*>(aObject)); | |
| MOZ_ASSERT(reinterpret_cast<void*>(aObject) != aCache, | |
| "nsISupports must be on our primary inheritance chain"); | |
| JS::Rooted<JSObject*> parent(aCx, | |
| GetRealParentObject(aObject, | |
| WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); | |
| if (!parent) { | |
| return NULL; | |
| } | |
| // That might have ended up wrapping us already, due to the wonders | |
| // of XBL. Check for that, and bail out as needed. Scope so we don't | |
| // collide with the "obj" we declare in CreateBindingJSObject. | |
| { | |
| JSObject* obj = aCache->GetWrapper(); | |
| if (obj) { | |
| return obj; | |
| } | |
| } | |
| JSAutoCompartment ac(aCx, parent); | |
| JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent)); | |
| JS::Handle<JSObject*> proto = GetProtoObject(aCx, global); | |
| if (!proto) { | |
| return NULL; | |
| } | |
| JSObject *obj; | |
| obj = JS_NewObject(aCx, &Class.mBase, proto, parent); | |
| if (!obj) { | |
| return NULL; | |
| } | |
| js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject)); | |
| NS_ADDREF(aObject); | |
| aCache->SetWrapper(obj); | |
| return obj; | |
| } | |
| } // namespace ContactFieldBinding | |
| namespace ContactManagerBinding { | |
| static bool | |
| find(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| ContactFindOptions arg0; | |
| if (!arg0.Init(cx, (0 < argc) ? JS::Handle<JS::Value>::fromMarkedLocation(&argv[0]) : JS::NullHandleValue)) { | |
| return false; | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->Find(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "find"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo find_methodinfo = { | |
| (JSJitPropertyOp)find, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| getAll(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| ContactFindSortOptions arg0; | |
| if (!arg0.Init(cx, (0 < argc) ? JS::Handle<JS::Value>::fromMarkedLocation(&argv[0]) : JS::NullHandleValue)) { | |
| return false; | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMCursor > result; | |
| result = self->GetAll(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "getAll"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo getAll_methodinfo = { | |
| (JSJitPropertyOp)getAll, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| clear(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->Clear(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "clear"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo clear_methodinfo = { | |
| (JSJitPropertyOp)clear, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| save(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| if (argc < 1) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactManager.save"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| NonNull<mozilla::dom::mozContact> arg0; | |
| if (argv[0].isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::mozContact, mozilla::dom::mozContact>(cx, &argv[0].toObject(), arg0); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "mozContact"); | |
| return false; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->Save(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "save"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo save_methodinfo = { | |
| (JSJitPropertyOp)save, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| remove(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| if (argc < 1) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactManager.remove"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| NonNull<mozilla::dom::mozContact> arg0; | |
| if (argv[0].isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::mozContact, mozilla::dom::mozContact>(cx, &argv[0].toObject(), arg0); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "mozContact"); | |
| return false; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->Remove(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "remove"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo remove_methodinfo = { | |
| (JSJitPropertyOp)remove, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| getSimContacts(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| if (argc < 1) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactManager.getSimContacts"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->GetSimContacts(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "getSimContacts"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo getSimContacts_methodinfo = { | |
| (JSJitPropertyOp)getSimContacts, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_oncontactchange(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| nsRefPtr<EventHandlerNonNull> result; | |
| result = self->GetOncontactchange(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "oncontactchange"); | |
| } | |
| if (result) { | |
| *vp = JS::ObjectValue(*GetCallbackFromCallbackObject(result)); | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } else { | |
| *vp = JS::NullValue(); | |
| return true; | |
| } | |
| } | |
| static bool | |
| set_oncontactchange(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, JS::Value* argv) | |
| { | |
| nsRefPtr<EventHandlerNonNull> arg0; | |
| if (argv[0].isObject() && JS_ObjectIsCallable(cx, &argv[0].toObject())) { | |
| arg0 = new EventHandlerNonNull(&argv[0].toObject()); | |
| } else { | |
| arg0 = nullptr; | |
| } | |
| ErrorResult rv; | |
| self->SetOncontactchange(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "oncontactchange"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo oncontactchange_getterinfo = { | |
| (JSJitPropertyOp)get_oncontactchange, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo oncontactchange_setterinfo = { | |
| (JSJitPropertyOp)set_oncontactchange, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| getRevision(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactManager* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::DOMRequest > result; | |
| result = self->GetRevision(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactManager", "getRevision"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo getRevision_methodinfo = { | |
| (JSJitPropertyOp)getRevision, | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static JSBool | |
| genericMethod(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactManager* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactManager, mozilla::dom::ContactManager>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactManager"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Method); | |
| JSJitMethodOp method = (JSJitMethodOp)info->op; | |
| return method(cx, obj, self, argc, vp); | |
| } | |
| static JSBool | |
| genericGetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactManager* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactManager, mozilla::dom::ContactManager>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactManager"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Getter); | |
| JSJitPropertyOp getter = info->op; | |
| return getter(cx, obj, self, vp); | |
| } | |
| static JSBool | |
| genericSetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactManager* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactManager, mozilla::dom::ContactManager>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactManager"); | |
| } | |
| } | |
| if (argc == 0) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactManager attribute setter"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Setter); | |
| JSJitPropertyOp setter = info->op; | |
| if (!setter(cx, obj, self, argv)) { | |
| return false; | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static already_AddRefed<ContactManager> | |
| ConstructNavigatorObjectHelper(JSContext* cx, GlobalObject& global, ErrorResult& aRv) | |
| { | |
| // Get the window to use as a parent and for initialization. | |
| nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get()); | |
| if (!window) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| JS::Rooted<JSObject*> jsImplObj(cx); | |
| // Make sure to have nothing on the JS context stack while creating and | |
| // initializing the object, so exceptions from that will get reported | |
| // properly, since those are never exceptions that a spec wants to be thrown. | |
| { // Scope for the nsCxPusher | |
| nsCxPusher pusher; | |
| pusher.PushNull(); | |
| // Get the XPCOM component containing the JS implementation. | |
| nsCOMPtr<nsISupports> implISupports = do_CreateInstance("@mozilla.org/contactManager;1"); | |
| if (!implISupports) { | |
| NS_WARNING("Failed to get JS implementation for contract \"@mozilla.org/contactManager;1\""); | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer. | |
| nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports); | |
| if (gpi) { | |
| JS::Rooted<JS::Value> initReturn(cx); | |
| nsresult rv = gpi->Init(window, initReturn.address()); | |
| if (NS_FAILED(rv)) { | |
| aRv.Throw(rv); | |
| return nullptr; | |
| } | |
| MOZ_ASSERT(initReturn.isUndefined(), | |
| "Expected nsIDOMGlobalPropertyInitializer to return undefined"); | |
| } | |
| // Extract the JS implementation from the XPCOM object. | |
| nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports); | |
| MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); | |
| if (!implWrapped) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| } | |
| // Build the C++ implementation. | |
| nsRefPtr<ContactManager> impl = new ContactManager(jsImplObj, window); | |
| return impl.forget(); | |
| } | |
| JSObject* | |
| ConstructNavigatorObject(JSContext* aCx, JS::Handle<JSObject*> aObj) | |
| { | |
| GlobalObject global(aCx, aObj); | |
| if (global.Failed()) { | |
| return nullptr; | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::ContactManager> result = ConstructNavigatorObjectHelper(aCx, global, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| ThrowMethodFailedWithDetails<true>(aCx, rv, "ContactManager", "navigatorConstructor"); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> v(aCx); | |
| if (!WrapNewBindingObject(aCx, aObj, result, v.address())) { | |
| MOZ_ASSERT(JS_IsExceptionPending(aCx)); | |
| return nullptr; | |
| } | |
| return &v.toObject(); | |
| } | |
| static JSBool | |
| _addProperty(JSContext* cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactManager>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactManager* self = UnwrapDOMObject<mozilla::dom::ContactManager>(obj); | |
| // We don't want to preserve if we don't have a wrapper. | |
| if (self->GetWrapperPreserveColor()) { | |
| nsContentUtils::PreserveWrapper(reinterpret_cast<nsISupports*>(self), self); | |
| } | |
| return true; | |
| } | |
| static void | |
| _finalize(JSFreeOp* fop, JSObject* obj) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactManager>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactManager* self = UnwrapDOMObject<mozilla::dom::ContactManager>(obj); | |
| if (self) { | |
| JSBindingFinalized<mozilla::dom::ContactManager>::Finalized(self); | |
| ClearWrapper(self, self); | |
| XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); | |
| if (rt) { | |
| rt->DeferredRelease(reinterpret_cast<nsISupports*>(self)); | |
| } else { | |
| NS_RELEASE(self); | |
| } | |
| } | |
| } | |
| static const JSFunctionSpec sMethods_specs[] = { | |
| JS_FNINFO("find", genericMethod, &find_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FNINFO("getAll", genericMethod, &getAll_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FNINFO("clear", genericMethod, &clear_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FNINFO("save", genericMethod, &save_methodinfo, 1, JSPROP_ENUMERATE), | |
| JS_FNINFO("remove", genericMethod, &remove_methodinfo, 1, JSPROP_ENUMERATE), | |
| JS_FNINFO("getSimContacts", genericMethod, &getSimContacts_methodinfo, 1, JSPROP_ENUMERATE), | |
| JS_FNINFO("getRevision", genericMethod, &getRevision_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sMethods[] = { | |
| { true, nullptr, &sMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sMethods_ids[8] = { JSID_VOID }; | |
| static const JSPropertySpec sAttributes_specs[] = { | |
| { "oncontactchange", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &oncontactchange_getterinfo }, { (JSStrictPropertyOp)genericSetter, &oncontactchange_setterinfo }}, | |
| { 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSPropertySpec> sAttributes[] = { | |
| { true, nullptr, &sAttributes_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sAttributes_ids[2] = { JSID_VOID }; | |
| static const NativeProperties sNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sMethods, sMethods_ids, sMethods_specs, | |
| sAttributes, sAttributes_ids, sAttributes_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| const NativePropertyHooks sNativePropertyHooks = { | |
| nullptr, | |
| nullptr, | |
| { &sNativeProperties, nullptr }, | |
| prototypes::id::ContactManager, | |
| constructors::id::_ID_Count, | |
| &EventTargetBinding::sNativePropertyHooks | |
| }; | |
| static DOMIfaceAndProtoJSClass PrototypeClass = { | |
| { | |
| "ContactManagerPrototype", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| nullptr, /* call */ | |
| nullptr, /* hasInstance */ | |
| nullptr, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterfacePrototype, | |
| &sNativePropertyHooks, | |
| "[object ContactManagerPrototype]", | |
| prototypes::id::ContactManager, | |
| PrototypeTraits<prototypes::id::ContactManager>::Depth | |
| }; | |
| void | |
| CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JSObject** protoAndIfaceArray) | |
| { | |
| JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObject(aCx, aGlobal)); | |
| if (!parentProto) { | |
| return; | |
| } | |
| JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObject(aCx, aGlobal)); | |
| if (!constructorProto) { | |
| return; | |
| } | |
| if (sMethods_ids[0] == JSID_VOID && | |
| (!InitIds(aCx, sMethods, sMethods_ids) || | |
| !InitIds(aCx, sAttributes, sAttributes_ids))) { | |
| sMethods_ids[0] = JSID_VOID; | |
| return; | |
| } | |
| dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, | |
| &PrototypeClass.mBase, &protoAndIfaceArray[prototypes::id::ContactManager], | |
| constructorProto, nullptr, nullptr, 0, nullptr, | |
| nullptr, | |
| &Class.mClass, | |
| &sNativeProperties, | |
| nullptr, | |
| NULL); | |
| } | |
| DOMJSClass Class = { | |
| { "ContactManager", | |
| JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(3), | |
| _addProperty, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| _finalize, /* finalize */ | |
| NULL, /* checkAccess */ | |
| nullptr, /* call */ | |
| NULL, /* hasInstance */ | |
| NULL, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| { | |
| { prototypes::id::EventTarget, prototypes::id::ContactManager, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, | |
| true, | |
| &sNativePropertyHooks, | |
| GetParentObject<mozilla::dom::ContactManager>::Get, | |
| GetProtoObject, | |
| nullptr | |
| } | |
| }; | |
| JSObject* | |
| Wrap(JSContext* aCx, JS::Handle<JSObject*> aScope, mozilla::dom::ContactManager* aObject, nsWrapperCache* aCache) | |
| { | |
| MOZ_ASSERT(static_cast<mozilla::dom::ContactManager*>(aObject) == | |
| reinterpret_cast<mozilla::dom::ContactManager*>(aObject)); | |
| MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == | |
| reinterpret_cast<mozilla::dom::EventTarget*>(aObject)); | |
| MOZ_ASSERT(ToSupports(aObject) == | |
| reinterpret_cast<nsISupports*>(aObject)); | |
| MOZ_ASSERT(reinterpret_cast<void*>(aObject) != aCache, | |
| "nsISupports must be on our primary inheritance chain"); | |
| JS::Rooted<JSObject*> parent(aCx, | |
| GetRealParentObject(aObject, | |
| WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); | |
| if (!parent) { | |
| return NULL; | |
| } | |
| // That might have ended up wrapping us already, due to the wonders | |
| // of XBL. Check for that, and bail out as needed. Scope so we don't | |
| // collide with the "obj" we declare in CreateBindingJSObject. | |
| { | |
| JSObject* obj = aCache->GetWrapper(); | |
| if (obj) { | |
| return obj; | |
| } | |
| } | |
| JSAutoCompartment ac(aCx, parent); | |
| JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent)); | |
| JS::Handle<JSObject*> proto = GetProtoObject(aCx, global); | |
| if (!proto) { | |
| return NULL; | |
| } | |
| JSObject *obj; | |
| obj = JS_NewObject(aCx, &Class.mBase, proto, parent); | |
| if (!obj) { | |
| return NULL; | |
| } | |
| js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject)); | |
| NS_ADDREF(aObject); | |
| aCache->SetWrapper(obj); | |
| return obj; | |
| } | |
| } // namespace ContactManagerBinding | |
| namespace ContactTelFieldBinding { | |
| static bool | |
| get_carrier(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactTelField* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetCarrier(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactTelField", "carrier"); | |
| } | |
| if (!xpc::StringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_carrier(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactTelField* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eNull, eNull, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetCarrier(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactTelField", "carrier"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo carrier_getterinfo = { | |
| (JSJitPropertyOp)get_carrier, | |
| prototypes::id::ContactTelField, | |
| PrototypeTraits<prototypes::id::ContactTelField>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo carrier_setterinfo = { | |
| (JSJitPropertyOp)set_carrier, | |
| prototypes::id::ContactTelField, | |
| PrototypeTraits<prototypes::id::ContactTelField>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| toJSON(JSContext* cx, JSHandleObject obj, mozilla::dom::ContactTelField* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JSObject* result; | |
| result = self->ToJSON(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactTelField", "toJSON"); | |
| } | |
| *vp = JS::ObjectValue(*result); | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo toJSON_methodinfo = { | |
| (JSJitPropertyOp)toJSON, | |
| prototypes::id::ContactTelField, | |
| PrototypeTraits<prototypes::id::ContactTelField>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static JSBool | |
| genericMethod(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactTelField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactTelField, mozilla::dom::ContactTelField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactTelField"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Method); | |
| JSJitMethodOp method = (JSJitMethodOp)info->op; | |
| return method(cx, obj, self, argc, vp); | |
| } | |
| static JSBool | |
| genericGetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactTelField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactTelField, mozilla::dom::ContactTelField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactTelField"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Getter); | |
| JSJitPropertyOp getter = info->op; | |
| return getter(cx, obj, self, vp); | |
| } | |
| static JSBool | |
| genericSetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::ContactTelField* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::ContactTelField, mozilla::dom::ContactTelField>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "ContactTelField"); | |
| } | |
| } | |
| if (argc == 0) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactTelField attribute setter"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Setter); | |
| JSJitPropertyOp setter = info->op; | |
| if (!setter(cx, obj, self, argv)) { | |
| return false; | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static JSBool | |
| _addProperty(JSContext* cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactTelField>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactTelField* self = UnwrapDOMObject<mozilla::dom::ContactTelField>(obj); | |
| // We don't want to preserve if we don't have a wrapper. | |
| if (self->GetWrapperPreserveColor()) { | |
| nsContentUtils::PreserveWrapper(reinterpret_cast<nsISupports*>(self), self); | |
| } | |
| return true; | |
| } | |
| static void | |
| _finalize(JSFreeOp* fop, JSObject* obj) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::ContactTelField>::value), "Must be an nsISupports class"); | |
| mozilla::dom::ContactTelField* self = UnwrapDOMObject<mozilla::dom::ContactTelField>(obj); | |
| if (self) { | |
| JSBindingFinalized<mozilla::dom::ContactTelField>::Finalized(self); | |
| ClearWrapper(self, self); | |
| XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); | |
| if (rt) { | |
| rt->DeferredRelease(reinterpret_cast<nsISupports*>(self)); | |
| } else { | |
| NS_RELEASE(self); | |
| } | |
| } | |
| } | |
| static const JSFunctionSpec sMethods_specs[] = { | |
| JS_FNINFO("toJSON", genericMethod, &toJSON_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sMethods[] = { | |
| { true, nullptr, &sMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sMethods_ids[2] = { JSID_VOID }; | |
| static const JSPropertySpec sAttributes_specs[] = { | |
| { "carrier", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &carrier_getterinfo }, { (JSStrictPropertyOp)genericSetter, &carrier_setterinfo }}, | |
| { 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSPropertySpec> sAttributes[] = { | |
| { true, nullptr, &sAttributes_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sAttributes_ids[2] = { JSID_VOID }; | |
| static const NativeProperties sNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sMethods, sMethods_ids, sMethods_specs, | |
| sAttributes, sAttributes_ids, sAttributes_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| const NativePropertyHooks sNativePropertyHooks = { | |
| nullptr, | |
| nullptr, | |
| { &sNativeProperties, nullptr }, | |
| prototypes::id::ContactTelField, | |
| constructors::id::ContactTelField, | |
| &ContactFieldBinding::sNativePropertyHooks | |
| }; | |
| static JSBool | |
| _constructor(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); | |
| if (argc < 4) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ContactTelField.constructor"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| GlobalObject global(cx, obj); | |
| if (global.Failed()) { | |
| return false; | |
| } | |
| AutoSequence<nsString > arg0; | |
| if (argv[0].isObject()) { | |
| JS::Rooted<JSObject*> seq(cx, &argv[0].toObject()); | |
| if (!IsArrayLike(cx, seq)) { | |
| ThrowErrorMessage(cx, MSG_NOT_SEQUENCE); | |
| return false; | |
| } | |
| uint32_t length; | |
| // JS_GetArrayLength actually works on all objects | |
| if (!JS_GetArrayLength(cx, seq, &length)) { | |
| return false; | |
| } | |
| AutoSequence<nsString > &arr = arg0; | |
| if (!arr.SetCapacity(length)) { | |
| JS_ReportOutOfMemory(cx); | |
| return false; | |
| } | |
| for (uint32_t i = 0; i < length; ++i) { | |
| JS::Rooted<JS::Value> temp(cx); | |
| if (!JS_GetElement(cx, seq, i, temp.address())) { | |
| return false; | |
| } | |
| nsString& slot = *arr.AppendElement(); | |
| { | |
| FakeDependentString str; | |
| if (!ConvertJSValueToString(cx, temp, temp.address(), eStringify, eStringify, str)) { | |
| return false; | |
| } | |
| slot = str; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| return false; | |
| } | |
| FakeDependentString arg1_holder; | |
| NonNull<nsAString> arg1; | |
| if (!ConvertJSValueToString(cx, argv[1], &argv[1], eStringify, eStringify, arg1_holder)) { | |
| return false; | |
| } | |
| arg1 = &arg1_holder; | |
| FakeDependentString arg2_holder; | |
| NonNull<nsAString> arg2; | |
| if (!ConvertJSValueToString(cx, argv[2], &argv[2], eStringify, eStringify, arg2_holder)) { | |
| return false; | |
| } | |
| arg2 = &arg2_holder; | |
| bool arg3; | |
| if (!ValueToPrimitive<bool, eDefault>(cx, argv[3], &arg3)) { | |
| return false; | |
| } | |
| Maybe<JSAutoCompartment> ac; | |
| if (xpc::WrapperFactory::IsXrayWrapper(obj)) { | |
| obj = js::CheckedUnwrap(obj); | |
| if (!obj) { | |
| return false; | |
| } | |
| ac.construct(cx, obj); | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::ContactTelField > result; | |
| result = mozilla::dom::ContactTelField::Constructor(global, cx, Constify(arg0), Constify(arg1), Constify(arg2), arg3, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "ContactTelField", "constructor"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static DOMIfaceAndProtoJSClass InterfaceObjectClass = { | |
| { | |
| "Function", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| _constructor, /* call */ | |
| InterfaceHasInstance, /* hasInstance */ | |
| _constructor, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterface, | |
| &sNativePropertyHooks, | |
| "function ContactTelField() {\n [native code]\n}", | |
| prototypes::id::ContactTelField, | |
| PrototypeTraits<prototypes::id::ContactTelField>::Depth | |
| }; | |
| static DOMIfaceAndProtoJSClass PrototypeClass = { | |
| { | |
| "ContactTelFieldPrototype", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| nullptr, /* call */ | |
| nullptr, /* hasInstance */ | |
| nullptr, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterfacePrototype, | |
| &sNativePropertyHooks, | |
| "[object ContactTelFieldPrototype]", | |
| prototypes::id::ContactTelField, | |
| PrototypeTraits<prototypes::id::ContactTelField>::Depth | |
| }; | |
| void | |
| CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JSObject** protoAndIfaceArray) | |
| { | |
| JS::Handle<JSObject*> parentProto(ContactFieldBinding::GetProtoObject(aCx, aGlobal)); | |
| if (!parentProto) { | |
| return; | |
| } | |
| JS::Handle<JSObject*> constructorProto(ContactFieldBinding::GetConstructorObject(aCx, aGlobal)); | |
| if (!constructorProto) { | |
| return; | |
| } | |
| if (sMethods_ids[0] == JSID_VOID && | |
| (!InitIds(aCx, sMethods, sMethods_ids) || | |
| !InitIds(aCx, sAttributes, sAttributes_ids))) { | |
| sMethods_ids[0] = JSID_VOID; | |
| return; | |
| } | |
| dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, | |
| &PrototypeClass.mBase, &protoAndIfaceArray[prototypes::id::ContactTelField], | |
| constructorProto, &InterfaceObjectClass.mBase, nullptr, 4, nullptr, | |
| &protoAndIfaceArray[constructors::id::ContactTelField], | |
| &Class.mClass, | |
| &sNativeProperties, | |
| nullptr, | |
| "ContactTelField"); | |
| } | |
| JSObject* | |
| DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool* aEnabled) | |
| { | |
| *aEnabled = true; | |
| return GetConstructorObject(aCx, aGlobal); | |
| } | |
| DOMJSClass Class = { | |
| { "ContactTelField", | |
| JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(3), | |
| _addProperty, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| _finalize, /* finalize */ | |
| NULL, /* checkAccess */ | |
| nullptr, /* call */ | |
| NULL, /* hasInstance */ | |
| NULL, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| { | |
| { prototypes::id::ContactField, prototypes::id::ContactTelField, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, | |
| true, | |
| &sNativePropertyHooks, | |
| GetParentObject<mozilla::dom::ContactTelField>::Get, | |
| GetProtoObject, | |
| nullptr | |
| } | |
| }; | |
| JSObject* | |
| Wrap(JSContext* aCx, JS::Handle<JSObject*> aScope, mozilla::dom::ContactTelField* aObject, nsWrapperCache* aCache) | |
| { | |
| MOZ_ASSERT(static_cast<mozilla::dom::ContactTelField*>(aObject) == | |
| reinterpret_cast<mozilla::dom::ContactTelField*>(aObject)); | |
| MOZ_ASSERT(static_cast<mozilla::dom::ContactField*>(aObject) == | |
| reinterpret_cast<mozilla::dom::ContactField*>(aObject)); | |
| MOZ_ASSERT(ToSupports(aObject) == | |
| reinterpret_cast<nsISupports*>(aObject)); | |
| MOZ_ASSERT(reinterpret_cast<void*>(aObject) != aCache, | |
| "nsISupports must be on our primary inheritance chain"); | |
| JS::Rooted<JSObject*> parent(aCx, | |
| GetRealParentObject(aObject, | |
| WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); | |
| if (!parent) { | |
| return NULL; | |
| } | |
| // That might have ended up wrapping us already, due to the wonders | |
| // of XBL. Check for that, and bail out as needed. Scope so we don't | |
| // collide with the "obj" we declare in CreateBindingJSObject. | |
| { | |
| JSObject* obj = aCache->GetWrapper(); | |
| if (obj) { | |
| return obj; | |
| } | |
| } | |
| JSAutoCompartment ac(aCx, parent); | |
| JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent)); | |
| JS::Handle<JSObject*> proto = GetProtoObject(aCx, global); | |
| if (!proto) { | |
| return NULL; | |
| } | |
| JSObject *obj; | |
| obj = JS_NewObject(aCx, &Class.mBase, proto, parent); | |
| if (!obj) { | |
| return NULL; | |
| } | |
| js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject)); | |
| NS_ADDREF(aObject); | |
| aCache->SetWrapper(obj); | |
| return obj; | |
| } | |
| } // namespace ContactTelFieldBinding | |
| namespace mozContactBinding { | |
| static bool | |
| get_id(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetId(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "id"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_id(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetId(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "id"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo id_getterinfo = { | |
| (JSJitPropertyOp)get_id, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo id_setterinfo = { | |
| (JSJitPropertyOp)set_id, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_published(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetPublished(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "published"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo published_getterinfo = { | |
| (JSJitPropertyOp)get_published, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_updated(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetUpdated(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "updated"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo updated_getterinfo = { | |
| (JSJitPropertyOp)get_updated, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_bday(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetBday(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "bday"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_bday(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetBday(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "bday"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo bday_getterinfo = { | |
| (JSJitPropertyOp)get_bday, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo bday_setterinfo = { | |
| (JSJitPropertyOp)set_bday, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_anniversary(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetAnniversary(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "anniversary"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_anniversary(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetAnniversary(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "anniversary"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo anniversary_getterinfo = { | |
| (JSJitPropertyOp)get_anniversary, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo anniversary_setterinfo = { | |
| (JSJitPropertyOp)set_anniversary, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_sex(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetSex(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "sex"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_sex(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetSex(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "sex"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo sex_getterinfo = { | |
| (JSJitPropertyOp)get_sex, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo sex_setterinfo = { | |
| (JSJitPropertyOp)set_sex, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_genderIdentity(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| DOMString result; | |
| self->GetGenderIdentity(result, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "genderIdentity"); | |
| } | |
| if (!xpc::NonVoidStringToJsval(cx, result, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_genderIdentity(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| ErrorResult rv; | |
| self->SetGenderIdentity(Constify(arg0), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "genderIdentity"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo genderIdentity_getterinfo = { | |
| (JSJitPropertyOp)get_genderIdentity, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_STRING /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo genderIdentity_setterinfo = { | |
| (JSJitPropertyOp)set_genderIdentity, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_photo(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetPhoto(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "photo"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_photo(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetPhoto(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "photo"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo photo_getterinfo = { | |
| (JSJitPropertyOp)get_photo, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo photo_setterinfo = { | |
| (JSJitPropertyOp)set_photo, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_adr(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetAdr(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "adr"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_adr(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetAdr(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "adr"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo adr_getterinfo = { | |
| (JSJitPropertyOp)get_adr, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo adr_setterinfo = { | |
| (JSJitPropertyOp)set_adr, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_email(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetEmail(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "email"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_email(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetEmail(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "email"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo email_getterinfo = { | |
| (JSJitPropertyOp)get_email, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo email_setterinfo = { | |
| (JSJitPropertyOp)set_email, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_url(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetUrl(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "url"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_url(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetUrl(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "url"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo url_getterinfo = { | |
| (JSJitPropertyOp)get_url, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo url_setterinfo = { | |
| (JSJitPropertyOp)set_url, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_impp(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetImpp(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "impp"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_impp(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetImpp(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "impp"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo impp_getterinfo = { | |
| (JSJitPropertyOp)get_impp, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo impp_setterinfo = { | |
| (JSJitPropertyOp)set_impp, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_tel(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetTel(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "tel"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_tel(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetTel(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "tel"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo tel_getterinfo = { | |
| (JSJitPropertyOp)get_tel, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo tel_setterinfo = { | |
| (JSJitPropertyOp)set_tel, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_name(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetName(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "name"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_name(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetName(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "name"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo name_getterinfo = { | |
| (JSJitPropertyOp)get_name, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo name_setterinfo = { | |
| (JSJitPropertyOp)set_name, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_honorificPrefix(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetHonorificPrefix(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "honorificPrefix"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_honorificPrefix(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetHonorificPrefix(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "honorificPrefix"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo honorificPrefix_getterinfo = { | |
| (JSJitPropertyOp)get_honorificPrefix, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo honorificPrefix_setterinfo = { | |
| (JSJitPropertyOp)set_honorificPrefix, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_givenName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetGivenName(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "givenName"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_givenName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetGivenName(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "givenName"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo givenName_getterinfo = { | |
| (JSJitPropertyOp)get_givenName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo givenName_setterinfo = { | |
| (JSJitPropertyOp)set_givenName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_additionalName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetAdditionalName(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "additionalName"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_additionalName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetAdditionalName(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "additionalName"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo additionalName_getterinfo = { | |
| (JSJitPropertyOp)get_additionalName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo additionalName_setterinfo = { | |
| (JSJitPropertyOp)set_additionalName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_familyName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetFamilyName(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "familyName"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_familyName(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetFamilyName(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "familyName"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo familyName_getterinfo = { | |
| (JSJitPropertyOp)get_familyName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo familyName_setterinfo = { | |
| (JSJitPropertyOp)set_familyName, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_honorificSuffix(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetHonorificSuffix(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "honorificSuffix"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_honorificSuffix(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetHonorificSuffix(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "honorificSuffix"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo honorificSuffix_getterinfo = { | |
| (JSJitPropertyOp)get_honorificSuffix, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo honorificSuffix_setterinfo = { | |
| (JSJitPropertyOp)set_honorificSuffix, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_nickname(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetNickname(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "nickname"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_nickname(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetNickname(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "nickname"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo nickname_getterinfo = { | |
| (JSJitPropertyOp)get_nickname, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo nickname_setterinfo = { | |
| (JSJitPropertyOp)set_nickname, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_category(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetCategory(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "category"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_category(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetCategory(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "category"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo category_getterinfo = { | |
| (JSJitPropertyOp)get_category, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo category_setterinfo = { | |
| (JSJitPropertyOp)set_category, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_org(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetOrg(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "org"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_org(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetOrg(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "org"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo org_getterinfo = { | |
| (JSJitPropertyOp)get_org, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo org_setterinfo = { | |
| (JSJitPropertyOp)set_org, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_jobTitle(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetJobTitle(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "jobTitle"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_jobTitle(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetJobTitle(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "jobTitle"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo jobTitle_getterinfo = { | |
| (JSJitPropertyOp)get_jobTitle, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo jobTitle_setterinfo = { | |
| (JSJitPropertyOp)set_jobTitle, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| get_note(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JS::Value result; | |
| result = self->GetNote(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "note"); | |
| } | |
| *vp = result; | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static bool | |
| set_note(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, JS::Value* argv) | |
| { | |
| LazyRootedValue arg0; | |
| arg0.construct(cx, argv[0]); | |
| ErrorResult rv; | |
| self->SetNote(arg0, rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "note"); | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo note_getterinfo = { | |
| (JSJitPropertyOp)get_note, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Getter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNKNOWN /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static const JSJitInfo note_setterinfo = { | |
| (JSJitPropertyOp)set_note, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Setter, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| setMetadata(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, unsigned argc, JS::Value* vp) | |
| { | |
| if (argc < 1) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "mozContact.setMetadata"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| FakeDependentString arg0_holder; | |
| NonNull<nsAString> arg0; | |
| if (!ConvertJSValueToString(cx, argv[0], &argv[0], eStringify, eStringify, arg0_holder)) { | |
| return false; | |
| } | |
| arg0 = &arg0_holder; | |
| Optional<LazyRootedValue > arg1; | |
| if (1 < argc) { | |
| arg1.Construct(); | |
| arg1.Value().construct(cx, argv[1]); | |
| } | |
| Optional<LazyRootedValue > arg2; | |
| if (2 < argc) { | |
| arg2.Construct(); | |
| arg2.Value().construct(cx, argv[2]); | |
| } | |
| ErrorResult rv; | |
| self->SetMetadata(Constify(arg0), Constify(arg1), Constify(arg2), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "setMetadata"); | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static const JSJitInfo setMetadata_methodinfo = { | |
| (JSJitPropertyOp)setMetadata, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_UNDEFINED /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static bool | |
| toJSON(JSContext* cx, JSHandleObject obj, mozilla::dom::mozContact* self, unsigned argc, JS::Value* vp) | |
| { | |
| ErrorResult rv; | |
| JSObject* result; | |
| result = self->ToJSON(rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "toJSON"); | |
| } | |
| *vp = JS::ObjectValue(*result); | |
| if (!MaybeWrapValue(cx, vp)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| static const JSJitInfo toJSON_methodinfo = { | |
| (JSJitPropertyOp)toJSON, | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth, | |
| JSJitInfo::Method, | |
| false, /* isInfallible. False in setters. */ | |
| false, /* isConstant. Only relevant for getters. */ | |
| false, /* isPure. Only relevant for getters. */ | |
| JSVAL_TYPE_OBJECT /* returnType. Only relevant for getters/methods. */ | |
| }; | |
| static JSBool | |
| genericMethod(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::mozContact* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::mozContact, mozilla::dom::mozContact>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "mozContact"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Method); | |
| JSJitMethodOp method = (JSJitMethodOp)info->op; | |
| return method(cx, obj, self, argc, vp); | |
| } | |
| static JSBool | |
| genericGetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::mozContact* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::mozContact, mozilla::dom::mozContact>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "mozContact"); | |
| } | |
| } | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Getter); | |
| JSJitPropertyOp getter = info->op; | |
| return getter(cx, obj, self, vp); | |
| } | |
| static JSBool | |
| genericSetter(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |
| JS::RootedObject obj(cx, &args.computeThis(cx).toObject()); | |
| if (!obj) { | |
| return false; | |
| } | |
| mozilla::dom::mozContact* self; | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::mozContact, mozilla::dom::mozContact>(cx, obj, self); | |
| if (NS_FAILED(rv)) { | |
| return ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "mozContact"); | |
| } | |
| } | |
| if (argc == 0) { | |
| return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "mozContact attribute setter"); | |
| } | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| const JSJitInfo *info = FUNCTION_VALUE_TO_JITINFO(JS_CALLEE(cx, vp)); | |
| MOZ_ASSERT(info->type == JSJitInfo::Setter); | |
| JSJitPropertyOp setter = info->op; | |
| if (!setter(cx, obj, self, argv)) { | |
| return false; | |
| } | |
| *vp = JSVAL_VOID; | |
| return true; | |
| } | |
| static JSBool | |
| _addProperty(JSContext* cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::mozContact>::value), "Must be an nsISupports class"); | |
| mozilla::dom::mozContact* self = UnwrapDOMObject<mozilla::dom::mozContact>(obj); | |
| // We don't want to preserve if we don't have a wrapper. | |
| if (self->GetWrapperPreserveColor()) { | |
| nsContentUtils::PreserveWrapper(reinterpret_cast<nsISupports*>(self), self); | |
| } | |
| return true; | |
| } | |
| static void | |
| _finalize(JSFreeOp* fop, JSObject* obj) | |
| { | |
| MOZ_STATIC_ASSERT((IsBaseOf<nsISupports, mozilla::dom::mozContact>::value), "Must be an nsISupports class"); | |
| mozilla::dom::mozContact* self = UnwrapDOMObject<mozilla::dom::mozContact>(obj); | |
| if (self) { | |
| JSBindingFinalized<mozilla::dom::mozContact>::Finalized(self); | |
| ClearWrapper(self, self); | |
| XPCJSRuntime *rt = nsXPConnect::GetRuntimeInstance(); | |
| if (rt) { | |
| rt->DeferredRelease(reinterpret_cast<nsISupports*>(self)); | |
| } else { | |
| NS_RELEASE(self); | |
| } | |
| } | |
| } | |
| static const JSFunctionSpec sMethods_specs[] = { | |
| JS_FNINFO("setMetadata", genericMethod, &setMetadata_methodinfo, 1, JSPROP_ENUMERATE), | |
| JS_FNINFO("toJSON", genericMethod, &toJSON_methodinfo, 0, JSPROP_ENUMERATE), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sMethods[] = { | |
| { true, nullptr, &sMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sMethods_ids[3] = { JSID_VOID }; | |
| static const JSFunctionSpec sChromeMethods_specs[] = { | |
| JS_FNINFO("QueryInterface", QueryInterface, nullptr, 1, 0), | |
| JS_FS_END | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSFunctionSpec> sChromeMethods[] = { | |
| { true, nullptr, &sChromeMethods_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sChromeMethods_ids[2] = { JSID_VOID }; | |
| static const JSPropertySpec sAttributes_specs[] = { | |
| { "id", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &id_getterinfo }, { (JSStrictPropertyOp)genericSetter, &id_setterinfo }}, | |
| { "published", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &published_getterinfo }, JSOP_NULLWRAPPER}, | |
| { "updated", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &updated_getterinfo }, JSOP_NULLWRAPPER}, | |
| { "bday", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &bday_getterinfo }, { (JSStrictPropertyOp)genericSetter, &bday_setterinfo }}, | |
| { "anniversary", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &anniversary_getterinfo }, { (JSStrictPropertyOp)genericSetter, &anniversary_setterinfo }}, | |
| { "sex", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &sex_getterinfo }, { (JSStrictPropertyOp)genericSetter, &sex_setterinfo }}, | |
| { "genderIdentity", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &genderIdentity_getterinfo }, { (JSStrictPropertyOp)genericSetter, &genderIdentity_setterinfo }}, | |
| { "photo", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &photo_getterinfo }, { (JSStrictPropertyOp)genericSetter, &photo_setterinfo }}, | |
| { "adr", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &adr_getterinfo }, { (JSStrictPropertyOp)genericSetter, &adr_setterinfo }}, | |
| { "email", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &email_getterinfo }, { (JSStrictPropertyOp)genericSetter, &email_setterinfo }}, | |
| { "url", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &url_getterinfo }, { (JSStrictPropertyOp)genericSetter, &url_setterinfo }}, | |
| { "impp", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &impp_getterinfo }, { (JSStrictPropertyOp)genericSetter, &impp_setterinfo }}, | |
| { "tel", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &tel_getterinfo }, { (JSStrictPropertyOp)genericSetter, &tel_setterinfo }}, | |
| { "name", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &name_getterinfo }, { (JSStrictPropertyOp)genericSetter, &name_setterinfo }}, | |
| { "honorificPrefix", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &honorificPrefix_getterinfo }, { (JSStrictPropertyOp)genericSetter, &honorificPrefix_setterinfo }}, | |
| { "givenName", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &givenName_getterinfo }, { (JSStrictPropertyOp)genericSetter, &givenName_setterinfo }}, | |
| { "additionalName", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &additionalName_getterinfo }, { (JSStrictPropertyOp)genericSetter, &additionalName_setterinfo }}, | |
| { "familyName", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &familyName_getterinfo }, { (JSStrictPropertyOp)genericSetter, &familyName_setterinfo }}, | |
| { "honorificSuffix", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &honorificSuffix_getterinfo }, { (JSStrictPropertyOp)genericSetter, &honorificSuffix_setterinfo }}, | |
| { "nickname", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &nickname_getterinfo }, { (JSStrictPropertyOp)genericSetter, &nickname_setterinfo }}, | |
| { "category", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &category_getterinfo }, { (JSStrictPropertyOp)genericSetter, &category_setterinfo }}, | |
| { "org", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &org_getterinfo }, { (JSStrictPropertyOp)genericSetter, &org_setterinfo }}, | |
| { "jobTitle", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, &jobTitle_getterinfo }, { (JSStrictPropertyOp)genericSetter, &jobTitle_setterinfo }}, | |
| { "note", 0, JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_NATIVE_ACCESSORS, { (JSPropertyOp)genericGetter, ¬e_getterinfo }, { (JSStrictPropertyOp)genericSetter, ¬e_setterinfo }}, | |
| { 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER } | |
| }; | |
| // Can't be const because the pref-enabled boolean needs to be writable | |
| static Prefable<const JSPropertySpec> sAttributes[] = { | |
| { true, nullptr, &sAttributes_specs[0] }, | |
| { false, NULL } | |
| }; | |
| static jsid sAttributes_ids[25] = { JSID_VOID }; | |
| static const NativeProperties sNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sMethods, sMethods_ids, sMethods_specs, | |
| sAttributes, sAttributes_ids, sAttributes_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| static const NativeProperties sChromeOnlyNativeProperties = { | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| sChromeMethods, sChromeMethods_ids, sChromeMethods_specs, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr, | |
| nullptr, nullptr, nullptr | |
| }; | |
| const NativePropertyHooks sNativePropertyHooks = { | |
| nullptr, | |
| nullptr, | |
| { &sNativeProperties, &sChromeOnlyNativeProperties }, | |
| prototypes::id::mozContact, | |
| constructors::id::mozContact, | |
| NULL | |
| }; | |
| static JSBool | |
| _constructor(JSContext* cx, unsigned argc, JS::Value* vp) | |
| { | |
| JS::Rooted<JSObject*> obj(cx, JSVAL_TO_OBJECT(JS_CALLEE(cx, vp))); | |
| JS::Value* argv = JS_ARGV(cx, vp); | |
| GlobalObject global(cx, obj); | |
| if (global.Failed()) { | |
| return false; | |
| } | |
| ContactProperties arg0; | |
| if (!arg0.Init(cx, (0 < argc) ? JS::Handle<JS::Value>::fromMarkedLocation(&argv[0]) : JS::NullHandleValue)) { | |
| return false; | |
| } | |
| ContactMetadata arg1; | |
| if (!arg1.Init(cx, (1 < argc) ? JS::Handle<JS::Value>::fromMarkedLocation(&argv[1]) : JS::NullHandleValue)) { | |
| return false; | |
| } | |
| Maybe<JSAutoCompartment> ac; | |
| if (xpc::WrapperFactory::IsXrayWrapper(obj)) { | |
| obj = js::CheckedUnwrap(obj); | |
| if (!obj) { | |
| return false; | |
| } | |
| ac.construct(cx, obj); | |
| if (arg0.mAnniversary.WasPassed()) { | |
| if (!JS_WrapValue(cx, &arg0.mAnniversary.Value())) { | |
| return false; | |
| } | |
| } | |
| if (arg0.mBday.WasPassed()) { | |
| if (!JS_WrapValue(cx, &arg0.mBday.Value())) { | |
| return false; | |
| } | |
| } | |
| if (arg1.mPublished.WasPassed()) { | |
| if (!JS_WrapValue(cx, &arg1.mPublished.Value())) { | |
| return false; | |
| } | |
| } | |
| if (arg1.mUpdated.WasPassed()) { | |
| if (!JS_WrapValue(cx, &arg1.mUpdated.Value())) { | |
| return false; | |
| } | |
| } | |
| } | |
| ErrorResult rv; | |
| nsRefPtr<mozilla::dom::mozContact > result; | |
| result = mozilla::dom::mozContact::Constructor(global, cx, Constify(arg0), Constify(arg1), rv); | |
| rv.WouldReportJSException(); | |
| if (rv.Failed()) { | |
| return ThrowMethodFailedWithDetails<true>(cx, rv, "mozContact", "constructor"); | |
| } | |
| if (!WrapNewBindingObject(cx, obj, result, vp)) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| return false; | |
| } | |
| return true; | |
| } | |
| static DOMIfaceAndProtoJSClass InterfaceObjectClass = { | |
| { | |
| "Function", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| _constructor, /* call */ | |
| InterfaceHasInstance, /* hasInstance */ | |
| _constructor, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterface, | |
| &sNativePropertyHooks, | |
| "function mozContact() {\n [native code]\n}", | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth | |
| }; | |
| static DOMIfaceAndProtoJSClass PrototypeClass = { | |
| { | |
| "mozContactPrototype", | |
| JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), | |
| JS_PropertyStub, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| nullptr, /* finalize */ | |
| nullptr, /* checkAccess */ | |
| nullptr, /* call */ | |
| nullptr, /* hasInstance */ | |
| nullptr, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| eInterfacePrototype, | |
| &sNativePropertyHooks, | |
| "[object mozContactPrototype]", | |
| prototypes::id::mozContact, | |
| PrototypeTraits<prototypes::id::mozContact>::Depth | |
| }; | |
| void | |
| CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JSObject** protoAndIfaceArray) | |
| { | |
| JS::Rooted<JSObject*> parentProto(aCx, JS_GetObjectPrototype(aCx, aGlobal)); | |
| if (!parentProto) { | |
| return; | |
| } | |
| JS::Rooted<JSObject*> constructorProto(aCx, JS_GetFunctionPrototype(aCx, aGlobal)); | |
| if (!constructorProto) { | |
| return; | |
| } | |
| if (sChromeMethods_ids[0] == JSID_VOID && | |
| (!InitIds(aCx, sChromeMethods, sChromeMethods_ids) || | |
| !InitIds(aCx, sMethods, sMethods_ids) || | |
| !InitIds(aCx, sAttributes, sAttributes_ids))) { | |
| sChromeMethods_ids[0] = JSID_VOID; | |
| return; | |
| } | |
| dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, | |
| &PrototypeClass.mBase, &protoAndIfaceArray[prototypes::id::mozContact], | |
| constructorProto, &InterfaceObjectClass.mBase, nullptr, 0, nullptr, | |
| &protoAndIfaceArray[constructors::id::mozContact], | |
| &Class.mClass, | |
| &sNativeProperties, | |
| xpc::AccessCheck::isChrome(aGlobal) ? &sChromeOnlyNativeProperties : nullptr, | |
| "mozContact"); | |
| } | |
| JSObject* | |
| DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool* aEnabled) | |
| { | |
| *aEnabled = true; | |
| return GetConstructorObject(aCx, aGlobal); | |
| } | |
| DOMJSClass Class = { | |
| { "mozContact", | |
| JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(3), | |
| _addProperty, /* addProperty */ | |
| JS_DeletePropertyStub, /* delProperty */ | |
| JS_PropertyStub, /* getProperty */ | |
| JS_StrictPropertyStub, /* setProperty */ | |
| JS_EnumerateStub, | |
| JS_ResolveStub, | |
| JS_ConvertStub, | |
| _finalize, /* finalize */ | |
| NULL, /* checkAccess */ | |
| nullptr, /* call */ | |
| NULL, /* hasInstance */ | |
| NULL, /* construct */ | |
| nullptr, /* trace */ | |
| JSCLASS_NO_INTERNAL_MEMBERS | |
| }, | |
| { | |
| { prototypes::id::mozContact, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, | |
| true, | |
| &sNativePropertyHooks, | |
| GetParentObject<mozilla::dom::mozContact>::Get, | |
| GetProtoObject, | |
| nullptr | |
| } | |
| }; | |
| JSObject* | |
| Wrap(JSContext* aCx, JS::Handle<JSObject*> aScope, mozilla::dom::mozContact* aObject, nsWrapperCache* aCache) | |
| { | |
| MOZ_ASSERT(static_cast<mozilla::dom::mozContact*>(aObject) == | |
| reinterpret_cast<mozilla::dom::mozContact*>(aObject)); | |
| MOZ_ASSERT(ToSupports(aObject) == | |
| reinterpret_cast<nsISupports*>(aObject)); | |
| MOZ_ASSERT(reinterpret_cast<void*>(aObject) != aCache, | |
| "nsISupports must be on our primary inheritance chain"); | |
| JS::Rooted<JSObject*> parent(aCx, | |
| GetRealParentObject(aObject, | |
| WrapNativeParent(aCx, aScope, aObject->GetParentObject()))); | |
| if (!parent) { | |
| return NULL; | |
| } | |
| // That might have ended up wrapping us already, due to the wonders | |
| // of XBL. Check for that, and bail out as needed. Scope so we don't | |
| // collide with the "obj" we declare in CreateBindingJSObject. | |
| { | |
| JSObject* obj = aCache->GetWrapper(); | |
| if (obj) { | |
| return obj; | |
| } | |
| } | |
| JSAutoCompartment ac(aCx, parent); | |
| JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent)); | |
| JS::Handle<JSObject*> proto = GetProtoObject(aCx, global); | |
| if (!proto) { | |
| return NULL; | |
| } | |
| JSObject *obj; | |
| obj = JS_NewObject(aCx, &Class.mBase, proto, parent); | |
| if (!obj) { | |
| return NULL; | |
| } | |
| js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject)); | |
| NS_ADDREF(aObject); | |
| aCache->SetWrapper(obj); | |
| return obj; | |
| } | |
| } // namespace mozContactBinding | |
| JSObject* | |
| ContactAddressJSImpl::ToJSON(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "toJSON", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NonNullLazyRootedObject rvalDecl; | |
| if (rval.isObject()) { | |
| rvalDecl.construct(cx, &rval.toObject()); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| return rvalDecl.ref(); | |
| } | |
| void | |
| ContactAddressJSImpl::__Init(const Sequence<nsString >& type, const nsAString& streetAddress, const nsAString& locality, const nsAString& region, const nsAString& postalCode, const nsAString& countryName, bool pref, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(7)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| unsigned argc = 7; | |
| do { | |
| argv[6] = BOOLEAN_TO_JSVAL(pref); | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(countryName); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[5])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(postalCode); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[4])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(region); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[3])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(locality); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[2])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(streetAddress); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[1])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| uint32_t length = type.Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, type[sequenceIdx0], tmp.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| } | |
| argv[0] = JS::ObjectValue(*returnArray); | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "__init", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| JS::Value | |
| ContactAddressJSImpl::GetType(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "type", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::GetStreetAddress(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "streetAddress", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::GetLocality(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "locality", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::GetRegion(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "region", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::GetPostalCode(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "postalCode", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::GetCountryName(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "countryName", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| bool | |
| ContactAddressJSImpl::GetPref(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return bool(0); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "pref", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return bool(0); | |
| } | |
| bool rvalDecl; | |
| if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return bool(0); | |
| } | |
| return rvalDecl; | |
| } | |
| void | |
| ContactAddressJSImpl::SetType(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "type", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetStreetAddress(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "streetAddress", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetLocality(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "locality", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetRegion(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "region", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetPostalCode(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "postalCode", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetCountryName(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "countryName", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactAddressJSImpl::SetPref(bool arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = BOOLEAN_TO_JSVAL(arg); | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "pref", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(ContactAddress, mImpl, mParent) | |
| NS_IMPL_CYCLE_COLLECTING_ADDREF(ContactAddress) | |
| NS_IMPL_CYCLE_COLLECTING_RELEASE(ContactAddress) | |
| NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContactAddress) | |
| NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY | |
| NS_INTERFACE_MAP_ENTRY(nsISupports) | |
| NS_INTERFACE_MAP_END | |
| ContactAddress::ContactAddress(JS::Handle<JSObject*> aJSImplObject, nsPIDOMWindow* aParent) | |
| : mImpl(new ContactAddressJSImpl(aJSImplObject)), | |
| mParent(aParent) | |
| { | |
| SetIsDOMBinding(); | |
| } | |
| nsISupports* | |
| ContactAddress::GetParentObject() const | |
| { | |
| return mParent; | |
| } | |
| JSObject* | |
| ContactAddress::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) | |
| { | |
| JS::Rooted<JSObject*> obj(aCx, ContactAddressBinding::Wrap(aCx, aScope, this)); | |
| if (!obj) { | |
| return nullptr; | |
| } | |
| // Now define it on our chrome object | |
| JSAutoCompartment ac(aCx, mImpl->Callback()); | |
| if (!JS_WrapObject(aCx, obj.address())) { | |
| return nullptr; | |
| } | |
| if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) { | |
| return nullptr; | |
| } | |
| return obj; | |
| } | |
| already_AddRefed<ContactAddress> | |
| ContactAddress::Constructor(const GlobalObject& global, JSContext* cx, const Sequence<nsString >& type, const nsAString& streetAddress, const nsAString& locality, const nsAString& region, const nsAString& postalCode, const nsAString& countryName, bool pref, ErrorResult& aRv) | |
| { | |
| // Get the window to use as a parent and for initialization. | |
| nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get()); | |
| if (!window) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| JS::Rooted<JSObject*> jsImplObj(cx); | |
| // Make sure to have nothing on the JS context stack while creating and | |
| // initializing the object, so exceptions from that will get reported | |
| // properly, since those are never exceptions that a spec wants to be thrown. | |
| { // Scope for the nsCxPusher | |
| nsCxPusher pusher; | |
| pusher.PushNull(); | |
| // Get the XPCOM component containing the JS implementation. | |
| nsCOMPtr<nsISupports> implISupports = do_CreateInstance("@mozilla.org/contactAddress;1"); | |
| if (!implISupports) { | |
| NS_WARNING("Failed to get JS implementation for contract \"@mozilla.org/contactAddress;1\""); | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer. | |
| nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports); | |
| if (gpi) { | |
| JS::Rooted<JS::Value> initReturn(cx); | |
| nsresult rv = gpi->Init(window, initReturn.address()); | |
| if (NS_FAILED(rv)) { | |
| aRv.Throw(rv); | |
| return nullptr; | |
| } | |
| MOZ_ASSERT(initReturn.isUndefined(), | |
| "Expected nsIDOMGlobalPropertyInitializer to return undefined"); | |
| } | |
| // Extract the JS implementation from the XPCOM object. | |
| nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports); | |
| MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); | |
| if (!implWrapped) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| } | |
| // Build the C++ implementation. | |
| nsRefPtr<ContactAddress> impl = new ContactAddress(jsImplObj, window); | |
| // Wrap the object before calling __Init so that __DOM_IMPL__ is available. | |
| nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window); | |
| JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject()); | |
| JS::Rooted<JS::Value> wrappedVal(cx); | |
| if (!WrapNewBindingObject(cx, scopeObj, impl, wrappedVal.address())) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| // Initialize the object with the constructor arguments. | |
| impl->mImpl->__Init(type, streetAddress, locality, region, postalCode, countryName, pref, aRv); | |
| if (aRv.Failed()) { | |
| return nullptr; | |
| } | |
| return impl.forget(); | |
| } | |
| JS::Value | |
| ContactAddress::GetType(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetType(aRv); | |
| } | |
| void | |
| ContactAddress::SetType(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetType(arg, aRv); | |
| } | |
| void | |
| ContactAddress::GetStreetAddress(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetStreetAddress(retval, aRv); | |
| } | |
| void | |
| ContactAddress::SetStreetAddress(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetStreetAddress(arg, aRv); | |
| } | |
| void | |
| ContactAddress::GetLocality(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetLocality(retval, aRv); | |
| } | |
| void | |
| ContactAddress::SetLocality(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetLocality(arg, aRv); | |
| } | |
| void | |
| ContactAddress::GetRegion(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetRegion(retval, aRv); | |
| } | |
| void | |
| ContactAddress::SetRegion(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetRegion(arg, aRv); | |
| } | |
| void | |
| ContactAddress::GetPostalCode(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetPostalCode(retval, aRv); | |
| } | |
| void | |
| ContactAddress::SetPostalCode(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetPostalCode(arg, aRv); | |
| } | |
| void | |
| ContactAddress::GetCountryName(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetCountryName(retval, aRv); | |
| } | |
| void | |
| ContactAddress::SetCountryName(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetCountryName(arg, aRv); | |
| } | |
| bool | |
| ContactAddress::GetPref(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetPref(aRv); | |
| } | |
| void | |
| ContactAddress::SetPref(bool arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetPref(arg, aRv); | |
| } | |
| JSObject* | |
| ContactAddress::ToJSON(ErrorResult& aRv) | |
| { | |
| return mImpl->ToJSON(aRv); | |
| } | |
| JSObject* | |
| ContactFieldJSImpl::ToJSON(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "toJSON", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NonNullLazyRootedObject rvalDecl; | |
| if (rval.isObject()) { | |
| rvalDecl.construct(cx, &rval.toObject()); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| return rvalDecl.ref(); | |
| } | |
| void | |
| ContactFieldJSImpl::__Init(const Sequence<nsString >& type, const nsAString& value, bool pref, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(3)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| unsigned argc = 3; | |
| do { | |
| argv[2] = BOOLEAN_TO_JSVAL(pref); | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(value); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[1])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| uint32_t length = type.Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, type[sequenceIdx0], tmp.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| } | |
| argv[0] = JS::ObjectValue(*returnArray); | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "__init", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| JS::Value | |
| ContactFieldJSImpl::GetType(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "type", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| void | |
| ContactFieldJSImpl::GetValue(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "value", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eNull, eNull, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| Nullable<bool > | |
| ContactFieldJSImpl::GetPref(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return Nullable<bool >(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "pref", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return Nullable<bool >(); | |
| } | |
| Nullable<bool> rvalDecl; | |
| if (rval.isNullOrUndefined()) { | |
| rvalDecl.SetNull(); | |
| } else if (!ValueToPrimitive<bool, eDefault>(cx, rval, &rvalDecl.SetValue())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return Nullable<bool >(); | |
| } | |
| return rvalDecl; | |
| } | |
| void | |
| ContactFieldJSImpl::SetType(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "type", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactFieldJSImpl::SetValue(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::StringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "value", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactFieldJSImpl::SetPref(const Nullable<bool >& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| if (arg.IsNull()) { | |
| argv[0] = JSVAL_NULL; | |
| break; | |
| } | |
| argv[0] = BOOLEAN_TO_JSVAL(arg.Value()); | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "pref", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(ContactField, mImpl, mParent) | |
| NS_IMPL_CYCLE_COLLECTING_ADDREF(ContactField) | |
| NS_IMPL_CYCLE_COLLECTING_RELEASE(ContactField) | |
| NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContactField) | |
| NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY | |
| NS_INTERFACE_MAP_ENTRY(nsISupports) | |
| NS_INTERFACE_MAP_END | |
| ContactField::ContactField(JS::Handle<JSObject*> aJSImplObject, nsPIDOMWindow* aParent) | |
| : mImpl(new ContactFieldJSImpl(aJSImplObject)), | |
| mParent(aParent) | |
| { | |
| SetIsDOMBinding(); | |
| } | |
| ContactField::~ContactField() | |
| { | |
| } | |
| nsISupports* | |
| ContactField::GetParentObject() const | |
| { | |
| return mParent; | |
| } | |
| JSObject* | |
| ContactField::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) | |
| { | |
| JS::Rooted<JSObject*> obj(aCx, ContactFieldBinding::Wrap(aCx, aScope, this)); | |
| if (!obj) { | |
| return nullptr; | |
| } | |
| // Now define it on our chrome object | |
| JSAutoCompartment ac(aCx, mImpl->Callback()); | |
| if (!JS_WrapObject(aCx, obj.address())) { | |
| return nullptr; | |
| } | |
| if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) { | |
| return nullptr; | |
| } | |
| return obj; | |
| } | |
| already_AddRefed<ContactField> | |
| ContactField::Constructor(const GlobalObject& global, JSContext* cx, const Sequence<nsString >& type, const nsAString& value, bool pref, ErrorResult& aRv) | |
| { | |
| // Get the window to use as a parent and for initialization. | |
| nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get()); | |
| if (!window) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| JS::Rooted<JSObject*> jsImplObj(cx); | |
| // Make sure to have nothing on the JS context stack while creating and | |
| // initializing the object, so exceptions from that will get reported | |
| // properly, since those are never exceptions that a spec wants to be thrown. | |
| { // Scope for the nsCxPusher | |
| nsCxPusher pusher; | |
| pusher.PushNull(); | |
| // Get the XPCOM component containing the JS implementation. | |
| nsCOMPtr<nsISupports> implISupports = do_CreateInstance("@mozilla.org/contactField;1"); | |
| if (!implISupports) { | |
| NS_WARNING("Failed to get JS implementation for contract \"@mozilla.org/contactField;1\""); | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer. | |
| nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports); | |
| if (gpi) { | |
| JS::Rooted<JS::Value> initReturn(cx); | |
| nsresult rv = gpi->Init(window, initReturn.address()); | |
| if (NS_FAILED(rv)) { | |
| aRv.Throw(rv); | |
| return nullptr; | |
| } | |
| MOZ_ASSERT(initReturn.isUndefined(), | |
| "Expected nsIDOMGlobalPropertyInitializer to return undefined"); | |
| } | |
| // Extract the JS implementation from the XPCOM object. | |
| nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports); | |
| MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); | |
| if (!implWrapped) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| } | |
| // Build the C++ implementation. | |
| nsRefPtr<ContactField> impl = new ContactField(jsImplObj, window); | |
| // Wrap the object before calling __Init so that __DOM_IMPL__ is available. | |
| nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window); | |
| JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject()); | |
| JS::Rooted<JS::Value> wrappedVal(cx); | |
| if (!WrapNewBindingObject(cx, scopeObj, impl, wrappedVal.address())) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| // Initialize the object with the constructor arguments. | |
| impl->mImpl->__Init(type, value, pref, aRv); | |
| if (aRv.Failed()) { | |
| return nullptr; | |
| } | |
| return impl.forget(); | |
| } | |
| JS::Value | |
| ContactField::GetType(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetType(aRv); | |
| } | |
| void | |
| ContactField::SetType(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetType(arg, aRv); | |
| } | |
| void | |
| ContactField::GetValue(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetValue(retval, aRv); | |
| } | |
| void | |
| ContactField::SetValue(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetValue(arg, aRv); | |
| } | |
| Nullable<bool > | |
| ContactField::GetPref(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetPref(aRv); | |
| } | |
| void | |
| ContactField::SetPref(const Nullable<bool >& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetPref(arg, aRv); | |
| } | |
| JSObject* | |
| ContactField::ToJSON(ErrorResult& aRv) | |
| { | |
| return mImpl->ToJSON(aRv); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::Find(const ContactFindOptions& options, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return nullptr; | |
| } | |
| unsigned argc = 1; | |
| do { | |
| if (!options.ToObject(cx, CallbackPreserveColor(), &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "find", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMCursor> | |
| ContactManagerJSImpl::GetAll(const ContactFindSortOptions& options, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return nullptr; | |
| } | |
| unsigned argc = 1; | |
| do { | |
| if (!options.ToObject(cx, CallbackPreserveColor(), &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "getAll", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMCursor* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMCursor, mozilla::dom::DOMCursor>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMCursor"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::Clear(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "clear", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::Save(mozilla::dom::mozContact& contact, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return nullptr; | |
| } | |
| unsigned argc = 1; | |
| do { | |
| if (!WrapNewBindingObject(cx, CallbackPreserveColor(), contact, &argv[0])) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "save", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::Remove(mozilla::dom::mozContact& contact, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return nullptr; | |
| } | |
| unsigned argc = 1; | |
| do { | |
| if (!WrapNewBindingObject(cx, CallbackPreserveColor(), contact, &argv[0])) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "remove", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::GetSimContacts(const nsAString& type, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return nullptr; | |
| } | |
| unsigned argc = 1; | |
| do { | |
| nsString mutableStr(type); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "getSimContacts", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<DOMRequest> | |
| ContactManagerJSImpl::GetRevision(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "getRevision", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| mozilla::dom::DOMRequest* rvalDecl; | |
| if (rval.isObject()) { | |
| { | |
| nsresult rv = UnwrapObject<prototypes::id::DOMRequest, mozilla::dom::DOMRequest>(cx, &rval.toObject(), rvalDecl); | |
| if (NS_FAILED(rv)) { | |
| ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "DOMRequest"); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NS_ADDREF(rvalDecl); | |
| return dont_AddRef(rvalDecl); | |
| } | |
| already_AddRefed<EventHandlerNonNull> | |
| ContactManagerJSImpl::GetOncontactchange(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "oncontactchange", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| nsRefPtr<EventHandlerNonNull> rvalDecl; | |
| if (rval.isObject()) { | |
| if (JS_ObjectIsCallable(cx, &rval.toObject())) { | |
| rvalDecl = new EventHandlerNonNull(&rval.toObject()); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_CALLABLE); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| } else if (rval.isNullOrUndefined()) { | |
| rvalDecl = nullptr; | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| return rvalDecl.forget(); | |
| } | |
| void | |
| ContactManagerJSImpl::SetOncontactchange(EventHandlerNonNull* arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| if (arg) { | |
| argv[0] = JS::ObjectValue(*GetCallbackFromCallbackObject(arg)); | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } else { | |
| argv[0] = JS::NullValue(); | |
| break; | |
| } | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "oncontactchange", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| NS_IMPL_CYCLE_COLLECTION_INHERITED_2(ContactManager, nsDOMEventTargetHelper, mImpl, mParent) | |
| NS_IMPL_ADDREF_INHERITED(ContactManager, nsDOMEventTargetHelper) | |
| NS_IMPL_RELEASE_INHERITED(ContactManager, nsDOMEventTargetHelper) | |
| NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ContactManager) | |
| NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper) | |
| ContactManager::ContactManager(JS::Handle<JSObject*> aJSImplObject, nsPIDOMWindow* aParent) | |
| : nsDOMEventTargetHelper(aParent), | |
| mImpl(new ContactManagerJSImpl(aJSImplObject)), | |
| mParent(aParent) | |
| { | |
| // Make sure we're an nsWrapperCache already | |
| MOZ_ASSERT(static_cast<nsWrapperCache*>(this)); | |
| // And that our ancestor has called SetIsDOMBinding() | |
| MOZ_ASSERT(IsDOMBinding()); | |
| } | |
| nsISupports* | |
| ContactManager::GetParentObject() const | |
| { | |
| return mParent; | |
| } | |
| JSObject* | |
| ContactManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) | |
| { | |
| JS::Rooted<JSObject*> obj(aCx, ContactManagerBinding::Wrap(aCx, aScope, this)); | |
| if (!obj) { | |
| return nullptr; | |
| } | |
| // Now define it on our chrome object | |
| JSAutoCompartment ac(aCx, mImpl->Callback()); | |
| if (!JS_WrapObject(aCx, obj.address())) { | |
| return nullptr; | |
| } | |
| if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) { | |
| return nullptr; | |
| } | |
| return obj; | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::Find(const ContactFindOptions& options, ErrorResult& aRv) | |
| { | |
| return mImpl->Find(options, aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMCursor> | |
| ContactManager::GetAll(const ContactFindSortOptions& options, ErrorResult& aRv) | |
| { | |
| return mImpl->GetAll(options, aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::Clear(ErrorResult& aRv) | |
| { | |
| return mImpl->Clear(aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::Save(mozilla::dom::mozContact& contact, ErrorResult& aRv) | |
| { | |
| return mImpl->Save(contact, aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::Remove(mozilla::dom::mozContact& contact, ErrorResult& aRv) | |
| { | |
| return mImpl->Remove(contact, aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::GetSimContacts(const nsAString& type, ErrorResult& aRv) | |
| { | |
| return mImpl->GetSimContacts(type, aRv); | |
| } | |
| already_AddRefed<EventHandlerNonNull> | |
| ContactManager::GetOncontactchange(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetOncontactchange(aRv); | |
| } | |
| void | |
| ContactManager::SetOncontactchange(EventHandlerNonNull* arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetOncontactchange(arg, aRv); | |
| } | |
| // Mark this as resultNotAddRefed to return raw pointers | |
| already_AddRefed<DOMRequest> | |
| ContactManager::GetRevision(ErrorResult& aRv) | |
| { | |
| return mImpl->GetRevision(aRv); | |
| } | |
| void | |
| mozContactJSImpl::SetMetadata(const nsAString& id, const Optional<LazyRootedValue >& published, const Optional<LazyRootedValue >& updated, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(3)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| unsigned argc = 3; | |
| do { | |
| if (updated.WasPassed()) { | |
| argv[2] = updated.Value(); | |
| if (!MaybeWrapValue(cx, &argv[2])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } else if (argc == 3) { | |
| // This is our current trailing argument; reduce argc | |
| --argc; | |
| } else { | |
| argv[2] = JS::UndefinedValue(); | |
| } | |
| } while (0); | |
| do { | |
| if (published.WasPassed()) { | |
| argv[1] = published.Value(); | |
| if (!MaybeWrapValue(cx, &argv[1])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } else if (argc == 2) { | |
| // This is our current trailing argument; reduce argc | |
| --argc; | |
| } else { | |
| argv[1] = JS::UndefinedValue(); | |
| } | |
| } while (0); | |
| do { | |
| nsString mutableStr(id); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "setMetadata", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| JSObject* | |
| mozContactJSImpl::ToJSON(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "toJSON", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NonNullLazyRootedObject rvalDecl; | |
| if (rval.isObject()) { | |
| rvalDecl.construct(cx, &rval.toObject()); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| return rvalDecl.ref(); | |
| } | |
| void | |
| mozContactJSImpl::__Init(const ContactProperties& properties, const ContactMetadata& metadata, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(2)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| unsigned argc = 2; | |
| do { | |
| if (!metadata.ToObject(cx, CallbackPreserveColor(), &argv[1])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| if (!properties.ToObject(cx, CallbackPreserveColor(), &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "__init", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::GetId(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "id", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetPublished(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "published", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetUpdated(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "updated", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetBday(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "bday", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetAnniversary(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "anniversary", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| void | |
| mozContactJSImpl::GetSex(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "sex", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| mozContactJSImpl::GetGenderIdentity(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "genderIdentity", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eStringify, eStringify, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetPhoto(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "photo", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetAdr(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "adr", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetEmail(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "email", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetUrl(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "url", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetImpp(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "impp", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetTel(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "tel", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetName(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "name", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetHonorificPrefix(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "honorificPrefix", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetGivenName(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "givenName", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetAdditionalName(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "additionalName", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetFamilyName(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "familyName", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetHonorificSuffix(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "honorificSuffix", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetNickname(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "nickname", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetCategory(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "category", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetOrg(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "org", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetJobTitle(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "jobTitle", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| JS::Value | |
| mozContactJSImpl::GetNote(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "note", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return JS::UndefinedValue(); | |
| } | |
| LazyRootedValue rvalDecl; | |
| rvalDecl.construct(cx, rval); | |
| return rvalDecl; | |
| } | |
| void | |
| mozContactJSImpl::SetId(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "id", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetBday(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "bday", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetAnniversary(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "anniversary", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetSex(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "sex", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetGenderIdentity(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "genderIdentity", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetPhoto(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "photo", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetAdr(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "adr", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetEmail(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "email", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetUrl(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "url", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetImpp(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "impp", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetTel(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "tel", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetName(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "name", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetHonorificPrefix(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "honorificPrefix", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetGivenName(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "givenName", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetAdditionalName(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "additionalName", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetFamilyName(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "familyName", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetHonorificSuffix(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "honorificSuffix", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetNickname(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "nickname", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetCategory(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "category", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetOrg(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "org", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetJobTitle(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "jobTitle", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| mozContactJSImpl::SetNote(JS::Value arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| argv[0] = arg; | |
| if (!MaybeWrapValue(cx, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "note", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(mozContact, mImpl, mParent) | |
| NS_IMPL_CYCLE_COLLECTING_ADDREF(mozContact) | |
| NS_IMPL_CYCLE_COLLECTING_RELEASE(mozContact) | |
| NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(mozContact) | |
| NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY | |
| NS_INTERFACE_MAP_ENTRY(nsISupports) | |
| NS_INTERFACE_MAP_END | |
| mozContact::mozContact(JS::Handle<JSObject*> aJSImplObject, nsPIDOMWindow* aParent) | |
| : mImpl(new mozContactJSImpl(aJSImplObject)), | |
| mParent(aParent) | |
| { | |
| SetIsDOMBinding(); | |
| } | |
| nsISupports* | |
| mozContact::GetParentObject() const | |
| { | |
| return mParent; | |
| } | |
| JSObject* | |
| mozContact::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) | |
| { | |
| JS::Rooted<JSObject*> obj(aCx, mozContactBinding::Wrap(aCx, aScope, this)); | |
| if (!obj) { | |
| return nullptr; | |
| } | |
| // Now define it on our chrome object | |
| JSAutoCompartment ac(aCx, mImpl->Callback()); | |
| if (!JS_WrapObject(aCx, obj.address())) { | |
| return nullptr; | |
| } | |
| if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) { | |
| return nullptr; | |
| } | |
| return obj; | |
| } | |
| already_AddRefed<mozContact> | |
| mozContact::Constructor(const GlobalObject& global, JSContext* cx, const ContactProperties& properties, const ContactMetadata& metadata, ErrorResult& aRv) | |
| { | |
| // Get the window to use as a parent and for initialization. | |
| nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get()); | |
| if (!window) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| JS::Rooted<JSObject*> jsImplObj(cx); | |
| // Make sure to have nothing on the JS context stack while creating and | |
| // initializing the object, so exceptions from that will get reported | |
| // properly, since those are never exceptions that a spec wants to be thrown. | |
| { // Scope for the nsCxPusher | |
| nsCxPusher pusher; | |
| pusher.PushNull(); | |
| // Get the XPCOM component containing the JS implementation. | |
| nsCOMPtr<nsISupports> implISupports = do_CreateInstance("@mozilla.org/contact;1"); | |
| if (!implISupports) { | |
| NS_WARNING("Failed to get JS implementation for contract \"@mozilla.org/contact;1\""); | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer. | |
| nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports); | |
| if (gpi) { | |
| JS::Rooted<JS::Value> initReturn(cx); | |
| nsresult rv = gpi->Init(window, initReturn.address()); | |
| if (NS_FAILED(rv)) { | |
| aRv.Throw(rv); | |
| return nullptr; | |
| } | |
| MOZ_ASSERT(initReturn.isUndefined(), | |
| "Expected nsIDOMGlobalPropertyInitializer to return undefined"); | |
| } | |
| // Extract the JS implementation from the XPCOM object. | |
| nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports); | |
| MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); | |
| if (!implWrapped) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| } | |
| // Build the C++ implementation. | |
| nsRefPtr<mozContact> impl = new mozContact(jsImplObj, window); | |
| // Wrap the object before calling __Init so that __DOM_IMPL__ is available. | |
| nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window); | |
| JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject()); | |
| JS::Rooted<JS::Value> wrappedVal(cx); | |
| if (!WrapNewBindingObject(cx, scopeObj, impl, wrappedVal.address())) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| // Initialize the object with the constructor arguments. | |
| impl->mImpl->__Init(properties, metadata, aRv); | |
| if (aRv.Failed()) { | |
| return nullptr; | |
| } | |
| return impl.forget(); | |
| } | |
| void | |
| mozContact::GetId(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetId(retval, aRv); | |
| } | |
| void | |
| mozContact::SetId(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetId(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetPublished(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetPublished(aRv); | |
| } | |
| JS::Value | |
| mozContact::GetUpdated(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetUpdated(aRv); | |
| } | |
| JS::Value | |
| mozContact::GetBday(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetBday(aRv); | |
| } | |
| void | |
| mozContact::SetBday(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetBday(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetAnniversary(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetAnniversary(aRv); | |
| } | |
| void | |
| mozContact::SetAnniversary(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetAnniversary(arg, aRv); | |
| } | |
| void | |
| mozContact::GetSex(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetSex(retval, aRv); | |
| } | |
| void | |
| mozContact::SetSex(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetSex(arg, aRv); | |
| } | |
| void | |
| mozContact::GetGenderIdentity(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetGenderIdentity(retval, aRv); | |
| } | |
| void | |
| mozContact::SetGenderIdentity(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetGenderIdentity(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetPhoto(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetPhoto(aRv); | |
| } | |
| void | |
| mozContact::SetPhoto(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetPhoto(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetAdr(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetAdr(aRv); | |
| } | |
| void | |
| mozContact::SetAdr(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetAdr(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetEmail(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetEmail(aRv); | |
| } | |
| void | |
| mozContact::SetEmail(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetEmail(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetUrl(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetUrl(aRv); | |
| } | |
| void | |
| mozContact::SetUrl(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetUrl(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetImpp(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetImpp(aRv); | |
| } | |
| void | |
| mozContact::SetImpp(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetImpp(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetTel(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetTel(aRv); | |
| } | |
| void | |
| mozContact::SetTel(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetTel(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetName(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetName(aRv); | |
| } | |
| void | |
| mozContact::SetName(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetName(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetHonorificPrefix(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetHonorificPrefix(aRv); | |
| } | |
| void | |
| mozContact::SetHonorificPrefix(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetHonorificPrefix(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetGivenName(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetGivenName(aRv); | |
| } | |
| void | |
| mozContact::SetGivenName(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetGivenName(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetAdditionalName(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetAdditionalName(aRv); | |
| } | |
| void | |
| mozContact::SetAdditionalName(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetAdditionalName(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetFamilyName(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetFamilyName(aRv); | |
| } | |
| void | |
| mozContact::SetFamilyName(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetFamilyName(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetHonorificSuffix(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetHonorificSuffix(aRv); | |
| } | |
| void | |
| mozContact::SetHonorificSuffix(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetHonorificSuffix(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetNickname(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetNickname(aRv); | |
| } | |
| void | |
| mozContact::SetNickname(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetNickname(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetCategory(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetCategory(aRv); | |
| } | |
| void | |
| mozContact::SetCategory(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetCategory(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetOrg(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetOrg(aRv); | |
| } | |
| void | |
| mozContact::SetOrg(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetOrg(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetJobTitle(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetJobTitle(aRv); | |
| } | |
| void | |
| mozContact::SetJobTitle(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetJobTitle(arg, aRv); | |
| } | |
| JS::Value | |
| mozContact::GetNote(ErrorResult& aRv) const | |
| { | |
| return mImpl->GetNote(aRv); | |
| } | |
| void | |
| mozContact::SetNote(JS::Value arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetNote(arg, aRv); | |
| } | |
| void | |
| mozContact::SetMetadata(const nsAString& id, const Optional<LazyRootedValue >& published, const Optional<LazyRootedValue >& updated, ErrorResult& aRv) | |
| { | |
| return mImpl->SetMetadata(id, published, updated, aRv); | |
| } | |
| JSObject* | |
| mozContact::ToJSON(ErrorResult& aRv) | |
| { | |
| return mImpl->ToJSON(aRv); | |
| } | |
| JSObject* | |
| ContactTelFieldJSImpl::ToJSON(ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "toJSON", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| 0, nullptr, rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| NonNullLazyRootedObject rvalDecl; | |
| if (rval.isObject()) { | |
| rvalDecl.construct(cx, &rval.toObject()); | |
| } else { | |
| ThrowErrorMessage(cx, MSG_NOT_OBJECT); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| return rvalDecl.ref(); | |
| } | |
| void | |
| ContactTelFieldJSImpl::__Init(const Sequence<nsString >& type, const nsAString& value, const nsAString& carrier, bool pref, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(4)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| unsigned argc = 4; | |
| do { | |
| argv[3] = BOOLEAN_TO_JSVAL(pref); | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(carrier); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[2])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| nsString mutableStr(value); | |
| if (!xpc::NonVoidStringToJsval(cx, mutableStr, &argv[1])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| do { | |
| uint32_t length = type.Length(); | |
| JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr)); | |
| if (!returnArray) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| // Scope for 'tmp' | |
| { | |
| JS::Rooted<JS::Value> tmp(cx); | |
| for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { | |
| // Control block to let us common up the JS_DefineElement calls when there | |
| // are different ways to succeed at wrapping the object. | |
| do { | |
| if (!xpc::NonVoidStringToJsval(cx, type[sequenceIdx0], tmp.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, | |
| nullptr, nullptr, JSPROP_ENUMERATE)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| } | |
| argv[0] = JS::ObjectValue(*returnArray); | |
| break; | |
| } while (0); | |
| JS::Rooted<JS::Value> callable(cx); | |
| if (!GetCallableProperty(cx, "__init", &callable)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| if (!JS_CallFunctionValue(cx, mCallback, callable, | |
| argc, argv.begin(), rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| void | |
| ContactTelFieldJSImpl::GetCarrier(nsString& retval, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue()); | |
| if (!JS_GetProperty(cx, mCallback, "carrier", rval.address())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| FakeDependentString rvalHolder; | |
| NonNull<nsAString> rvalDecl; | |
| if (!ConvertJSValueToString(cx, rval, rval.address(), eNull, eNull, rvalHolder)) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| rvalDecl = &rvalHolder; | |
| retval = rvalDecl; | |
| } | |
| void | |
| ContactTelFieldJSImpl::SetCarrier(const nsAString& arg, ErrorResult& aRv, ExceptionHandling aExceptionHandling) | |
| { | |
| CallSetup s(CallbackPreserveColor(), aRv, aExceptionHandling); | |
| JSContext* cx = s.GetContext(); | |
| if (!cx) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| JS::AutoValueVector argv(cx); | |
| if (!argv.resize(1)) { | |
| aRv.Throw(NS_ERROR_OUT_OF_MEMORY); | |
| return; | |
| } | |
| do { | |
| nsString mutableStr(arg); | |
| if (!xpc::StringToJsval(cx, mutableStr, &argv[0])) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| break; | |
| } while (0); | |
| MOZ_ASSERT(argv.length() == 1); | |
| if (!JS_SetProperty(cx, mCallback, "carrier", argv.begin())) { | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return; | |
| } | |
| } | |
| NS_IMPL_CYCLE_COLLECTION_INHERITED_2(ContactTelField, mozilla::dom::ContactField, mImpl, mParent) | |
| NS_IMPL_ADDREF_INHERITED(ContactTelField, mozilla::dom::ContactField) | |
| NS_IMPL_RELEASE_INHERITED(ContactTelField, mozilla::dom::ContactField) | |
| NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ContactTelField) | |
| NS_INTERFACE_MAP_END_INHERITING(mozilla::dom::ContactField) | |
| ContactTelField::ContactTelField(JS::Handle<JSObject*> aJSImplObject, nsPIDOMWindow* aParent) | |
| : mozilla::dom::ContactField(aJSImplObject, aParent), | |
| mImpl(new ContactTelFieldJSImpl(aJSImplObject)), | |
| mParent(aParent) | |
| { | |
| // Make sure we're an nsWrapperCache already | |
| MOZ_ASSERT(static_cast<nsWrapperCache*>(this)); | |
| // And that our ancestor has called SetIsDOMBinding() | |
| MOZ_ASSERT(IsDOMBinding()); | |
| } | |
| nsISupports* | |
| ContactTelField::GetParentObject() const | |
| { | |
| return mParent; | |
| } | |
| JSObject* | |
| ContactTelField::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) | |
| { | |
| JS::Rooted<JSObject*> obj(aCx, ContactTelFieldBinding::Wrap(aCx, aScope, this)); | |
| if (!obj) { | |
| return nullptr; | |
| } | |
| // Now define it on our chrome object | |
| JSAutoCompartment ac(aCx, mImpl->Callback()); | |
| if (!JS_WrapObject(aCx, obj.address())) { | |
| return nullptr; | |
| } | |
| if (!JS_DefineProperty(aCx, mImpl->Callback(), "__DOM_IMPL__", JS::ObjectValue(*obj), nullptr, nullptr, 0)) { | |
| return nullptr; | |
| } | |
| return obj; | |
| } | |
| already_AddRefed<ContactTelField> | |
| ContactTelField::Constructor(const GlobalObject& global, JSContext* cx, const Sequence<nsString >& type, const nsAString& value, const nsAString& carrier, bool pref, ErrorResult& aRv) | |
| { | |
| // Get the window to use as a parent and for initialization. | |
| nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get()); | |
| if (!window) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| JS::Rooted<JSObject*> jsImplObj(cx); | |
| // Make sure to have nothing on the JS context stack while creating and | |
| // initializing the object, so exceptions from that will get reported | |
| // properly, since those are never exceptions that a spec wants to be thrown. | |
| { // Scope for the nsCxPusher | |
| nsCxPusher pusher; | |
| pusher.PushNull(); | |
| // Get the XPCOM component containing the JS implementation. | |
| nsCOMPtr<nsISupports> implISupports = do_CreateInstance("@mozilla.org/contactTelField;1"); | |
| if (!implISupports) { | |
| NS_WARNING("Failed to get JS implementation for contract \"@mozilla.org/contactTelField;1\""); | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| // Initialize the object, if it implements nsIDOMGlobalPropertyInitializer. | |
| nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports); | |
| if (gpi) { | |
| JS::Rooted<JS::Value> initReturn(cx); | |
| nsresult rv = gpi->Init(window, initReturn.address()); | |
| if (NS_FAILED(rv)) { | |
| aRv.Throw(rv); | |
| return nullptr; | |
| } | |
| MOZ_ASSERT(initReturn.isUndefined(), | |
| "Expected nsIDOMGlobalPropertyInitializer to return undefined"); | |
| } | |
| // Extract the JS implementation from the XPCOM object. | |
| nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports); | |
| MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component."); | |
| if (!implWrapped) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| if (NS_FAILED(implWrapped->GetJSObject(jsImplObj.address()))) { | |
| aRv.Throw(NS_ERROR_FAILURE); | |
| return nullptr; | |
| } | |
| } | |
| // Build the C++ implementation. | |
| nsRefPtr<ContactTelField> impl = new ContactTelField(jsImplObj, window); | |
| // Wrap the object before calling __Init so that __DOM_IMPL__ is available. | |
| nsCOMPtr<nsIGlobalObject> globalHolder = do_QueryInterface(window); | |
| JS::Rooted<JSObject*> scopeObj(cx, globalHolder->GetGlobalJSObject()); | |
| JS::Rooted<JS::Value> wrappedVal(cx); | |
| if (!WrapNewBindingObject(cx, scopeObj, impl, wrappedVal.address())) { | |
| MOZ_ASSERT(JS_IsExceptionPending(cx)); | |
| aRv.Throw(NS_ERROR_UNEXPECTED); | |
| return nullptr; | |
| } | |
| // Initialize the object with the constructor arguments. | |
| impl->mImpl->__Init(type, value, carrier, pref, aRv); | |
| if (aRv.Failed()) { | |
| return nullptr; | |
| } | |
| return impl.forget(); | |
| } | |
| void | |
| ContactTelField::GetCarrier(nsString& retval, ErrorResult& aRv) const | |
| { | |
| return mImpl->GetCarrier(retval, aRv); | |
| } | |
| void | |
| ContactTelField::SetCarrier(const nsAString& arg, ErrorResult& aRv) | |
| { | |
| mImpl->SetCarrier(arg, aRv); | |
| } | |
| JSObject* | |
| ContactTelField::ToJSON(ErrorResult& aRv) | |
| { | |
| return mImpl->ToJSON(aRv); | |
| } | |
| } // namespace dom | |
| } // namespace mozilla |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment