Bug 678998 - Rename IsFunctionQName to GetLocalNameFromFunctionQName and make it infallible, now that QName's localName slot stores an atom and conversion to jsid can be infallible. r=luke
authorJeff Walden <jwalden@mit.edu>
Mon, 15 Aug 2011 00:12:48 -0400
changeset 75296 c36563ee6447afd04561b1ba9f30e740c43261b8
parent 75295 c6a3b64dcac076dbca8ad87ff165be85d6fd3da2
child 75297 edead6fe5c9514e39cff0fc5b5bd9bef54406760
push id1224
push userjwalden@mit.edu
push dateMon, 15 Aug 2011 19:43:03 +0000
treeherdermozilla-inbound@c36563ee6447 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs678998
milestone8.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 678998 - Rename IsFunctionQName to GetLocalNameFromFunctionQName and make it infallible, now that QName's localName slot stores an atom and conversion to jsid can be infallible. r=luke
js/src/jsatom.cpp
js/src/jsinterp.cpp
js/src/jsxml.cpp
js/src/jsxml.h
--- a/js/src/jsatom.cpp
+++ b/js/src/jsatom.cpp
@@ -769,19 +769,17 @@ js_InternNonIntElementIdSlow(JSContext *
                              jsid *idp)
 {
     JS_ASSERT(idval.isObject());
     if (obj->isXML()) {
         *idp = OBJECT_TO_JSID(&idval.toObject());
         return true;
     }
 
-    if (!js_IsFunctionQName(cx, &idval.toObject(), idp))
-        return JS_FALSE;
-    if (!JSID_IS_VOID(*idp))
+    if (js_GetLocalNameFromFunctionQName(&idval.toObject(), idp, cx))
         return true;
 
     return js_ValueToStringId(cx, idval, idp);
 }
 
 bool
 js_InternNonIntElementIdSlow(JSContext *cx, JSObject *obj, const Value &idval,
                              jsid *idp, Value *vp)
