зеркало из https://github.com/mozilla/gecko-dev.git
bug 1466893 - Part 2: Convert BigInt arguments to the Number constructor. r=jandem
This commit is contained in:
Родитель
01d8866628
Коммит
d875414c13
|
@ -29,6 +29,9 @@
|
|||
#include "js/Conversions.h"
|
||||
#include "util/DoubleToString.h"
|
||||
#include "util/StringBuffer.h"
|
||||
#ifdef ENABLE_BIGINT
|
||||
#include "vm/BigIntType.h"
|
||||
#endif
|
||||
#include "vm/GlobalObject.h"
|
||||
#include "vm/JSAtom.h"
|
||||
#include "vm/JSContext.h"
|
||||
|
@ -487,8 +490,14 @@ Number(JSContext* cx, unsigned argc, Value* vp)
|
|||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
if (args.length() > 0) {
|
||||
if (!ToNumber(cx, args[0]))
|
||||
// BigInt proposal section 6.2, steps 2a-c.
|
||||
if (!ToNumeric(cx, args[0]))
|
||||
return false;
|
||||
#ifdef ENABLE_BIGINT
|
||||
if (args[0].isBigInt())
|
||||
args[0].setNumber(BigInt::numberValue(args[0].toBigInt()));
|
||||
#endif
|
||||
MOZ_ASSERT(args[0].isNumber());
|
||||
}
|
||||
|
||||
if (!args.isConstructing()) {
|
||||
|
|
|
@ -175,6 +175,18 @@ js::ToBigInt(JSContext* cx, HandleValue val)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// ES 2019 draft 6.1.6
|
||||
double
|
||||
BigInt::numberValue(BigInt* x)
|
||||
{
|
||||
// mpz_get_d may cause a hardware overflow trap, so use
|
||||
// mpz_get_d_2exp to get the fractional part and exponent
|
||||
// separately.
|
||||
signed long int exp;
|
||||
double d = mpz_get_d_2exp(&exp, x->num_);
|
||||
return ldexp(d, exp);
|
||||
}
|
||||
|
||||
JSLinearString*
|
||||
BigInt::toString(JSContext* cx, BigInt* x, uint8_t radix)
|
||||
{
|
||||
|
|
|
@ -69,6 +69,7 @@ class BigInt final : public js::gc::TenuredCell
|
|||
|
||||
static BigInt* copy(JSContext* cx, Handle<BigInt*> x);
|
||||
|
||||
static double numberValue(BigInt* x);
|
||||
static JSLinearString* toString(JSContext* cx, BigInt* x, uint8_t radix);
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче