diff options
author | Brian Smith <brian@dbsoft.org> | 2023-07-19 16:00:07 -0500 |
---|---|---|
committer | Brian Smith <brian@dbsoft.org> | 2023-07-19 16:00:07 -0500 |
commit | 700bead8ba82020d32eb0050bd809f8743192088 (patch) | |
tree | 87fcd0a92aceb9b9a98116659d92a4eefe41f6d4 /js/src | |
parent | f734e4f724fc83c8c296ca4c1f0eee8728fdb343 (diff) | |
download | uxp-700bead8ba82020d32eb0050bd809f8743192088.tar.gz |
Issue #1240 - Part 6a - Implement BigInt.prototype.toLocaleString.
https://bugzilla.mozilla.org/show_bug.cgi?id=1366287 Part 5.
Diffstat (limited to 'js/src')
-rw-r--r-- | js/src/builtin/BigInt.cpp | 27 | ||||
-rw-r--r-- | js/src/builtin/BigInt.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/js/src/builtin/BigInt.cpp b/js/src/builtin/BigInt.cpp index 72dcb3be56..4aaa84bf1d 100644 --- a/js/src/builtin/BigInt.cpp +++ b/js/src/builtin/BigInt.cpp @@ -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 }; diff --git a/js/src/builtin/BigInt.h b/js/src/builtin/BigInt.h index daa9fafac7..13c1985b30 100644 --- a/js/src/builtin/BigInt.h +++ b/js/src/builtin/BigInt.h @@ -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; |