@@ -789,19 +787,17 @@ js_InternNonIntElementIdSlow(JSContext *
     JS_ASSERT(idval.isObject());
     if (obj->isXML()) {
         JSObject &idobj = idval.toObject();
         *idp = OBJECT_TO_JSID(&idobj);
         vp->setObject(idobj);
         return true;
     }
 
-    if (!js_IsFunctionQName(cx, &idval.toObject(), idp))
-        return JS_FALSE;
-    if (!JSID_IS_VOID(*idp)) {
+    if (js_GetLocalNameFromFunctionQName(&idval.toObject(), idp, cx)) {
         *vp = IdToValue(*idp);
         return true;
     }
 
     if (js_ValueToStringId(cx, idval, idp)) {
         vp->setString(JSID_TO_STRING(*idp));
         return true;
     }
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -533,19 +533,17 @@ js_OnUnknownMethod(JSContext *cx, Value 
         return false;
     if (tvr.value().isPrimitive()) {
         vp[0] = tvr.value();
     } else {
 #if JS_HAS_XML_SUPPORT
         /* Extract the function name from function::name qname. */
         if (vp[0].isObject()) {
             obj = &vp[0].toObject();
-            if (!js_IsFunctionQName(cx, obj, &id))
-                return false;
-            if (!JSID_IS_VOID(id))
+            if (js_GetLocalNameFromFunctionQName(obj, &id, cx))
                 vp[0] = IdToValue(id);
         }
 #endif
         obj = js_NewGCObject(cx, FINALIZE_OBJECT2);
         if (!obj)
             return false;
 
         obj->init(cx, &js_NoSuchMethodClass, NULL, NULL, NULL, false);
--- a/js/src/jsxml.cpp
+++ b/js/src/jsxml.cpp
@@ -2807,36 +2807,34 @@ ToAttributeName(JSContext *cx, jsval v)
 }
 
 static void
 ReportBadXMLName(JSContext *cx, const Value &idval)
 {
     js_ReportValueError(cx, JSMSG_BAD_XML_NAME, JSDVG_IGNORE_STACK, idval, NULL);
 }
 
-static JSBool
-IsFunctionQName(JSContext *cx, JSObject *qn, jsid *funidp)
+static bool
+GetLocalNameFromFunctionQName(JSObject *qn, jsid *funidp, JSContext *cx)
 {
     JSAtom *atom = cx->runtime->atomState.functionNamespaceURIAtom;
     JSLinearString *uri = qn->getNameURI();
     if (uri && (uri == atom || EqualStrings(uri, atom))) {
         *funidp = ATOM_TO_JSID(qn->getQNameLocalName());
         return true;
     }
-    *funidp = JSID_VOID;
-    return true;
-}
-
-JSBool
-js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp)
-{
-    if (obj->getClass() == &js_QNameClass)
-        return IsFunctionQName(cx, obj, funidp);
-    *funidp = JSID_VOID;
-    return JS_TRUE;
+    return false;
+}
+
+bool
+js_GetLocalNameFromFunctionQName(JSObject *obj, jsid *funidp, JSContext *cx)
+{
+    if (!obj->isQName())
+        return false;
+    return GetLocalNameFromFunctionQName(obj, funidp, cx);
 }
 
 static JSObject *
 ToXMLName(JSContext *cx, jsval v, jsid *funidp)
 {
     JSAtom *atomizedName;
     JSString *name;
     JSObject *obj;
@@ -2894,18 +2892,18 @@ ToXMLName(JSContext *cx, jsval v, jsid *
 
 construct:
     v = STRING_TO_JSVAL(name);
     obj = js_ConstructObject(cx, &js_QNameClass, NULL, NULL, 1, Valueify(&v));
     if (!obj)
         return NULL;
 
 out:
-    if (!IsFunctionQName(cx, obj, funidp))
-        return NULL;
+    if (!GetLocalNameFromFunctionQName(obj, funidp, cx))
+        *funidp = JSID_VOID;
     return obj;
 
 bad:
     JSAutoByteString bytes;
     if (js_ValueToPrintable(cx, StringValue(name), &bytes))
         JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_XML_NAME, bytes.ptr());
     return NULL;
 }
@@ -4974,24 +4972,18 @@ again:
 /*
  * 11.2.2.1 Step 3(d) onward.
  */
 JSBool
 js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, Value *vp)
 {
     JS_ASSERT(obj->isXML());
 
-    if (JSID_IS_OBJECT(id)) {
-        jsid funid;
-
-        if (!js_IsFunctionQName(cx, JSID_TO_OBJECT(id), &funid))
-            return JS_FALSE;
-        if (!JSID_IS_VOID(funid))
-            id = funid;
-    }
+    if (JSID_IS_OBJECT(id))
+        js_GetLocalNameFromFunctionQName(JSID_TO_OBJECT(id), &id, cx);
 
     /*
      * As our callers have a bad habit of passing a pointer to an unrooted
      * local value as vp, we use a proper root here.
      */
     AutoValueRooter tvr(cx);
     JSBool ok = GetXMLFunction(cx, obj, id, Jsvalify(tvr.addr()));
     *vp = tvr.value();
@@ -7442,18 +7434,18 @@ js_FindXMLProperty(JSContext *cx, const 
         if (!nameobj)
             return JS_FALSE;
     } else {
         JS_ASSERT(nameobj->getClass() == &js_AttributeNameClass ||
                   nameobj->getClass() == &js_QNameClass);
     }
 
     qn = nameobj;
-    if (!IsFunctionQName(cx, qn, &funid))
-        return JS_FALSE;
+    if (!GetLocalNameFromFunctionQName(qn, &funid, cx))
+        funid = JSID_VOID;
 
     obj = &js_GetTopStackFrame(cx)->scopeChain();
     do {
         /* Skip any With object that can wrap XML. */
         target = obj;
         while (target->getClass() == &js_WithClass) {
              proto = target->getProto();
              if (!proto)
--- a/js/src/jsxml.h
+++ b/js/src/jsxml.h
@@ -275,21 +275,21 @@ js_InitQNameClass(JSContext *cx, JSObjec
 
 extern JSObject *
 js_InitXMLClass(JSContext *cx, JSObject *obj);
 
 extern JSObject *
 js_InitXMLClasses(JSContext *cx, JSObject *obj);
 
 /*
- * If obj is QName corresponding to function::name, set *funidp to name's id,
- * otherwise set *funidp to void.
+ * If obj is a QName corresponding to function::name, set *funidp to name's id
+ * and return true, else return false.
  */
-JSBool
-js_IsFunctionQName(JSContext *cx, JSObject *obj, jsid *funidp);
+extern bool
+js_GetLocalNameFromFunctionQName(JSObject *obj, jsid *funidp, JSContext *cx);
 
 extern JSBool
 js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp);
 
 extern JSBool
 js_SetDefaultXMLNamespace(JSContext *cx, const js::Value &v);
 
 /*