mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-04 14:58:37 +09:00
Issue #1240 - Part 6a - Implement BigInt.prototype.toLocaleString. https://bugzilla.mozilla.org/show_bug.cgi?id=1366287 Part 5.
This commit is contained in:
parent
e3ec738471
commit
e8f0ea219f
2 changed files with 29 additions and 0 deletions
|
|
@ -153,6 +153,32 @@ BigIntObject::toString(JSContext* cx, unsigned argc, Value* vp)
|
|||
return CallNonGenericMethod<IsBigInt, toString_impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal section 5.3.2. "This function is
|
||||
// implementation-dependent, and it is permissible, but not encouraged,
|
||||
// for it to return the same thing as toString."
|
||||
bool
|
||||
BigIntObject::toLocaleString_impl(JSContext* cx, const CallArgs& args)
|
||||
{
|
||||
HandleValue thisv = args.thisv();
|
||||
MOZ_ASSERT(IsBigInt(thisv));
|
||||
RootedBigInt bi(cx, thisv.isBigInt()
|
||||
? thisv.toBigInt()
|
||||
: thisv.toObject().as<BigIntObject>().unbox());
|
||||
|
||||
RootedString str(cx, BigInt::toString(cx, bi, 10));
|
||||
if (!str)
|
||||
return false;
|
||||
args.rval().setString(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
BigIntObject::toLocaleString(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<IsBigInt, toLocaleString_impl>(cx, args);
|
||||
}
|
||||
|
||||
const ClassSpec BigIntObject::classSpec_ = {
|
||||
GenericCreateConstructor<BigIntConstructor, 1, gc::AllocKind::FUNCTION>,
|
||||
CreateBigIntPrototype,
|
||||
|
|
@ -179,5 +205,6 @@ const JSPropertySpec BigIntObject::properties[] = {
|
|||
const JSFunctionSpec BigIntObject::methods[] = {
|
||||
JS_FN("valueOf", valueOf, 0, 0),
|
||||
JS_FN("toString", toString, 0, 0),
|
||||
JS_FN("toLocaleString", toLocaleString, 0, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class BigIntObject : public NativeObject
|
|||
static bool valueOf(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||
static bool toString_impl(JSContext* cx, const CallArgs& args);
|
||||
static bool toString(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||
static bool toLocaleString_impl(JSContext* cx, const CallArgs& args);
|
||||
static bool toLocaleString(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||
|
||||
JS::BigInt* unbox() const;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue