mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Backed out changeset 3dace40ce193 (bug 1492669) for build bustage on Result.h:308. CLOSED TREE
This commit is contained in:
parent
d8a1368253
commit
5b32dd158a
@ -28,8 +28,6 @@
|
||||
using namespace js;
|
||||
|
||||
using mozilla::Maybe;
|
||||
using mozilla::Some;
|
||||
using mozilla::Nothing;
|
||||
using mozilla::Range;
|
||||
using mozilla::RangedPtr;
|
||||
|
||||
@ -732,82 +730,6 @@ BigInt::looselyEqual(JSContext* cx, HandleBigInt lhs, HandleValue rhs)
|
||||
return false;
|
||||
}
|
||||
|
||||
// BigInt proposal section 1.1.12. BigInt::lessThan ( x, y )
|
||||
bool
|
||||
BigInt::lessThan(BigInt* x, BigInt* y)
|
||||
{
|
||||
return mpz_cmp(x->num_, y->num_) < 0;
|
||||
}
|
||||
|
||||
Maybe<bool>
|
||||
BigInt::lessThan(BigInt* lhs, double rhs)
|
||||
{
|
||||
if (mozilla::IsNaN(rhs)) {
|
||||
return Maybe<bool>(Nothing());
|
||||
}
|
||||
return Some(mpz_cmp_d(lhs->num_, rhs) < 0);
|
||||
}
|
||||
|
||||
Maybe<bool>
|
||||
BigInt::lessThan(double lhs, BigInt* rhs)
|
||||
{
|
||||
if (mozilla::IsNaN(lhs)) {
|
||||
return Maybe<bool>(Nothing());
|
||||
}
|
||||
return Some(-mpz_cmp_d(rhs->num_, lhs) < 0);
|
||||
}
|
||||
|
||||
JS::Result<Maybe<bool>>
|
||||
BigInt::lessThan(JSContext* cx, HandleBigInt lhs, HandleString rhs)
|
||||
{
|
||||
RootedBigInt rhsBigInt(cx);
|
||||
MOZ_TRY_VAR(rhsBigInt, StringToBigInt(cx, rhs, 0));
|
||||
if (!rhsBigInt) {
|
||||
return Maybe<bool>(Nothing());
|
||||
}
|
||||
return Some(lessThan(lhs, rhsBigInt));
|
||||
}
|
||||
|
||||
JS::Result<Maybe<bool>>
|
||||
BigInt::lessThan(JSContext* cx, HandleString lhs, HandleBigInt rhs)
|
||||
{
|
||||
RootedBigInt lhsBigInt(cx);
|
||||
MOZ_TRY_VAR(lhsBigInt, StringToBigInt(cx, lhs, 0));
|
||||
if (!lhsBigInt) {
|
||||
return Maybe<bool>(Nothing());
|
||||
}
|
||||
return Some(lessThan(lhsBigInt, rhs));
|
||||
}
|
||||
|
||||
JS::Result<Maybe<bool>>
|
||||
BigInt::lessThan(JSContext* cx, HandleValue lhs, HandleValue rhs)
|
||||
{
|
||||
if (lhs.isBigInt()) {
|
||||
if (rhs.isString()) {
|
||||
RootedBigInt lhsBigInt(cx, lhs.toBigInt());
|
||||
RootedString rhsString(cx, rhs.toString());
|
||||
return lessThan(cx, lhsBigInt, rhsString);
|
||||
}
|
||||
|
||||
if (rhs.isNumber()) {
|
||||
return lessThan(lhs.toBigInt(), rhs.toNumber());
|
||||
}
|
||||
|
||||
MOZ_ASSERT(rhs.isBigInt());
|
||||
return Some(lessThan(lhs.toBigInt(), rhs.toBigInt()));
|
||||
}
|
||||
|
||||
MOZ_ASSERT(rhs.isBigInt());
|
||||
if (lhs.isString()) {
|
||||
RootedString lhsString(cx, lhs.toString());
|
||||
RootedBigInt rhsBigInt(cx, rhs.toBigInt());
|
||||
return lessThan(cx, lhsString, rhsBigInt);
|
||||
}
|
||||
|
||||
MOZ_ASSERT(lhs.isNumber());
|
||||
return lessThan(lhs.toNumber(), rhs.toBigInt());
|
||||
}
|
||||
|
||||
JSLinearString*
|
||||
BigInt::toString(JSContext* cx, BigInt* x, uint8_t radix)
|
||||
{
|
||||
|
@ -116,16 +116,6 @@ class BigInt final : public js::gc::TenuredCell
|
||||
static bool equal(BigInt* lhs, double rhs);
|
||||
static JS::Result<bool> looselyEqual(JSContext* cx, HandleBigInt lhs, HandleValue rhs);
|
||||
|
||||
static bool lessThan(BigInt* x, BigInt* y);
|
||||
|
||||
// These methods return Nothing when the non-BigInt operand is NaN
|
||||
// or a string that can't be interpreted as a BigInt.
|
||||
static mozilla::Maybe<bool> lessThan(BigInt* lhs, double rhs);
|
||||
static mozilla::Maybe<bool> lessThan(double lhs, BigInt* rhs);
|
||||
static JS::Result<mozilla::Maybe<bool>> lessThan(JSContext* cx, HandleBigInt lhs, HandleString rhs);
|
||||
static JS::Result<mozilla::Maybe<bool>> lessThan(JSContext* cx, HandleString lhs, HandleBigInt rhs);
|
||||
static JS::Result<mozilla::Maybe<bool>> lessThan(JSContext* cx, HandleValue lhs, HandleValue rhs);
|
||||
|
||||
// Return the length in bytes of the representation used by
|
||||
// writeBytes.
|
||||
static size_t byteLength(BigInt* x);
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include "vm/Interpreter.h"
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
#include "jsnum.h"
|
||||
|
||||
#include "builtin/String.h"
|
||||
@ -757,151 +755,51 @@ ProcessCallSiteObjOperation(JSContext* cx, HandleObject cso, HandleObject raw)
|
||||
return true;
|
||||
}
|
||||
|
||||
// BigInt proposal 3.2.4 Abstract Relational Comparison
|
||||
// Returns Nothing when at least one operand is a NaN, or when
|
||||
// ToNumeric or StringToBigInt can't interpret a string as a numeric
|
||||
// value. (These cases correspond to a NaN result in the spec.)
|
||||
// Otherwise, return a boolean to indicate whether lhs is less than
|
||||
// rhs. The operands must be primitives; the caller is responsible for
|
||||
// evaluating them in the correct order.
|
||||
static MOZ_ALWAYS_INLINE JS::Result<mozilla::Maybe<bool>>
|
||||
LessThanImpl(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs)
|
||||
{
|
||||
// Steps 1 and 2 are performed by the caller.
|
||||
#define RELATIONAL_OP(OP) \
|
||||
JS_BEGIN_MACRO \
|
||||
/* Optimize for two int-tagged operands (typical loop control). */ \
|
||||
if (lhs.isInt32() && rhs.isInt32()) { \
|
||||
*res = lhs.toInt32() OP rhs.toInt32(); \
|
||||
} else { \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, lhs)) \
|
||||
return false; \
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, rhs)) \
|
||||
return false; \
|
||||
if (lhs.isString() && rhs.isString()) { \
|
||||
JSString* l = lhs.toString(); \
|
||||
JSString* r = rhs.toString(); \
|
||||
int32_t result; \
|
||||
if (!CompareStrings(cx, l, r, &result)) \
|
||||
return false; \
|
||||
*res = result OP 0; \
|
||||
} else { \
|
||||
double l, r; \
|
||||
if (!ToNumber(cx, lhs, &l) || !ToNumber(cx, rhs, &r)) \
|
||||
return false; \
|
||||
*res = (l OP r); \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
JS_END_MACRO
|
||||
|
||||
// Step 3.
|
||||
if (lhs.isString() && rhs.isString()) {
|
||||
JSString* l = lhs.toString();
|
||||
JSString* r = rhs.toString();
|
||||
int32_t result;
|
||||
if (!CompareStrings(cx, l, r, &result)) {
|
||||
return cx->alreadyReportedError();
|
||||
}
|
||||
return mozilla::Some(result < 0);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BIGINT
|
||||
// Step 4a.
|
||||
if (lhs.isBigInt() && rhs.isString()) {
|
||||
return BigInt::lessThan(cx, lhs, rhs);
|
||||
}
|
||||
|
||||
// Step 4b.
|
||||
if (lhs.isString() && rhs.isBigInt()) {
|
||||
return BigInt::lessThan(cx, lhs, rhs);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Steps 4c and 4d.
|
||||
if (!ToNumeric(cx, lhs) || !ToNumeric(cx, rhs)) {
|
||||
return cx->alreadyReportedError();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_BIGINT
|
||||
// Steps 4e-j.
|
||||
if (lhs.isBigInt() || rhs.isBigInt()) {
|
||||
return BigInt::lessThan(cx, lhs, rhs);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Step 4e for Number operands.
|
||||
MOZ_ASSERT(lhs.isNumber() && rhs.isNumber());
|
||||
double lhsNum = lhs.toNumber();
|
||||
double rhsNum = rhs.toNumber();
|
||||
|
||||
if (mozilla::IsNaN(lhsNum) || mozilla::IsNaN(rhsNum)) {
|
||||
return mozilla::Maybe<bool>(mozilla::Nothing());
|
||||
}
|
||||
|
||||
return mozilla::Some(lhsNum < rhsNum);
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
LessThanOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res) {
|
||||
RELATIONAL_OP(<);
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
LessThanOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res)
|
||||
{
|
||||
if (lhs.isInt32() && rhs.isInt32()) {
|
||||
*res = lhs.toInt32() < rhs.toInt32();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, lhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, rhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Maybe<bool> tmpResult;
|
||||
JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, LessThanImpl(cx, lhs, rhs));
|
||||
*res = tmpResult.valueOr(false);
|
||||
return true;
|
||||
LessThanOrEqualOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res) {
|
||||
RELATIONAL_OP(<=);
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
LessThanOrEqualOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res)
|
||||
{
|
||||
if (lhs.isInt32() && rhs.isInt32()) {
|
||||
*res = lhs.toInt32() <= rhs.toInt32();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, lhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, rhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Maybe<bool> tmpResult;
|
||||
JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, LessThanImpl(cx, rhs, lhs));
|
||||
*res = !tmpResult.valueOr(true);
|
||||
return true;
|
||||
GreaterThanOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res) {
|
||||
RELATIONAL_OP(>);
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
GreaterThanOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res)
|
||||
{
|
||||
if (lhs.isInt32() && rhs.isInt32()) {
|
||||
*res = lhs.toInt32() > rhs.toInt32();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, lhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, rhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Maybe<bool> tmpResult;
|
||||
JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, LessThanImpl(cx, rhs, lhs));
|
||||
*res = tmpResult.valueOr(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
GreaterThanOrEqualOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res)
|
||||
{
|
||||
if (lhs.isInt32() && rhs.isInt32()) {
|
||||
*res = lhs.toInt32() >= rhs.toInt32();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, lhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ToPrimitive(cx, JSTYPE_NUMBER, rhs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Maybe<bool> tmpResult;
|
||||
JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, LessThanImpl(cx, lhs, rhs));
|
||||
*res = !tmpResult.valueOr(true);
|
||||
return true;
|
||||
GreaterThanOrEqualOperation(JSContext* cx, MutableHandleValue lhs, MutableHandleValue rhs, bool* res) {
|
||||
RELATIONAL_OP(>=);
|
||||
}
|
||||
|
||||
static MOZ_ALWAYS_INLINE bool
|
||||
|
Loading…
Reference in New Issue
Block a user