Bug 720759 - Convert js::SameValue, js::StrictlyEqual, js::LooselyEqual, and js::EqualStrings to return a value through a bool*, not a JSBool*, to eliminate a (single!) Windows warning. r=Ms2ger

This commit is contained in:
Jeff Walden 2012-01-24 10:29:55 -08:00
parent c9140c221f
commit 41a1ee8186
11 changed files with 88 additions and 52 deletions

View File

@ -138,7 +138,7 @@ HashableValue::equals(const HashableValue &other) const
&other.value.toString()->asLinear()));
#ifdef DEBUG
JSBool same;
bool same;
JS_ASSERT(SameValue(NULL, value, other.value, &same));
JS_ASSERT(same == b);
#endif

View File

@ -640,7 +640,11 @@ JS_StrictlyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal)
AssertNoGC(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, v1, v2);
return StrictlyEqual(cx, v1, v2, equal);
bool eq;
if (!StrictlyEqual(cx, v1, v2, &eq))
return false;
*equal = eq;
return true;
}
JS_PUBLIC_API(JSBool)
@ -649,7 +653,11 @@ JS_LooselyEqual(JSContext *cx, jsval v1, jsval v2, JSBool *equal)
AssertNoGC(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, v1, v2);
return LooselyEqual(cx, v1, v2, equal);
bool eq;
if (!LooselyEqual(cx, v1, v2, &eq))
return false;
*equal = eq;
return true;
}
JS_PUBLIC_API(JSBool)
@ -658,7 +666,11 @@ JS_SameValue(JSContext *cx, jsval v1, jsval v2, JSBool *same)
AssertNoGC(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, v1, v2);
return SameValue(cx, v1, v2, same);
bool s;
if (!SameValue(cx, v1, v2, &s))
return false;
*same = s;
return true;
}
JS_PUBLIC_API(JSBool)

View File

@ -3132,12 +3132,12 @@ array_indexOfHelper(JSContext *cx, IndexOfKind mode, CallArgs &args)
return JS_FALSE;
}
if (!hole) {
JSBool equal;
bool equal;
if (!StrictlyEqual(cx, elt, tosearch, &equal))
return JS_FALSE;
return false;
if (equal) {
args.rval().setNumber(i);
return JS_TRUE;
return true;
}
}
if (i == stop)

View File

@ -835,12 +835,16 @@ js::HasInstance(JSContext *cx, JSObject *obj, const Value *v, JSBool *bp)
}
bool
js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *result)
js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *result)
{
#if JS_HAS_XML_SUPPORT
if (JS_UNLIKELY(lval.isObject() && lval.toObject().isXML()) ||
(rval.isObject() && rval.toObject().isXML())) {
return js_TestXMLEquality(cx, lval, rval, result);
JSBool res;
if (!js_TestXMLEquality(cx, lval, rval, &res))
return false;
*result = !!res;
return true;
}
#endif
@ -862,7 +866,11 @@ js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *re
JSObject *r = &rval.toObject();
if (JSEqualityOp eq = l->getClass()->ext.equality) {
return eq(cx, l, &rval, result);
JSBool res;
if (!eq(cx, l, &rval, &res))
return false;
*result = !!res;
return true;
}
*result = l == r;
@ -905,7 +913,7 @@ js::LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *re
}
bool
js::StrictlyEqual(JSContext *cx, const Value &lref, const Value &rref, JSBool *equal)
js::StrictlyEqual(JSContext *cx, const Value &lref, const Value &rref, bool *equal)
{
Value lval = lref, rval = rref;
if (SameType(lval, rval)) {
@ -957,7 +965,7 @@ IsNaN(const Value &v)
}
bool
js::SameValue(JSContext *cx, const Value &v1, const Value &v2, JSBool *same)
js::SameValue(JSContext *cx, const Value &v1, const Value &v2, bool *same)
{
if (IsNegativeZero(v1)) {
*same = IsNegativeZero(v2);
@ -2264,7 +2272,7 @@ END_CASE(JSOP_BITAND)
JS_BEGIN_MACRO \
Value rval = regs.sp[-1]; \
Value lval = regs.sp[-2]; \
JSBool cond; \
bool cond; \
if (!LooselyEqual(cx, lval, rval, &cond)) \
goto error; \
cond = cond OP JS_TRUE; \
@ -2287,7 +2295,7 @@ END_CASE(JSOP_NE)
JS_BEGIN_MACRO \
const Value &rref = regs.sp[-1]; \
const Value &lref = regs.sp[-2]; \
JSBool equal; \
bool equal; \
if (!StrictlyEqual(cx, lref, rref, &equal)) \
goto error; \
COND = equal OP JS_TRUE; \

View File

@ -239,14 +239,14 @@ CheckRedeclaration(JSContext *cx, JSObject *obj, PropertyName *name, uintN attrs
}
extern bool
StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *equal);
StrictlyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *equal);
extern bool
LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, JSBool *equal);
LooselyEqual(JSContext *cx, const Value &lval, const Value &rval, bool *equal);
/* === except that NaN is the same as NaN and -0 is not the same as +0. */
extern bool
SameValue(JSContext *cx, const Value &v1, const Value &v2, JSBool *same);
SameValue(JSContext *cx, const Value &v1, const Value &v2, bool *same);
extern JSType
TypeOfValue(JSContext *cx, const Value &v);

