Bug 865969 part 9. Remaining miscellaneous rooting fixes in WebIDL bindings. r=ms2ger
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 03 May 2013 19:29:09 -0400
changeset 141762 fd740c1533feb6fcb3fbbe711e4c017185c7e198
parent 141761 7b6fb38754e109a5f420395bf7d81b121284c821
child 141763 8e05ccbcb09b9069e5f0d562f1293f292d3f9962
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersms2ger
bugs865969
milestone23.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 865969 part 9. Remaining miscellaneous rooting fixes in WebIDL bindings. r=ms2ger
dom/bindings/BindingUtils.h
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.h
+++ b/dom/bindings/BindingUtils.h
@@ -620,17 +620,17 @@ WrapNewBindingObject(JSContext* cx, JS::
 template <class T>
 inline bool
 WrapNewBindingNonWrapperCachedObject(JSContext* cx,
                                      JS::Handle<JSObject*> scopeArg,
                                      T* value, JS::Value* vp)
 {
   MOZ_ASSERT(value);
   // We try to wrap in the compartment of the underlying object of "scope"
-  JSObject* obj;
+  JS::Rooted<JSObject*> obj(cx);
   {
     // scope for the JSAutoCompartment so that we restore the compartment
     // before we call JS_WrapValue.
     Maybe<JSAutoCompartment> ac;
     // Maybe<Handle> doesn't so much work, and in any case, adding
     // more Maybe (one for a Rooted and one for a Handle) adds more
     // code (and branches!) than just adding a single rooted.
     JS::Rooted<JSObject*> scope(cx, scopeArg);
@@ -665,17 +665,17 @@ WrapNewBindingNonWrapperCachedOwnedObjec
                                           nsAutoPtr<T>& value, JS::Value* vp)
 {
   // We do a runtime check on value, because otherwise we might in
   // fact end up wrapping a null and invoking methods on it later.
   if (!value) {
     NS_RUNTIMEABORT("Don't try to wrap null objects");
   }
   // We try to wrap in the compartment of the underlying object of "scope"
-  JSObject* obj;
+  JS::Rooted<JSObject*> obj(cx);
   {
     // scope for the JSAutoCompartment so that we restore the compartment
     // before we call JS_WrapValue.
     Maybe<JSAutoCompartment> ac;
     // Maybe<Handle> doesn't so much work, and in any case, adding
     // more Maybe (one for a Rooted and one for a Handle) adds more
     // code (and branches!) than just adding a single rooted.
     JS::Rooted<JSObject*> scope(cx, scopeArg);
@@ -683,19 +683,17 @@ WrapNewBindingNonWrapperCachedOwnedObjec
       scope = js::CheckedUnwrap(scope, /* stopAtOuter = */ false);
       if (!scope)
         return false;
       ac.construct(cx, scope);
     }
 
     bool tookOwnership = false;
     obj = value->WrapObject(cx, scope, &tookOwnership);
-    if (obj) {
-      MOZ_ASSERT(tookOwnership);
-    }
+    MOZ_ASSERT_IF(obj, tookOwnership);
     if (tookOwnership) {
       value.forget();
     }
   }
 
   if (!obj) {
     return false;
   }
@@ -1017,18 +1015,18 @@ WrapObject(JSContext* cx, JS::Handle<JSO
 // WrapObject() above, but does NOT allow Xrays around the result, since we
 // don't want those for our parent object.
 template<typename T>
 static inline JSObject*
 WrapNativeISupportsParent(JSContext* cx, JS::Handle<JSObject*> scope, T* p,
                           nsWrapperCache* cache)
 {
   qsObjectHelper helper(ToSupports(p), cache);
-  JS::Value v;
-  return XPCOMObjectToJsval(cx, scope, helper, nullptr, false, &v) ?
+  JS::Rooted<JS::Value> v(cx);
+  return XPCOMObjectToJsval(cx, scope, helper, nullptr, false, v.address()) ?
          JSVAL_TO_OBJECT(v) :
          nullptr;
 }
 
 
 // Fallback for when our parent is not a WebIDL binding object.
 template<typename T, bool isISupports=IsISupports<T>::Value >
 struct WrapNativeParentFallback
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -224,17 +224,17 @@ def CallOnUnforgeableHolder(descriptor, 
     If isXrayCheck is not None it should be a string that contains a statement
     returning whether proxy is an Xray. If isXrayCheck is None the generated
     code won't try to unwrap Xrays.
     """
     code = string.Template(code).substitute({ "holder": "unforgeableHolder" })
     if not isXrayCheck is None:
         pre = """// Scope for 'global', 'ac' and 'unforgeableHolder'
 {
-  JSObject* global;
+  JS::Rooted<JSObject*> global(cx);
   Maybe<JSAutoCompartment> ac;
   if (""" + isXrayCheck + """) {
     global = js::GetGlobalForObjectCrossCompartment(js::UncheckedUnwrap(proxy));
     ac.construct(cx, global);
   } else {
     global = js::GetGlobalForObjectCrossCompartment(proxy);
   }"""
     else:
@@ -2268,18 +2268,18 @@ class CastableObjectUnwrapper():
                               "codeOnFailure" : CGIndenter(CGGeneric(codeOnFailure), 4).define() }
         if descriptor.hasXPConnectImpls:
             # We don't use xpc_qsUnwrapThis because it will always throw on
             # unwrap failure, whereas we want to control whether we throw or
             # not.
             self.substitution["codeOnFailure"] = CGIndenter(CGGeneric(string.Template(
                 "${type} *objPtr;\n"
                 "xpc_qsSelfRef objRef;\n"
-                "JS::Value val = JS::ObjectValue(*${source});\n"
-                "nsresult rv = xpc_qsUnwrapArg<${type}>(cx, val, &objPtr, &objRef.ptr, &val);\n"
+                "JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*${source}));\n"
+                "nsresult rv = xpc_qsUnwrapArg<${type}>(cx, val, &objPtr, &objRef.ptr, val.address());\n"
                 "if (NS_FAILED(rv)) {\n"
                 "${codeOnFailure}\n"
                 "}\n"
                 "// We should be castable!\n"
                 "MOZ_ASSERT(!objRef.ptr);\n"
                 "// We should have an object, too!\n"
                 "MOZ_ASSERT(objPtr);\n"
                 "${target} = objPtr;").substitute(self.substitution)), 4).define()
@@ -3684,33 +3684,33 @@ if (%s.IsNull()) {
         index = "sequenceIdx%d" % sequenceWrapLevel
         sequenceWrapLevel += 1
         innerTemplate = wrapForType(
             type.inner, descriptorProvider,
             {
                 'result' :  "%s[%s]" % (result, index),
                 'successCode': "break;",
                 'jsvalRef': "tmp",
-                'jsvalPtr': "&tmp",
+                'jsvalPtr': "tmp.address()",
                 'isCreator': isCreator,
                 'exceptionCode': exceptionCode,
                 'obj': "returnArray"
                 }
             )
         sequenceWrapLevel -= 1
         innerTemplate = CGIndenter(CGGeneric(innerTemplate), 6).define()
         return (("""
 uint32_t length = %s.Length();
 JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length, nullptr));
 if (!returnArray) {
 %s
 }
 // Scope for 'tmp'
 {
-  jsval tmp;
+  JS::Rooted<JS::Value> tmp(cx);
   for (uint32_t %s = 0; %s < length; ++%s) {
     // Control block to let us common up the JS_DefineElement calls when there
     // are different ways to succeed at wrapping the object.
     do {
 %s
     } while (0);
     if (!JS_DefineElement(cx, returnArray, %s, tmp,
                           nullptr, nullptr, JSPROP_ENUMERATE)) {
@@ -6592,17 +6592,17 @@ MOZ_ASSERT_IF(desc->obj, desc->obj == ${
                 condition = "!IsArrayIndex(index) && " + condition
             namedGet = ("\n" +
                         CGIfWrapper(CGProxyNamedGetter(self.descriptor, templateValues),
                                     condition).define() +
                         "\n")
         else:
             namedGet = ""
 
-        return setOrIndexedGet + """JSObject* expando;
+        return setOrIndexedGet + """JS::Rooted<JSObject*> expando(cx);
 if (!isXray && (expando = GetExpandoObject(proxy))) {
   if (!JS_GetPropertyDescriptorById(cx, expando, id, flags, desc)) {
     return false;
   }
   if (desc->obj) {
     // Pretend the property lives on the wrapper.
     desc->obj = proxy;
     return true;
@@ -6796,17 +6796,17 @@ if (!AppendNamedPropertyIds(cx, proxy, n
                 "}")
             addUnforgeable = CallOnUnforgeableHolder(self.descriptor,
                                                      addUnforgeable,
                                                      "isXray")
         else:
             addUnforgeable = ""
         return """bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
 """ + addIndices + addUnforgeable + addNames + """
-JSObject* expando;
+JS::Rooted<JSObject*> expando(cx);
 if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
     !js::GetPropertyNames(cx, expando, JSITER_OWNONLY | JSITER_HIDDEN, &props)) {
   return false;
 }
 
 return true;"""
 
 class CGDOMJSProxyHandler_hasOwn(ClassMethod):
@@ -6992,35 +6992,35 @@ class CGDOMJSProxyHandler_getElementIfPr
                    "// there is an indexed getter.\n" +
                    "\n") % (self.descriptor.nativeType)
         else:
             if self.descriptor.supportsNamedProperties():
                 get = CGProxyNamedGetter(self.descriptor, templateValues,
                                          "UINT_TO_JSVAL(index)").define()
             get += """
 
-JSObject* expando = GetExpandoObject(proxy);
+JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
 if (expando) {
   JSBool isPresent;
   if (!JS_GetElementIfPresent(cx, expando, index, expando, vp.address(), &isPresent)) {
     return false;
   }
   if (isPresent) {
     *present = true;
     return true;
   }
 }
 """
 
         return """MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
              "Should not have a XrayWrapper here");
 
 """ + get + """
-JSObject *proto;
-if (!js::GetObjectProto(cx, proxy, &proto)) {
+JS::Rooted<JSObject*> proto(cx);
+if (!js::GetObjectProto(cx, proxy, proto.address())) {
   return false;
 }
 if (proto) {
   JSBool isPresent;
   if (!JS_GetElementIfPresent(cx, proto, index, proxy, vp.address(), &isPresent)) {
     return false;
   }
   *present = isPresent;
@@ -7546,23 +7546,23 @@ class CGDictionary(CGThing):
         innerTemplate = wrapForType(
             member.type, self.descriptorProvider,
             {
                 'result' : "currentValue",
                 'successCode' : ("if (!%s) {\n"
                                  "  return false;\n"
                                  "}" % propDef),
                 'jsvalRef': "temp",
-                'jsvalPtr': "&temp",
+                'jsvalPtr': "temp.address()",
                 'isCreator': False,
                 'obj': "parentObject"
             }, isMember=True)
         conversion = CGGeneric(innerTemplate)
         conversion = CGWrapper(conversion,
-                               pre=("JS::Value temp;\n"
+                               pre=("JS::Rooted<JS::Value> temp(cx);\n"
                                     "const %s& currentValue = %s;\n" %
                                     (declType.define(), memberData)
                                     ))
 
         if not member.defaultValue:
             # Only do the conversion if we have a value
             conversion = CGIfWrapper(conversion, "%s.WasPassed()" % memberLoc)
         else: