From fe9c5481ddd49732fef50f8421dc12d8992a1ca7 Mon Sep 17 00:00:00 2001 From: Robin Templeton Date: Mon, 29 Apr 2019 23:20:17 +0000 Subject: [PATCH] Bug 1531647 - Implement atomic operations on BigInt TypedArrays r=lth Differential Revision: https://phabricator.services.mozilla.com/D21648 --HG-- extra : moz-landing-system : lando --- js/src/builtin/AtomicsObject.cpp | 152 ++++++++++++++++++++++++------- js/src/tests/jstests.list | 59 ------------ 2 files changed, 119 insertions(+), 92 deletions(-) diff --git a/js/src/builtin/AtomicsObject.cpp b/js/src/builtin/AtomicsObject.cpp index 00deb344aee6..8c124c272caa 100644 --- a/js/src/builtin/AtomicsObject.cpp +++ b/js/src/builtin/AtomicsObject.cpp @@ -151,6 +151,68 @@ JS::Result<> ArrayOps::storeResult(JSContext* cx, uint32_t v, return Ok(); } +template <> +struct ArrayOps { + static JS::Result convertValue(JSContext* cx, HandleValue v) { + BigInt* bi = ToBigInt(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + return BigInt::toInt64(bi); + } + + static JS::Result convertValue(JSContext* cx, HandleValue v, + MutableHandleValue result) { + BigInt* bi = ToBigInt(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + result.setBigInt(bi); + return BigInt::toInt64(bi); + } + + static JS::Result<> storeResult(JSContext* cx, int64_t v, + MutableHandleValue result) { + BigInt* bi = BigInt::createFromInt64(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + result.setBigInt(bi); + return Ok(); + } +}; + +template <> +struct ArrayOps { + static JS::Result convertValue(JSContext* cx, HandleValue v) { + BigInt* bi = ToBigInt(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + return BigInt::toUint64(bi); + } + + static JS::Result convertValue(JSContext* cx, HandleValue v, + MutableHandleValue result) { + BigInt* bi = ToBigInt(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + result.setBigInt(bi); + return BigInt::toUint64(bi); + } + + static JS::Result<> storeResult(JSContext* cx, uint64_t v, + MutableHandleValue result) { + BigInt* bi = BigInt::createFromUint64(cx, v); + if (!bi) { + return cx->alreadyReportedError(); + } + result.setBigInt(bi); + return Ok(); + } +}; + template