mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Issue #1240 - Part 6c - Implement asIntN and asUintN methods for BigInt values. https://bugzilla.mozilla.org/show_bug.cgi?id=1501104
This commit is contained in:
parent
e004b99054
commit
bbbab3898f
2 changed files with 66 additions and 1 deletions
|
|
@ -179,10 +179,66 @@ BigIntObject::toLocaleString(JSContext* cx, unsigned argc, Value* vp)
|
|||
return CallNonGenericMethod<IsBigInt, toLocaleString_impl>(cx, args);
|
||||
}
|
||||
|
||||
// BigInt proposal section 5.2.1. BigInt.asUintN ( bits, bigint )
|
||||
bool
|
||||
BigIntObject::asUintN(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
// Step 1.
|
||||
uint64_t bits;
|
||||
if (!ToIndex(cx, args[0], &bits)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
RootedBigInt bi(cx, ToBigInt(cx, args[1]));
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
BigInt* res = BigInt::asUintN(cx, bi, bits);
|
||||
if (!res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
args.rval().setBigInt(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
// BigInt proposal section 5.2.2. BigInt.asIntN ( bits, bigint )
|
||||
bool
|
||||
BigIntObject::asIntN(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
// Step 1.
|
||||
uint64_t bits;
|
||||
if (!ToIndex(cx, args[0], &bits)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
RootedBigInt bi(cx, ToBigInt(cx, args[1]));
|
||||
if (!bi) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step 3.
|
||||
BigInt* res = BigInt::asIntN(cx, bi, bits);
|
||||
if (!res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
args.rval().setBigInt(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
const ClassSpec BigIntObject::classSpec_ = {
|
||||
GenericCreateConstructor<BigIntConstructor, 1, gc::AllocKind::FUNCTION>,
|
||||
CreateBigIntPrototype,
|
||||
nullptr,
|
||||
BigIntObject::staticMethods,
|
||||
nullptr,
|
||||
BigIntObject::methods,
|
||||
BigIntObject::properties
|
||||
|
|
@ -208,3 +264,9 @@ const JSFunctionSpec BigIntObject::methods[] = {
|
|||
JS_FN("toLocaleString", toLocaleString, 0, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
||||
const JSFunctionSpec BigIntObject::staticMethods[] = {
|
||||
JS_FN("asUintN", asUintN, 2, 0),
|
||||
JS_FN("asIntN", asIntN, 2, 0),
|
||||
JS_FS_END
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,12 +33,15 @@ class BigIntObject : public NativeObject
|
|||
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);
|
||||
static bool asUintN(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||
static bool asIntN(JSContext* cx, unsigned argc, JS::Value* vp);
|
||||
|
||||
JS::BigInt* unbox() const;
|
||||
|
||||
private:
|
||||
static const JSPropertySpec properties[];
|
||||
static const JSFunctionSpec methods[];
|
||||
static const JSFunctionSpec staticMethods[];
|
||||
};
|
||||
|
||||
extern JSObject*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue