Bug 765341 - Change js_ValueToAtom to return a JSAtom* directly, and rename it to js::ToAtom. r=sfink

--HG--
extra : rebase_source : 44f039cd09ac2ab1825e7f9fd1e2a01f5907bb67
This commit is contained in:
Jeff Walden 2012-06-12 16:03:10 -07:00
parent 695d880981
commit f63db7ff7f
9 changed files with 39 additions and 35 deletions

View File

@ -5778,8 +5778,8 @@ Parser::memberExpr(JSBool allowCallSyntax)
name = atom->asPropertyName();
}
} else if (propExpr->isKind(PNK_NUMBER)) {
JSAtom *atom;
if (!js_ValueToAtom(context, NumberValue(propExpr->pn_dval), &atom))
JSAtom *atom = ToAtom(context, NumberValue(propExpr->pn_dval));
if (!atom)
return NULL;
if (!atom->isIndex(&index))
name = atom->asPropertyName();
@ -6789,7 +6789,8 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (!pn3)
return NULL;
pn3->pn_dval = tokenStream.currentToken().number();
if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom))
atom = ToAtom(context, DoubleValue(pn3->pn_dval));
if (!atom)
return NULL;
break;
case TOK_NAME:
@ -6822,7 +6823,8 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (!pn3)
return NULL;
pn3->pn_dval = index;
if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom))
atom = ToAtom(context, DoubleValue(pn3->pn_dval));
if (!atom)
return NULL;
} else {
pn3 = NameNode::create(PNK_STRING, atom, this, this->tc->sc);
@ -6834,7 +6836,8 @@ Parser::primaryExpr(TokenKind tt, bool afterDoubleDot)
if (!pn3)
return NULL;
pn3->pn_dval = tokenStream.currentToken().number();
if (!js_ValueToAtom(context, DoubleValue(pn3->pn_dval), &atom))
atom = ToAtom(context, DoubleValue(pn3->pn_dval));
if (!atom)
return NULL;
} else {
tokenStream.ungetToken();

View File

@ -837,8 +837,8 @@ array_getGeneric(JSContext *cx, HandleObject obj, HandleObject receiver, HandleI
if (ValueIsSpecial(obj, &idval, &sid, cx))
return array_getSpecial(cx, obj, receiver, Rooted<SpecialId>(cx, sid), vp);
JSAtom *atom;
if (!js_ValueToAtom(cx, idval, &atom))
JSAtom *atom = ToAtom(cx, idval);
if (!atom)
return false;
if (atom->isIndex(&index))

View File

@ -522,8 +522,8 @@ InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
}
#endif
JSAtom *atom;
if (!js_ValueToAtom(cx, idval, &atom))
JSAtom *atom = ToAtom(cx, idval);
if (!atom)
return false;
*idp = AtomToId(atom);

View File

@ -410,11 +410,11 @@ js_DumpAtoms(JSContext *cx, FILE *fp);
#endif
inline bool
js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp);
namespace js {
inline JSAtom *
ToAtom(JSContext *cx, const js::Value &v);
bool
InternNonIntElementId(JSContext *cx, JSObject *obj, const Value &idval,
jsid *idp, Value *vp);

View File

@ -24,30 +24,27 @@ js::AtomStateEntry::asPtr() const
return atom;
}
inline bool
js_ValueToAtom(JSContext *cx, const js::Value &v, JSAtom **atomp)
namespace js {
inline JSAtom *
ToAtom(JSContext *cx, const js::Value &v)
{
if (!v.isString()) {
JSString *str = js::ToStringSlow(cx, v);
if (!str)
return false;
return NULL;
JS::Anchor<JSString *> anchor(str);
*atomp = js_AtomizeString(cx, str);
return !!*atomp;
return js_AtomizeString(cx, str);
}
JSString *str = v.toString();
if (str->isAtom()) {
*atomp = &str->asAtom();
return true;
}
if (str->isAtom())
return &str->asAtom();
*atomp = js_AtomizeString(cx, str);
return !!*atomp;
JS::Anchor<JSString *> anchor(str);
return js_AtomizeString(cx, str);
}
namespace js {
inline bool
ValueToId(JSContext* cx, JSObject *obj, const Value &v, jsid *idp)
{

View File

@ -635,8 +635,8 @@ GetObjectElementOperation(JSContext *cx, JSOp op, HandleObject obj, const Value
if (!obj->getSpecial(cx, obj, special, res))
return false;
} else {
JSAtom *name;
if (!js_ValueToAtom(cx, *res, &name))
JSAtom *name = ToAtom(cx, *res);
if (!name)
return false;
if (name->isIndex(&index)) {

View File

@ -3179,8 +3179,8 @@ JSObject::deleteByValue(JSContext *cx, const Value &property, Value *rval, bool
RootedObject self(cx, this);
JSAtom *name;
if (!js_ValueToAtom(cx, propval, &name))
JSAtom *name = ToAtom(cx, propval);
if (!name)
return false;
if (name->isIndex(&index))

View File

@ -1110,8 +1110,8 @@ class TypedArrayTemplate
if (ValueIsSpecial(obj, &idval, &sid, cx))
return obj_getSpecial(cx, obj, receiver, Rooted<SpecialId>(cx, sid), vp);
JSAtom *atom;
if (!js_ValueToAtom(cx, idval, &atom))
JSAtom *atom = ToAtom(cx, idval);
if (!atom)
return false;
if (atom->isIndex(&index))

View File

@ -761,7 +761,8 @@ QNameHelper(JSContext *cx, int argc, jsval *argv, jsval *rval)
} else if (argc < 0) {
name = cx->runtime->atomState.typeAtoms[JSTYPE_VOID];
} else {
if (!js_ValueToAtom(cx, nameval, &name))
name = ToAtom(cx, nameval);
if (!name)
return false;
}
@ -2828,7 +2829,8 @@ ToAttributeName(JSContext *cx, jsval v)
JSAtom *name;
if (JSVAL_IS_STRING(v)) {
if (!js_ValueToAtom(cx, v, &name))
name = ToAtom(cx, v);
if (!name)
return NULL;
uri = prefix = cx->runtime->emptyString;
} else {
@ -2852,7 +2854,8 @@ ToAttributeName(JSContext *cx, jsval v)
if (clasp == &AnyNameClass) {
name = cx->runtime->atomState.starAtom;
} else {
if (!js_ValueToAtom(cx, v, &name))
name = ToAtom(cx, v);
if (!name)
return NULL;
}
uri = prefix = cx->runtime->emptyString;
@ -6705,7 +6708,8 @@ xml_setLocalName(JSContext *cx, unsigned argc, jsval *vp)
if (!JSVAL_IS_PRIMITIVE(name) && JSVAL_TO_OBJECT(name)->isQName()) {
namestr = JSVAL_TO_OBJECT(name)->getQNameLocalName();
} else {
if (!js_ValueToAtom(cx, name, &namestr))
namestr = ToAtom(cx, name);
if (!namestr)
return false;
}
}