View File

@ -2141,17 +2141,17 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const jsid &id, const PropD
break;
if (desc.hasGet) {
JSBool same;
bool same;
if (!SameValue(cx, desc.getterValue(), shape->getterOrUndefined(), &same))
return JS_FALSE;
return false;
if (!same)
break;
}
if (desc.hasSet) {
JSBool same;
bool same;
if (!SameValue(cx, desc.setterValue(), shape->setterOrUndefined(), &same))
return JS_FALSE;
return false;
if (!same)
break;
}
@ -2190,10 +2190,10 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const jsid &id, const PropD
if (!shape->isDataDescriptor())
break;
JSBool same;
bool same;
if (desc.hasValue) {
if (!SameValue(cx, desc.value, v, &same))
return JS_FALSE;
return false;
if (!same) {
/*
* Insist that a non-configurable js::PropertyOp data
@ -2268,9 +2268,9 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const jsid &id, const PropD
if (desc.hasWritable && desc.writable())
return Reject(cx, JSMSG_CANT_REDEFINE_PROP, throwError, id, rval);
if (desc.hasValue) {
JSBool same;
bool same;
if (!SameValue(cx, desc.value, v, &same))
return JS_FALSE;
return false;
if (!same)
return Reject(cx, JSMSG_CANT_REDEFINE_PROP, throwError, id, rval);
}
@ -2282,17 +2282,17 @@ DefinePropertyOnObject(JSContext *cx, JSObject *obj, const jsid &id, const PropD
JS_ASSERT(desc.isAccessorDescriptor() && shape->isAccessorDescriptor());
if (!shape->configurable()) {
if (desc.hasSet) {
JSBool same;
bool same;
if (!SameValue(cx, desc.setterValue(), shape->setterOrUndefined(), &same))
return JS_FALSE;
return false;
if (!same)
return Reject(cx, JSMSG_CANT_REDEFINE_PROP, throwError, id, rval);
}
if (desc.hasGet) {
JSBool same;
bool same;
if (!SameValue(cx, desc.getterValue(), shape->getterOrUndefined(), &same))
return JS_FALSE;
return false;
if (!same)
return Reject(cx, JSMSG_CANT_REDEFINE_PROP, throwError, id, rval);
}

View File

@ -3378,7 +3378,7 @@ js_ValueToSource(JSContext *cx, const Value &v)
namespace js {
bool
EqualStrings(JSContext *cx, JSString *str1, JSString *str2, JSBool *result)
EqualStrings(JSContext *cx, JSString *str1, JSString *str2, bool *result)
{
if (str1 == str2) {
*result = true;

View File

@ -186,7 +186,7 @@ namespace js {
* or str2 are not GC-allocated things.
*/
extern bool
EqualStrings(JSContext *cx, JSString *str1, JSString *str2, JSBool *result);
EqualStrings(JSContext *cx, JSString *str1, JSString *str2, bool *result);
/* EqualStrings is infallible on linear strings. */
extern bool

View File

@ -3384,8 +3384,10 @@ retry:
return JS_TRUE;
if (JSXML_HAS_VALUE(xml)) {
if (!EqualStrings(cx, xml->xml_value, vxml->xml_value, bp))
bool equal;
if (!EqualStrings(cx, xml->xml_value, vxml->xml_value, &equal))
return JS_FALSE;
*bp = equal;
} else if (xml->xml_kids.length != vxml->xml_kids.length) {
*bp = JS_FALSE;
} else {
@ -3425,8 +3427,10 @@ retry:
vattr = XMLARRAY_MEMBER(&vxml->xml_attrs, j, JSXML);
if (!vattr)
continue;
if (!EqualStrings(cx, attr->xml_value, vattr->xml_value, bp))
bool equal;
if (!EqualStrings(cx, attr->xml_value, vattr->xml_value, &equal))
return JS_FALSE;
*bp = equal;
}
}
}
@ -5275,8 +5279,11 @@ js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
if (ok) {
ok = (str = ToStringSlow(cx, ObjectValue(*obj))) &&
(vstr = ToString(cx, v));
if (ok)
ok = EqualStrings(cx, str, vstr, bp);
if (ok) {
bool equal;
ok = EqualStrings(cx, str, vstr, &equal);
*bp = equal;
}
js_LeaveLocalRootScope(cx);
}
} else {
@ -5289,14 +5296,20 @@ js_TestXMLEquality(JSContext *cx, const Value &v1, const Value &v2, JSBool *bp)
if (HasSimpleContent(xml)) {
ok = (str = ToString(cx, ObjectValue(*obj))) &&
(vstr = ToString(cx, v));
if (ok)
ok = EqualStrings(cx, str, vstr, bp);
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)) {
ok = EqualStrings(cx, str, JSVAL_TO_STRING(v), bp);
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) {

View File

@ -2300,7 +2300,7 @@ mjit::Compiler::jsop_stricteq(JSOp op)
/* Constant-fold. */
if (lhs->isConstant() && rhs->isConstant()) {
JSBool b;
bool b;
StrictlyEqual(cx, lhs->getValue(), rhs->getValue(), &b);
frame.popn(2);
frame.push(BooleanValue((op == JSOP_STRICTEQ) ? b : !b));

View File

@ -568,7 +568,7 @@ stubs::Not(VMFrame &f)
f.regs.sp[-1].setBoolean(b);
}
template <JSBool EQ, bool IFNAN>
template <bool EQ, bool IFNAN>
static inline bool
StubEqualityOp(VMFrame &f)
{
@ -578,23 +578,25 @@ StubEqualityOp(VMFrame &f)
Value rval = regs.sp[-1];
Value lval = regs.sp[-2];
JSBool cond;
bool cond;
/* The string==string case is easily the hottest; try it first. */
if (lval.isString() && rval.isString()) {
JSString *l = lval.toString();
JSString *r = rval.toString();
JSBool equal;
bool equal;
if (!EqualStrings(cx, l, r, &equal))
return false;
cond = equal == EQ;
} else
#if JS_HAS_XML_SUPPORT
if ((lval.isObject() && lval.toObject().isXML()) ||
(rval.isObject() && rval.toObject().isXML())) {
if (!js_TestXMLEquality(cx, lval, rval, &cond))
(rval.isObject() && rval.toObject().isXML()))
{
JSBool equal;
if (!js_TestXMLEquality(cx, lval, rval, &equal))
return false;
cond = cond == EQ;
cond = !!equal == EQ;
} else
#endif
@ -610,9 +612,10 @@ StubEqualityOp(VMFrame &f)
} else if (lval.isObject()) {
JSObject *l = &lval.toObject(), *r = &rval.toObject();
if (JSEqualityOp eq = l->getClass()->ext.equality) {
if (!eq(cx, l, &rval, &cond))
JSBool equal;
if (!eq(cx, l, &rval, &equal))
return false;
cond = cond == EQ;
cond = !!equal == EQ;
} else {
cond = (l == r) == EQ;
}
@ -639,7 +642,7 @@ StubEqualityOp(VMFrame &f)
if (lval.isString() && rval.isString()) {
JSString *l = lval.toString();
JSString *r = rval.toString();
JSBool equal;
bool equal;
if (!EqualStrings(cx, l, r, &equal))
return false;
cond = equal == EQ;
@ -663,7 +666,7 @@ StubEqualityOp(VMFrame &f)
JSBool JS_FASTCALL
stubs::Equal(VMFrame &f)
{
if (!StubEqualityOp<JS_TRUE, false>(f))
if (!StubEqualityOp<true, false>(f))
THROWV(JS_FALSE);
return f.regs.sp[-2].toBoolean();
}
@ -671,7 +674,7 @@ stubs::Equal(VMFrame &f)
JSBool JS_FASTCALL
stubs::NotEqual(VMFrame &f)
{
if (!StubEqualityOp<JS_FALSE, true>(f))
if (!StubEqualityOp<false, true>(f))
THROWV(JS_FALSE);
return f.regs.sp[-2].toBoolean();
}
@ -1319,7 +1322,7 @@ stubs::StrictEq(VMFrame &f)
{
const Value &rhs = f.regs.sp[-1];
const Value &lhs = f.regs.sp[-2];
JSBool equal;
bool equal;
if (!StrictlyEqual(f.cx, lhs, rhs, &equal))
THROW();
f.regs.sp--;
@ -1331,7 +1334,7 @@ stubs::StrictNe(VMFrame &f)
{
const Value &rhs = f.regs.sp[-1];
const Value &lhs = f.regs.sp[-2];
JSBool equal;
bool equal;
if (!StrictlyEqual(f.cx, lhs, rhs, &equal))
THROW();
f.regs.sp--;