tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 98782f1d9cd9fab1fcc91e90f9f42ad0288735db
parent 83e06b74711afbaf88c6f898762d8761b551dc59
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed, 12 Nov 2025 09:05:12 +0000

Bug 1999551 - Part 2: Update js::LooselyEqual. r=jandem

Differential Revision: https://phabricator.services.mozilla.com/D272196

Diffstat:
Mjs/src/vm/EqualityOperations.cpp | 62+++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 35 insertions(+), 27 deletions(-)

diff --git a/js/src/vm/EqualityOperations.cpp b/js/src/vm/EqualityOperations.cpp @@ -140,14 +140,34 @@ bool js::LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval, } // Step 7. If x is a BigInt and y is a String, then - // Step 7.a. Let n be StringToBigInt(y). - // Step 7.b. If n is undefined, return false. - // Step 7.c. Return ! IsLooselyEqual(x, n). - // TODO + if (lval.isBigInt() && rval.isString()) { + // Step 7.a. Let n be StringToBigInt(y). + BigInt* n; + JS::Rooted<JSString*> str(cx, rval.toString()); + JS_TRY_VAR_OR_RETURN_FALSE(cx, n, StringToBigInt(cx, str)); + if (!n) { + // Step 7.b. If n is undefined, return false. + *result = false; + return true; + } + // Step 7.c. Return ! IsLooselyEqual(x, n). + *result = JS::BigInt::equal(lval.toBigInt(), n); + return true; + } // Step 8. If x is a String and y is a BigInt, return ! IsLooselyEqual(y, // x). - // TODO + if (lval.isString() && rval.isBigInt()) { + BigInt* n; + JS::Rooted<JSString*> str(cx, lval.toString()); + JS_TRY_VAR_OR_RETURN_FALSE(cx, n, StringToBigInt(cx, str)); + if (!n) { + *result = false; + return true; + } + *result = JS::BigInt::equal(rval.toBigInt(), n); + return true; + } // Step 9. If x is a Boolean, return ! IsLooselyEqual(! ToNumber(x), y). if (lval.isBoolean()) { @@ -161,8 +181,8 @@ bool js::LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval, // Step 11. If x is either a String, a Number, a BigInt, or a Symbol and y // is an Object, return ! IsLooselyEqual(x, ? ToPrimitive(y)). - // TODO - if ((lval.isString() || lval.isNumber() || lval.isSymbol()) && + if ((lval.isString() || lval.isNumber() || lval.isBigInt() || + lval.isSymbol()) && rval.isObject()) { JS::Rooted<JS::Value> rvalue(cx, rval); if (!ToPrimitive(cx, &rvalue)) { @@ -173,9 +193,8 @@ bool js::LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval, // Step 12. If x is an Object and y is either a String, a Number, a BigInt, // or a Symbol, return ! IsLooselyEqual(? ToPrimitive(x), y). - // TODO - if (lval.isObject() && - (rval.isString() || rval.isNumber() || rval.isSymbol())) { + if (lval.isObject() && (rval.isString() || rval.isNumber() || + rval.isBigInt() || rval.isSymbol())) { JS::Rooted<JS::Value> lvalue(cx, lval); if (!ToPrimitive(cx, &lvalue)) { return false; @@ -185,25 +204,14 @@ bool js::LooselyEqual(JSContext* cx, JS::Handle<JS::Value> lval, // Step 13. If x is a BigInt and y is a Number, or if x is a Number and y // is a BigInt, then - // Step 13.a. If x is not finite or y is not finite, return false. - // Step 13.b. If ℝ(x) = ℝ(y), return true; otherwise return false. - // TODO - - if (lval.isBigInt()) { - JS::Rooted<JS::BigInt*> lbi(cx, lval.toBigInt()); - bool tmpResult; - JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, - JS::BigInt::looselyEqual(cx, lbi, rval)); - *result = tmpResult; + if (lval.isBigInt() && rval.isNumber()) { + // Step 13.a. If x is not finite or y is not finite, return false. + // Step 13.b. If ℝ(x) = ℝ(y), return true; otherwise return false. + *result = BigInt::equal(lval.toBigInt(), rval.toNumber()); return true; } - - if (rval.isBigInt()) { - JS::Rooted<JS::BigInt*> rbi(cx, rval.toBigInt()); - bool tmpResult; - JS_TRY_VAR_OR_RETURN_FALSE(cx, tmpResult, - JS::BigInt::looselyEqual(cx, rbi, lval)); - *result = tmpResult; + if (lval.isNumber() && rval.isBigInt()) { + *result = BigInt::equal(rval.toBigInt(), lval.toNumber()); return true; }