Bug 773962 - Introduce Cu.recomputeWrappers. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Mon, 23 Jul 2012 15:51:18 +0200
changeset 100130 325ff8e04bf103885c47ceac1fc2f8e7292de973
parent 100129 64aba0b5c3746a69cd063ac13dd7adb15c5303b7
child 100131 195065ccf37bcf8b7ec88be41cd04def616ce2b8
push id12343
push userbobbyholley@gmail.com
push dateMon, 23 Jul 2012 13:51:47 +0000
treeherdermozilla-inbound@195065ccf37b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs773962, 742444
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 773962 - Introduce Cu.recomputeWrappers. r=mrbkap It's sort of annoying to add this API just for tests, but there's not another great way to trigger a compartment-wide transplant with Xray waivers (since setting document.domain doesn't recompute wrappers to/from chrome, and Xray waivers will stop being accessible to content entirely in bug 742444).
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -113,17 +113,17 @@ interface nsIXPCComponents_utils_Sandbox
 interface ScheduledGCCallback : nsISupports
 {
     void callback();
 };
 
 /**
 * interface of Components.utils
 */
-[scriptable, uuid(fc26b9e9-87a1-44a4-b774-53781b7df16b)]
+[scriptable, uuid(2df24c04-f1ef-481c-8605-433082a34e95)]
 interface nsIXPCComponents_Utils : nsISupports
 {
 
     /* reportError is designed to be called from JavaScript only.
      *
      * It will report a JS Error object to the JS console, and return. It
      * is meant for use in exception handler blocks which want to "eat"
      * an exception, but still want to report it to the console.
@@ -307,16 +307,27 @@ interface nsIXPCComponents_Utils : nsISu
      *
      * Dead-wrapper objects hold no other objects alive (they have no outgoing
      * reference edges) and will throw if you touch them (e.g. by
      * reading/writing a property).
      */
     bool isDeadWrapper(in jsval obj);
 
     /*
+     * To be called from JS only. This is for Gecko internal use only, and may
+     * disappear at any moment.
+     *
+     * Forces a recomputation of all wrappers in and out of the compartment
+     * containing |obj|. If |obj| is not an object, all wrappers system-wide
+     * are recomputed.
+     */
+    [implicit_jscontext]
+    void recomputeWrappers([optional] in jsval vobj);
+
+    /*
      * To be called from JS only.
      *
      * These are the set of JSContext options that privileged script
      * is allowed to control for the purposes of testing.  These
      * options should be kept in sync with what's controllable in the
      * jsshell and by setting prefs in nsJSEnvironment.
      *
      * NB: Assume that getting any of these attributes is relatively
@@ -351,17 +362,17 @@ interface nsIXPCComponents_Utils : nsISu
 
     [implicit_jscontext]
     void nukeSandbox(in jsval obj);
 };
 
 /**
 * interface of JavaScript's 'Components' object
 */
-[scriptable, uuid(4676e9cf-2c07-423b-b161-26bb9d8067d3)]
+[scriptable, uuid(8406dedb-23cc-42db-9f69-1f18785091b5)]
 interface nsIXPCComponents : nsISupports
 {
     readonly attribute nsIXPCComponents_Interfaces      interfaces;
     readonly attribute nsIXPCComponents_InterfacesByID  interfacesByID;
     readonly attribute nsIXPCComponents_Classes         classes;
     readonly attribute nsIXPCComponents_ClassesByID     classesByID;
     readonly attribute nsIStackFrame                    stack;
     readonly attribute nsIXPCComponents_Results         results;
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -4302,16 +4302,34 @@ nsXPCComponents_Utils::IsDeadWrapper(con
     *out = false;
     if (JSVAL_IS_PRIMITIVE(obj))
         return NS_ERROR_INVALID_ARG;
 
     *out = JS_IsDeadWrapper(JSVAL_TO_OBJECT(obj));
     return NS_OK;
 }
 
+/* void recomputerWrappers(jsval vobj); */
+NS_IMETHODIMP
+nsXPCComponents_Utils::RecomputeWrappers(const jsval &vobj, JSContext *cx)
+{
+    // Determine the compartment of the given object, if any.
+    JSCompartment *c = vobj.isObject()
+                       ? js::GetObjectCompartment(js::UnwrapObject(&vobj.toObject()))
+                       : NULL;
+
+    // If no compartment was given, recompute all.
+    if (!c)
+        return js::RecomputeWrappers(cx, js::AllCompartments(), js::AllCompartments());
+
+    // Otherwise, recompute wrappers for the given compartment.
+    return js::RecomputeWrappers(cx, js::SingleCompartment(c), js::AllCompartments()) &&
+           js::RecomputeWrappers(cx, js::AllCompartments(), js::SingleCompartment(c));
+}
+
 /* string canCreateWrapper (in nsIIDPtr iid); */
 NS_IMETHODIMP
 nsXPCComponents_Utils::CanCreateWrapper(const nsIID * iid, char **_retval)
 {
     // We let anyone do this...
     *_retval = xpc_CloneAllAccess();
     return NS_OK;
 }