in rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java [3874:3978]
public static boolean eq(Object x, Object y) {
if (x == null || Undefined.isUndefined(x)) {
if (y == null || Undefined.isUndefined(y)) {
return true;
}
if (y instanceof ScriptableObject) {
Object test = ((ScriptableObject) y).equivalentValues(x);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
return false;
} else if (x instanceof BigInteger) {
return eqBigInt((BigInteger) x, y);
} else if (x instanceof Number) {
return eqNumber(((Number) x).doubleValue(), y);
} else if (x == y) {
return true;
} else if (x instanceof CharSequence) {
return eqString((CharSequence) x, y);
} else if (x instanceof Boolean) {
boolean b = ((Boolean) x).booleanValue();
if (y instanceof Boolean) {
return b == ((Boolean) y).booleanValue();
}
if (y instanceof ScriptableObject) {
Object test = ((ScriptableObject) y).equivalentValues(x);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
return eqNumber(b ? 1.0 : 0.0, y);
} else if (isSymbol(x) && isObject(y)) {
return eq(x, toPrimitive(y));
} else if (x instanceof Scriptable) {
if (x instanceof Delegator) {
x = ((Delegator) x).getDelegee();
if (y instanceof Delegator) {
return eq(x, ((Delegator) y).getDelegee());
}
if (x == y) {
return true;
}
}
if (y instanceof Delegator && ((Delegator) y).getDelegee() == x) {
return true;
}
if (isSymbol(y) && isObject(x)) {
return eq(toPrimitive(x), y);
}
if (y == null || Undefined.isUndefined(y)) {
if (x instanceof ScriptableObject) {
Object test = ((ScriptableObject) x).equivalentValues(y);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
return false;
} else if (y instanceof Scriptable) {
if (x instanceof ScriptableObject) {
Object test = ((ScriptableObject) x).equivalentValues(y);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
if (y instanceof ScriptableObject) {
Object test = ((ScriptableObject) y).equivalentValues(x);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
if (x instanceof Wrapper && y instanceof Wrapper) {
// See bug 413838. Effectively an extension to ECMA for
// the LiveConnect case.
Object unwrappedX = ((Wrapper) x).unwrap();
Object unwrappedY = ((Wrapper) y).unwrap();
return unwrappedX == unwrappedY
|| (isPrimitive(unwrappedX)
&& isPrimitive(unwrappedY)
&& eq(unwrappedX, unwrappedY));
}
return false;
} else if (y instanceof Boolean) {
if (x instanceof ScriptableObject) {
Object test = ((ScriptableObject) x).equivalentValues(y);
if (test != Scriptable.NOT_FOUND) {
return ((Boolean) test).booleanValue();
}
}
double d = ((Boolean) y).booleanValue() ? 1.0 : 0.0;
return eqNumber(d, x);
} else if (y instanceof BigInteger) {
return eqBigInt((BigInteger) y, x);
} else if (y instanceof Number) {
return eqNumber(((Number) y).doubleValue(), x);
} else if (y instanceof CharSequence) {
return eqString((CharSequence) y, x);
}
// covers the case when y == Undefined.instance as well
return false;
} else {
warnAboutNonJSObject(x);
return x == y;
}
}