Bug 771378 (part 2) - Remove use of MUST_FLOW_THROUGH from jsxml.cpp. r=jwalden.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 17 Jul 2012 16:40:21 -0700
changeset 99592 0b273f6a04af2e0dae8cfcbbedfd8b1e19ad2995
parent 99591 6d030947dffea35e52ba30a631e787a0d0186b86
child 99593 02416efff4af5a6e3217f9be643bc38734982a87
push id12084
push usernnethercote@mozilla.com
push dateWed, 18 Jul 2012 00:09:27 +0000
treeherdermozilla-inbound@02416efff4af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs771378
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 771378 (part 2) - Remove use of MUST_FLOW_THROUGH from jsxml.cpp. r=jwalden.
js/src/jsxml.cpp
--- a/js/src/jsxml.cpp
+++ b/js/src/jsxml.cpp
@@ -79,37 +79,16 @@ pointer_match(const T *a, const T *b)
  *
  * TODO
  * - XXXbe patrol
  * - Fuse objects and their JSXML* private data into single GC-things
  * - fix function::foo vs. x.(foo == 42) collision using proper namespacing
  * - JSCLASS_DOCUMENT_OBSERVER support -- live two-way binding to Gecko's DOM!
  */
 
-static inline bool
-js_EnterLocalRootScope(JSContext *cx)
-{
-    return true;
-}
-
-static inline void
-js_LeaveLocalRootScope(JSContext *cx)
-{
-}
-
-static inline void
-js_LeaveLocalRootScopeWithResult(JSContext *cx, Value rval)
-{
-}
-
-static inline void
-js_LeaveLocalRootScopeWithResult(JSContext *cx, void *rval)
-{
-}
-
 /*
  * Random utilities and global functions.
  */
 const char js_AttributeName_str[] = "AttributeName";
 const char js_localName_str[]     = "localName";
 const char js_xml_parent_str[]    = "parent";
 const char js_prefix_str[]        = "prefix";
 const char js_toXMLString_str[]   = "toXMLString";
@@ -1338,18 +1317,16 @@ ParseNodeToXML(Parser *parser, ParseNode
 #define PN2X_SKIP_CHILD ((JSXML *) 1)
 
     /*
      * Cases return early to avoid common code that gets an outermost xml's
      * object, which protects GC-things owned by xml and its descendants from
      * garbage collection.
      */
     xml = NULL;
-    if (!js_EnterLocalRootScope(cx))
-        return NULL;
     switch (pn->getKind()) {
       case PNK_XMLELEM:
         length = inScopeNSes->length;
         pn2 = pn->pn_head;
         xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags);
         if (!xml)
             goto fail;
 
@@ -1633,29 +1610,26 @@ ParseNodeToXML(Parser *parser, ParseNode
             xml->xml_flags |= XMLF_WHITESPACE_TEXT;
         xml->xml_value = str;
         break;
 
       default:
         goto syntax;
     }
 
-    js_LeaveLocalRootScopeWithResult(cx, xml);
     return xml;
 
 skip_child:
-    js_LeaveLocalRootScope(cx);
     return PN2X_SKIP_CHILD;
 
 #undef PN2X_SKIP_CHILD
 
 syntax:
     parser->reportError(pn, JSMSG_BAD_XML_MARKUP);
 fail:
-    js_LeaveLocalRootScope(cx);
     return NULL;
 }
 
 /*
  * XML helper, object-ops, and library functions.  We start with the helpers,
  * in ECMA-357 order, but merging XML (9.1) and XMLList (9.2) helpers.
  */
 static JSBool
@@ -1972,40 +1946,34 @@ ToXMLList(JSContext *cx, jsval v)
 
     str = ToString(cx, v);
     if (!str)
         return NULL;
     if (str->empty()) {
         xml = NULL;
         length = 0;
     } else {
-        if (!js_EnterLocalRootScope(cx))
+        xml = ParseXMLSource(cx, str);
+        if (!xml)
             return NULL;
-        xml = ParseXMLSource(cx, str);
-        if (!xml) {
-            js_LeaveLocalRootScope(cx);
-            return NULL;
-        }
         length = JSXML_LENGTH(xml);
     }
 
     listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
     if (listobj) {
         list = (JSXML *) listobj->getPrivate();
         for (i = 0; i < length; i++) {
             kid = OrphanXMLChild(cx, xml, i);
             if (!kid || !Append(cx, list, kid)) {
                 listobj = NULL;
                 break;
             }
         }
     }
 
