Discovered that trying to use duck-typing in passing an object into cookieExists() will hard-crash Firefox, and figured out why; added comment to syncCores.js explaining this.
authorjonathandicarlo@jonathan-dicarlos-macbook-pro.local
Thu, 03 Apr 2008 14:30:34 -0700
changeset 44420 c400385f8c1efaa32920f99ea366e3c43c7b2ba6
parent 44419 a0b5a748653d71ec475b772ed2bf393e9d1e12e1
child 44422 cb241593580e1ec0bd87cd5e2df29bbfa464b677
child 44423 09878516185054365eb21acb6252f47ea457efd4
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Discovered that trying to use duck-typing in passing an object into cookieExists() will hard-crash Firefox, and figured out why; added comment to syncCores.js explaining this.
services/sync/modules/syncCores.js
--- a/services/sync/modules/syncCores.js
+++ b/services/sync/modules/syncCores.js
@@ -444,45 +444,52 @@ CookieSyncCore.prototype = {
                              getService(Ci.nsICookieManager2);
     // need the 2nd revision of the ICookieManager interface
     // because it supports add() and the 1st one doesn't.
     return this.__cookieManager
   },
 
 
   _itemExists: function CSC__itemExists(GUID) {
-    // true if a cookie with the given GUID exists.
-    // The GUID that we are passed should correspond to the keys
-    // that we define in the JSON returned by CookieStore.wrap()
-    // That is, it will be a string of the form
-    // "host:path:name".
+    /* true if a cookie with the given GUID exists.
+       The GUID that we are passed should correspond to the keys
+       that we define in the JSON returned by CookieStore.wrap()
+       That is, it will be a string of the form
+       "host:path:name". */
     
-    // TODO verify that colons can't normally appear in any of
-    // the fields -- if they did it then we can't rely on .split(":")
-    // to parse correctly.
+    /* TODO verify that colons can't normally appear in any of
+       the fields -- if they did it then we can't rely on .split(":")
+       to parse correctly.*/
     
     let cookieArray = GUID.split( ":" );
     let cookieHost = cookieArray[0];
     let cookiePath = cookieArray[1];
     let cookieName = cookieArray[2];
 
-    // alternate implementation would be to instantiate a cookie from
-    // cookieHost, cookiePath, and cookieName, 
-    // then call cookieManager.cookieExists().
+    /* alternate implementation would be to instantiate a cookie from
+       cookieHost, cookiePath, and cookieName, then call 
+       cookieManager.cookieExists(). Maybe that would have better
+       performance?  This implementation seems pretty slow.*/
     let enumerator = this._cookieManager.enumerator;
     while (enumerator.hasMoreElements())
       {
 	let aCookie = enumerator.getNext();
 	if (aCookie.host == cookieHost &&
 	    aCookie.path == cookiePath &&
 	    aCookie.name == cookieName ) {
 	  return true;
 	}
       }
     return false;
+    /* Note: We can't just call cookieManager.cookieExists() with a generic
+       javascript object with .host, .path, and .name attributes attatched.
+       cookieExists is implemented in C and does a hard static_cast to an
+       nsCookie object, so duck typing doesn't work (and in fact makes 
+       Firefox hard-crash as the static_cast returns null and is not checked.)
+    */
   },
 
   _commandLike: function CSC_commandLike(a, b) {
     // Method required to be overridden.
     // a and b each have a .data and a .GUID
     // If this function returns true, an editCommand will be
     // generated to try to resolve the thing.
     // but are a and b objects of the type in the Store or