Bug 921553. Fix some binding rooting hazards that have popped up. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 30 Sep 2013 10:29:10 -0400
changeset 149273 2c7230203ec219434acc19bc5c4d9a09369da4ce
parent 149272 2963a336e7ec57d6e9d4ed3d8f6ada5805306e61
child 149274 26cdc56bad7d22331c167bbf94b68d7fc6deb978
push id25380
push userryanvm@gmail.com
push dateMon, 30 Sep 2013 20:16:36 +0000
treeherdermozilla-central@1332fc1c15e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs921553
milestone27.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 921553. Fix some binding rooting hazards that have popped up. r=peterv
dom/bindings/BindingUtils.cpp
dom/bindings/Codegen.py
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -2080,17 +2080,17 @@ NonVoidByteStringToJsval(JSContext *cx, 
     return true;
 }
 
 bool
 ConvertJSValueToByteString(JSContext* cx, JS::Handle<JS::Value> v,
                            JS::MutableHandle<JS::Value> pval, bool nullable,
                            nsACString& result)
 {
-  JSString *s;
+  JS::Rooted<JSString*> s(cx);
   if (v.isString()) {
     s = v.toString();
   } else {
 
     if (nullable && v.isNullOrUndefined()) {
       result.SetIsVoid(true);
       return true;
     }
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -6146,28 +6146,34 @@ def getUnionTypeTemplateVars(unionType, 
                     "mUnion.mType = mUnion.eObject;")
         setter = ClassMethod("SetToObject", "void",
                              [Argument("JSContext*", "cx"),
                               Argument("JSObject*", "obj")],
                              inline=True, bodyInHeader=True,
                              body=body)
 
     else:
+        # Important: we need to not have our declName involve
+        # maybe-GCing operations.
         jsConversion = string.Template(conversionInfo.template).substitute(
             {
                 "val": "value",
                 "mutableVal": "pvalue",
-                "declName": "SetAs" + name + "(%s)" % ctorArgs,
+                "declName": "memberSlot",
                 "holderName": "m" + name + "Holder",
                 }
             )
-        jsConversion = CGWrapper(CGGeneric(jsConversion),
-                                 pre="tryNext = false;\n",
-                                 post="\n"
-                                      "return true;")
+        jsConversion = CGWrapper(CGIndenter(CGGeneric(jsConversion)),
+                                 pre=("tryNext = false;\n"
+                                      "{ // scope for memberSlot\n"
+                                      "  %s& memberSlot = SetAs%s(%s);\n"
+                                      % (structType, name, ctorArgs)),
+                                 post=("\n"
+                                       "}\n"
+                                      "return true;"))
         setter = ClassMethod("TrySetTo" + name, "bool",
                               [Argument("JSContext*", "cx"),
                                Argument("JS::Handle<JS::Value>", "value"),
                                Argument("JS::MutableHandle<JS::Value>", "pvalue"),
                                Argument("bool&", "tryNext")],
                               inline=not ownsMembers,
                               bodyInHeader=not ownsMembers,
                               body=jsConversion.define())