-    if (xml)
-        js_LeaveLocalRootScopeWithResult(cx, listobj);
     return listobj;
 
 bad:
     js_ReportValueError(cx, JSMSG_BAD_XMLLIST_CONVERSION,
                         JSDVG_IGNORE_STACK, v, NULL);
     return NULL;
 }
 
@@ -2476,20 +2444,16 @@ XMLToXMLString(JSContext *cx, JSXML *xml
 
         if (sb.empty())
             return cx->runtime->emptyString;
         return sb.finishString();
 
       default:;
     }
 
-    /* After this point, control must flow through label out: to exit. */
-    if (!js_EnterLocalRootScope(cx))
-        return NULL;
-
     /* ECMA-357 10.2.1 step 8 onward: handle ToXMLString on an XML element. */
     if (!ancestorNSes) {
         // Ensure a namespace with empty strings exists in the initial array,
         // otherwise every call to GetNamespace() when running toString() on
         // an XML object with no namespace defined will create a new Namespace
         // object on every call.
         JSObject *emptyns = NewXMLNamespace(cx, cx->runtime->emptyString, cx->runtime->emptyString, JS_FALSE);
         if (!emptyns || !XMLARRAY_APPEND(cx, &empty.array, emptyns))
@@ -2760,17 +2724,16 @@ XMLToXMLString(JSContext *cx, JSXML *xml
 
         /* Step 27. */
         if (!sb.append(xml->name->getQNameLocalName()) || !sb.append('>'))
             goto out;
     }
 
     str = sb.finishString();
 out:
-    js_LeaveLocalRootScopeWithResult(cx, str);
     return str;
 }
 
 /* ECMA-357 10.2 */
 static JSString *
 ToXMLString(JSContext *cx, jsval v, uint32_t toSourceFlag)
 {
     if (JSVAL_IS_NULL(v) || JSVAL_IS_VOID(v)) {
@@ -3061,30 +3024,26 @@ Append(JSContext *cx, JSXML *list, JSXML
 static JSXML *
 DeepCopyInLRS(JSContext *cx, JSXML *xml, unsigned flags);
 
 static JSXML *
 DeepCopy(JSContext *cx, JSXML *xml, JSObject *obj, unsigned flags)
 {
     JSXML *copy;
 
-    /* Our caller may not be protecting newborns with a local root scope. */
-    if (!js_EnterLocalRootScope(cx))
-        return NULL;
     copy = DeepCopyInLRS(cx, xml, flags);
     if (copy) {
         if (obj) {
             /* Caller provided the object for this copy, hook 'em up. */
             obj->setPrivate(copy);
             copy->object = obj;
         } else if (!js_GetXMLObject(cx, copy)) {
             copy = NULL;
         }
     }
-    js_LeaveLocalRootScopeWithResult(cx, copy);
     return copy;
 }
 
 /*
  * (i) We must be in a local root scope (InLRS).
  * (ii) parent must have a rooted object.
  * (iii) from's owning object must be locked if not thread-local.
  */
@@ -3311,32 +3270,29 @@ Descendants(JSContext *cx, JSXML *xml, j
 
     /*
      * Protect nameqn's object and strings from GC by linking list to it
      * temporarily.  The newborn GC root for the last allocated object
      * protects listobj, which protects list. Any other object allocations
      * occurring beneath DescendantsHelper use local roots.
      */
     list->name = nameqn;
-    if (!js_EnterLocalRootScope(cx))
-        return NULL;
     if (xml->xml_class == JSXML_CLASS_LIST) {
         ok = JS_TRUE;
         for (i = 0, n = xml->xml_kids.length; i < n; i++) {
             kid = XMLARRAY_MEMBER(&xml->xml_kids, i, JSXML);
             if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
                 ok = DescendantsHelper(cx, kid, nameqn, list);
                 if (!ok)
                     break;
             }
         }
     } else {
         ok = DescendantsHelper(cx, xml, nameqn, list);
     }
-    js_LeaveLocalRootScopeWithResult(cx, list);
     if (!ok)
         return NULL;
     list->name = NULL;
     return list;
 }
 
 /* Recursive (JSXML *) parameterized version of Equals. */
 static JSBool
@@ -3900,21 +3856,18 @@ PutProperty(JSContext *cx, HandleObject 
     /* Precompute vxml for 9.2.1.2 2(c)(vii)(2-3) and 2(d) and 9.1.1.2 1. */
     vxml = NULL;
     if (!JSVAL_IS_PRIMITIVE(*vp)) {
         vobj = JSVAL_TO_OBJECT(*vp);
         if (vobj->isXML())
             vxml = (JSXML *) vobj->getPrivate();
     }
 
-    ok = js_EnterLocalRootScope(cx);
-    if (!ok)
-        return JS_FALSE;
-
-    MUST_FLOW_THROUGH("out");
+    ok = JS_TRUE;
+
     jsval roots[3];
     roots[OBJ_ROOT] = OBJECT_TO_JSVAL(obj);
     roots[ID_ROOT] = IdToJsval(id);
     roots[VAL_ROOT] = *vp;
     AutoArrayRooter tvr(cx, ArrayLength(roots), roots);
 
     if (js_IdIsIndex(id, &index)) {
         if (xml->xml_class != JSXML_CLASS_LIST) {
@@ -4498,17 +4451,16 @@ PutProperty(JSContext *cx, HandleObject 
             }
         } else {
             /* 15(a). */
             ok = Replace(cx, xml, matchIndex, *vp);
         }
     }
 
 out:
-    js_LeaveLocalRootScope(cx);
     return ok;
 
 type_error:
     {
         JSAutoByteString bytes;
         if (js_ValueToPrintable(cx, IdToValue(id), &bytes))
             JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_XMLLIST_PUT, bytes.ptr());
     }
@@ -5272,80 +5224,70 @@ js_TestXMLEquality(JSContext *cx, const 
         if (vxml->xml_class == JSXML_CLASS_LIST) {
             ok = Equals(cx, vxml, OBJECT_TO_JSVAL(obj), bp);
         } else {
             if (((xml->xml_class == JSXML_CLASS_TEXT ||
                   xml->xml_class == JSXML_CLASS_ATTRIBUTE) &&
                  HasSimpleContent(vxml)) ||
                 ((vxml->xml_class == JSXML_CLASS_TEXT ||
                   vxml->xml_class == JSXML_CLASS_ATTRIBUTE) &&
-                 HasSimpleContent(xml))) {
-                ok = js_EnterLocalRootScope(cx);
+                 HasSimpleContent(xml)))
+            {
+                ok = (str = ToStringSlow(cx, ObjectValue(*obj))) &&
+                     (vstr = ToString(cx, v));
                 if (ok) {
-                    ok = (str = ToStringSlow(cx, ObjectValue(*obj))) &&
-                         (vstr = ToString(cx, v));
-                    if (ok) {
-                        bool equal;
-                        ok = EqualStrings(cx, str, vstr, &equal);
-                        *bp = equal;
-                    }
-                    js_LeaveLocalRootScope(cx);
+                    bool equal;
+                    ok = EqualStrings(cx, str, vstr, &equal);
+                    *bp = equal;
                 }
             } else {
                 ok = XMLEquals(cx, xml, vxml, bp);
             }
         }
     } else {
-        ok = js_EnterLocalRootScope(cx);
-        if (ok) {
-            if (HasSimpleContent(xml)) {
-                ok = (str = ToString(cx, ObjectValue(*obj))) &&
-                     (vstr = ToString(cx, v));
+        if (HasSimpleContent(xml)) {
+            ok = (str = ToString(cx, ObjectValue(*obj))) &&
+                 (vstr = ToString(cx, v));
+            if (ok) {
+                bool equal;
+                ok = EqualStrings(cx, str, vstr, &equal);
+                *bp = equal;
+            }
+        } else if (JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v)) {
+            str = ToString(cx, ObjectValue(*obj));
+            if (!str) {
+                ok = JS_FALSE;
+            } else if (JSVAL_IS_STRING(v)) {
+                bool equal;
+                ok = EqualStrings(cx, str, JSVAL_TO_STRING(v), &equal);
+                if (ok)
+                    *bp = equal;
+            } else {
+                ok = JS_ValueToNumber(cx, STRING_TO_JSVAL(str), &d);
                 if (ok) {
-                    bool equal;
-                    ok = EqualStrings(cx, str, vstr, &equal);
-                    *bp = equal;
+                    d2 = JSVAL_IS_INT(v) ? JSVAL_TO_INT(v)
+                                         : JSVAL_TO_DOUBLE(v);
+                    *bp = (d == d2);
                 }
-            } else if (JSVAL_IS_STRING(v) || JSVAL_IS_NUMBER(v)) {
-                str = ToString(cx, ObjectValue(*obj));
-                if (!str) {
-                    ok = JS_FALSE;
-                } else if (JSVAL_IS_STRING(v)) {
-                    bool equal;
-                    ok = EqualStrings(cx, str, JSVAL_TO_STRING(v), &equal);
-                    if (ok)
-                        *bp = equal;
-                } else {
-                    ok = JS_ValueToNumber(cx, STRING_TO_JSVAL(str), &d);
-                    if (ok) {
-                        d2 = JSVAL_IS_INT(v) ? JSVAL_TO_INT(v)
-                                             : JSVAL_TO_DOUBLE(v);
-                        *bp = (d == d2);
-                    }
-                }
-            } else {
-                *bp = JS_FALSE;
             }
-            js_LeaveLocalRootScope(cx);
+        } else {
+            *bp = JS_FALSE;
         }
     }
     return ok;
 }
 
 JSBool
 js_ConcatenateXML(JSContext *cx, JSObject *obj, JSObject *robj, Value *vp)
 {
     JSBool ok;
     JSObject *listobj;
     JSXML *list, *lxml, *rxml;
 
     JS_ASSERT(obj->isXML());
-    ok = js_EnterLocalRootScope(cx);
-    if (!ok)
-        return JS_FALSE;
 
     listobj = js_NewXMLObject(cx, JSXML_CLASS_LIST);
     if (!listobj) {
         ok = JS_FALSE;
         goto out;
     }
 
     list = (JSXML *) listobj->getPrivate();
@@ -5357,17 +5299,16 @@ js_ConcatenateXML(JSContext *cx, JSObjec
     JS_ASSERT(robj->isXML());
     rxml = (JSXML *) robj->getPrivate();
     ok = Append(cx, list, rxml);
     if (!ok)
         goto out;
 
     vp->setObject(*listobj);
 out:
-    js_LeaveLocalRootScopeWithResult(cx, *vp);
     return ok;
 }
 
 JS_FRIEND_DATA(Class) js::XMLClass = {
     js_XML_str,
     JSCLASS_HAS_PRIVATE | JSCLASS_IMPLEMENTS_BARRIERS |
     JSCLASS_HAS_CACHED_PROTO(JSProto_XML),
     JS_PropertyStub,         /* addProperty */
@@ -5757,27 +5698,23 @@ xml_comments_helper(JSContext *cx, JSObj
 
     ok = JS_TRUE;
 
     if (xml->xml_class == JSXML_CLASS_LIST) {
         /* 13.5.4.6 Step 2. */
         for (i = 0, n = JSXML_LENGTH(xml); i < n; i++) {
             kid = XMLARRAY_MEMBER(&xml->xml_kids, i, JSXML);
             if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
-                ok = js_EnterLocalRootScope(cx);
-                if (!ok)
-                    break;
                 kidobj = js_GetXMLObject(cx, kid);
                 if (kidobj) {
                     ok = xml_comments_helper(cx, kidobj, kid, &v);
                 } else {
                     ok = JS_FALSE;
                     v = JSVAL_NULL;
                 }
-                js_LeaveLocalRootScopeWithResult(cx, v);
                 if (!ok)
                     break;
                 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
                 if (JSXML_LENGTH(vxml) != 0) {
                     ok = Append(cx, list, vxml);
                     if (!ok)
                         break;
                 }
@@ -5881,27 +5818,23 @@ xml_elements_helper(JSContext *cx, JSObj
     list->xml_targetprop = nameqn;
     ok = JS_TRUE;
 
     if (xml->xml_class == JSXML_CLASS_LIST) {
         /* 13.5.4.6 */
         JSXMLArrayCursor<JSXML> cursor(&xml->xml_kids);
         while (JSXML *kid = cursor.getNext()) {
             if (kid->xml_class == JSXML_CLASS_ELEMENT) {
-                ok = js_EnterLocalRootScope(cx);
-                if (!ok)
-                    break;
                 kidobj = js_GetXMLObject(cx, kid);
                 if (kidobj) {
                     ok = xml_elements_helper(cx, kidobj, kid, nameqn, &v);
                 } else {
                     ok = JS_FALSE;
                     v = JSVAL_NULL;
                 }
-                js_LeaveLocalRootScopeWithResult(cx, v);
                 if (!ok)
                     break;
                 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
                 if (JSXML_LENGTH(vxml) != 0) {
                     ok = Append(cx, list, vxml);
                     if (!ok)
                         break;
                 }
@@ -6429,28 +6362,24 @@ xml_processingInstructions_helper(JSCont
     list->xml_targetprop = nameqn;
     ok = JS_TRUE;
 
     if (xml->xml_class == JSXML_CLASS_LIST) {
         /* 13.5.4.17 Step 4 (misnumbered 9 -- Erratum?). */
         JSXMLArrayCursor<JSXML> cursor(&xml->xml_kids);
         while (JSXML *kid = cursor.getNext()) {
             if (kid->xml_class == JSXML_CLASS_ELEMENT) {
-                ok = js_EnterLocalRootScope(cx);
-                if (!ok)
-                    break;
                 kidobj = js_GetXMLObject(cx, kid);
                 if (kidobj) {
                     ok = xml_processingInstructions_helper(cx, kidobj, kid,
                                                            nameqn, &v);
                 } else {
                     ok = JS_FALSE;
                     v = JSVAL_NULL;
                 }
-                js_LeaveLocalRootScopeWithResult(cx, v);
                 if (!ok)
                     break;
                 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
                 if (JSXML_LENGTH(vxml) != 0) {
                     ok = Append(cx, list, vxml);
                     if (!ok)
                         break;
                 }
@@ -6923,27 +6852,24 @@ xml_text_helper(JSContext *cx, JSObject 
     list = xml_list_helper(cx, xml, vp);
     if (!list)
         return JS_FALSE;
 
     if (xml->xml_class == JSXML_CLASS_LIST) {
         for (i = 0, n = xml->xml_kids.length; i < n; i++) {
             kid = XMLARRAY_MEMBER(&xml->xml_kids, i, JSXML);
             if (kid && kid->xml_class == JSXML_CLASS_ELEMENT) {
-                JSBool ok = js_EnterLocalRootScope(cx);
-                if (!ok)
-                    break;
+                JSBool ok;
                 kidobj = js_GetXMLObject(cx, kid);
                 if (kidobj) {
                     ok = xml_text_helper(cx, kidobj, kid, &v);
                 } else {
                     ok = JS_FALSE;
                     v = JSVAL_NULL;
                 }
-                js_LeaveLocalRootScopeWithResult(cx, v);
                 if (!ok)
                     return JS_FALSE;
                 vxml = (JSXML *) JSVAL_TO_OBJECT(v)->getPrivate();
                 if (JSXML_LENGTH(vxml) != 0 && !Append(cx, list, vxml))
                     return JS_FALSE;
             }
         }
     } else {
@@ -6973,33 +6899,30 @@ xml_toString_helper(JSContext *cx, JSXML
         xml->xml_class == JSXML_CLASS_TEXT) {
         return xml->xml_value;
     }
 
     if (!HasSimpleContent(xml))
         return ToXMLString(cx, OBJECT_TO_JSVAL(xml->object), 0);
 
     RootedString str(cx, cx->runtime->emptyString);
-    if (!js_EnterLocalRootScope(cx))
-        return NULL;
     JSXMLArrayCursor<JSXML> cursor(&xml->xml_kids);
     while (JSXML *kid = cursor.getNext()) {
         if (kid->xml_class != JSXML_CLASS_COMMENT &&
             kid->xml_class != JSXML_CLASS_PROCESSING_INSTRUCTION) {
             RootedString kidstr(cx, xml_toString_helper(cx, kid));
             if (!kidstr) {
                 str = NULL;
                 break;
             }
             str = js_ConcatStrings(cx, str, kidstr);
             if (!str)
                 break;
         }
     }
-    js_LeaveLocalRootScopeWithResult(cx, str);
     return str;
 }
 
 static JSBool
 xml_toSource(JSContext *cx, unsigned argc, jsval *vp)
 {
     JSObject *obj = ToObject(cx, &vp[1]);
     if (!obj)