зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1874684 - Part 18: Fix narrowing warnings from clang-tidy. r=allstarschh
Differential Revision: https://phabricator.services.mozilla.com/D198552
This commit is contained in:
Родитель
0e014d0303
Коммит
075bb94b0e
|
@ -208,7 +208,7 @@ static NormalizedTimeDuration NormalizeMicroseconds(const Int96& microseconds) {
|
|||
auto [seconds, micros] = microseconds / ToMicroseconds(TemporalUnit::Second);
|
||||
|
||||
// Scale microseconds to nanoseconds.
|
||||
int32_t nanos = micros * ToNanoseconds(TemporalUnit::Microsecond);
|
||||
int32_t nanos = micros * int32_t(ToNanoseconds(TemporalUnit::Microsecond));
|
||||
|
||||
return {seconds, nanos};
|
||||
}
|
||||
|
@ -752,7 +752,7 @@ bool js::temporal::ThrowIfInvalidDuration(JSContext* cx,
|
|||
|
||||
// Steps 2.b-c.
|
||||
if ((v < 0 && sign > 0) || (v > 0 && sign < 0)) {
|
||||
return ThrowInvalidDurationPart(cx, v, name,
|
||||
return ThrowInvalidDurationPart(cx, double(v), name,
|
||||
JSMSG_TEMPORAL_DURATION_INVALID_SIGN);
|
||||
}
|
||||
|
||||
|
@ -762,7 +762,7 @@ bool js::temporal::ThrowIfInvalidDuration(JSContext* cx,
|
|||
auto throwIfTooLarge = [&](int64_t v, const char* name) {
|
||||
if (std::abs(v) >= (int64_t(1) << 32)) {
|
||||
return ThrowInvalidDurationPart(
|
||||
cx, v, name, JSMSG_TEMPORAL_DURATION_INVALID_NON_FINITE);
|
||||
cx, double(v), name, JSMSG_TEMPORAL_DURATION_INVALID_NON_FINITE);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@ -2508,7 +2508,7 @@ static Duration AbsoluteDuration(const Duration& duration) {
|
|||
}
|
||||
|
||||
// Steps 1.b-c.
|
||||
uint32_t k = 100'000'000;
|
||||
int32_t k = 100'000'000;
|
||||
do {
|
||||
if (!result.append(char('0' + (subSecondNanoseconds / k)))) {
|
||||
return false;
|
||||
|
@ -2529,7 +2529,7 @@ static Duration AbsoluteDuration(const Duration& duration) {
|
|||
}
|
||||
|
||||
// Steps 2.b-c.
|
||||
uint32_t k = 100'000'000;
|
||||
int32_t k = 100'000'000;
|
||||
for (uint8_t i = 0; i < precision.value(); i++) {
|
||||
if (!result.append(char('0' + (subSecondNanoseconds / k)))) {
|
||||
return false;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "builtin/temporal/Instant.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
@ -865,7 +866,8 @@ static bool Instant_fromEpochSeconds(JSContext* cx, unsigned argc, Value* vp) {
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
auto* result = CreateTemporalInstant(cx, Instant::fromSeconds(epochSeconds));
|
||||
int64_t seconds = mozilla::AssertedCast<int64_t>(epochSeconds);
|
||||
auto* result = CreateTemporalInstant(cx, Instant::fromSeconds(seconds));
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
@ -908,8 +910,9 @@ static bool Instant_fromEpochMilliseconds(JSContext* cx, unsigned argc,
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
int64_t milliseconds = mozilla::AssertedCast<int64_t>(epochMilliseconds);
|
||||
auto* result =
|
||||
CreateTemporalInstant(cx, Instant::fromMilliseconds(epochMilliseconds));
|
||||
CreateTemporalInstant(cx, Instant::fromMilliseconds(milliseconds));
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1215,7 +1218,7 @@ static bool Instant_round(JSContext* cx, const CallArgs& args) {
|
|||
}
|
||||
|
||||
// Steps 10-15.
|
||||
uint64_t maximum = UnitsPerDay(smallestUnit);
|
||||
int64_t maximum = UnitsPerDay(smallestUnit);
|
||||
|
||||
// Step 16.
|
||||
if (!ValidateTemporalRoundingIncrement(cx, roundingIncrement, maximum,
|
||||
|
|
|
@ -39,12 +39,12 @@ mozilla::Maybe<Int96> Int96::fromInteger(double value) {
|
|||
|
||||
// Inlined version of |BigInt::createFromDouble()| for DigitBits=32. See the
|
||||
// comments in |BigInt::createFromDouble()| for how this code works.
|
||||
constexpr size_t DigitBits = 32;
|
||||
constexpr int DigitBits = 32;
|
||||
|
||||
// The number can't have more than three digits when it's below |maximum|.
|
||||
Int96::Digits digits = {};
|
||||
|
||||
int exponent = mozilla::ExponentComponent(value);
|
||||
int exponent = int(mozilla::ExponentComponent(value));
|
||||
MOZ_ASSERT(0 <= exponent && exponent <= 95,
|
||||
"exponent is lower than exponent of 0x1p+96");
|
||||
|
||||
|
@ -62,7 +62,7 @@ mozilla::Maybe<Int96> Int96::fromInteger(double value) {
|
|||
int msdTopBit = exponent % DigitBits;
|
||||
|
||||
// First, build the MSD by shifting the mantissa appropriately.
|
||||
int remainingMantissaBits = Double::kSignificandWidth - msdTopBit;
|
||||
int remainingMantissaBits = int(Double::kSignificandWidth - msdTopBit);
|
||||
digits[--length] = mantissa >> remainingMantissaBits;
|
||||
|
||||
// Fill in digits containing mantissa contributions.
|
||||
|
|
|
@ -133,7 +133,7 @@ class Int96 final {
|
|||
remainder = n % divisor;
|
||||
}
|
||||
|
||||
int64_t result = (TwoDigit(quotient[1]) << 32) | quotient[0];
|
||||
int64_t result = int64_t((TwoDigit(quotient[1]) << 32) | quotient[0]);
|
||||
if (negative) {
|
||||
result *= -1;
|
||||
if (remainder != 0) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "builtin/temporal/PlainDate.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Casting.h"
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
|
@ -316,13 +317,16 @@ static PlainDateObject* CreateTemporalDate(JSContext* cx, const CallArgs& args,
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
object->setFixedSlot(PlainDateObject::ISO_YEAR_SLOT, Int32Value(isoYear));
|
||||
object->setFixedSlot(PlainDateObject::ISO_YEAR_SLOT,
|
||||
Int32Value(int32_t(isoYear)));
|
||||
|
||||
// Step 6.
|
||||
object->setFixedSlot(PlainDateObject::ISO_MONTH_SLOT, Int32Value(isoMonth));
|
||||
object->setFixedSlot(PlainDateObject::ISO_MONTH_SLOT,
|
||||
Int32Value(int32_t(isoMonth)));
|
||||
|
||||
// Step 7.
|
||||
object->setFixedSlot(PlainDateObject::ISO_DAY_SLOT, Int32Value(isoDay));
|
||||
object->setFixedSlot(PlainDateObject::ISO_DAY_SLOT,
|
||||
Int32Value(int32_t(isoDay)));
|
||||
|
||||
// Step 8.
|
||||
object->setFixedSlot(PlainDateObject::CALENDAR_SLOT, calendar.toValue());
|
||||
|
@ -602,30 +606,28 @@ bool js::temporal::ToTemporalDate(JSContext* cx, Handle<Value> item,
|
|||
/**
|
||||
* Mathematical Operations, "modulo" notation.
|
||||
*/
|
||||
static int32_t NonNegativeModulo(double x, int32_t y) {
|
||||
MOZ_ASSERT(IsInteger(x));
|
||||
static int32_t NonNegativeModulo(int64_t x, int32_t y) {
|
||||
MOZ_ASSERT(y > 0);
|
||||
|
||||
double r = std::fmod(x, y);
|
||||
|
||||
int32_t result;
|
||||
MOZ_ALWAYS_TRUE(mozilla::NumberEqualsInt32(r, &result));
|
||||
|
||||
int32_t result = mozilla::AssertedCast<int32_t>(x % y);
|
||||
return (result < 0) ? (result + y) : result;
|
||||
}
|
||||
|
||||
struct BalancedYearMonth final {
|
||||
double year = 0;
|
||||
int64_t year = 0;
|
||||
int32_t month = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* BalanceISOYearMonth ( year, month )
|
||||
*/
|
||||
static BalancedYearMonth BalanceISOYearMonth(double year, double month) {
|
||||
// Step 1.
|
||||
MOZ_ASSERT(IsInteger(year));
|
||||
MOZ_ASSERT(IsInteger(month));
|
||||
static BalancedYearMonth BalanceISOYearMonth(int64_t year, int64_t month) {
|
||||
MOZ_ASSERT(std::abs(year) < (int64_t(1) << 33),
|
||||
"year is the addition of plain-date year with duration years");
|
||||
MOZ_ASSERT(std::abs(month) < (int64_t(1) << 33),
|
||||
"month is the addition of plain-date month with duration months");
|
||||
|
||||
// Step 1. (Not applicable in our implementation.)
|
||||
|
||||
// Note: If either abs(year) or abs(month) is greater than 2^53 (the double
|
||||
// integral precision limit), the additions resp. subtractions below are
|
||||
|
@ -633,18 +635,17 @@ static BalancedYearMonth BalanceISOYearMonth(double year, double month) {
|
|||
// function (AddISODate) will throw an error for large values anyway.
|
||||
|
||||
// Step 2.
|
||||
year = year + std::floor((month - 1) / 12);
|
||||
MOZ_ASSERT(IsInteger(year) || std::isinf(year));
|
||||
int64_t balancedYear = year + temporal::FloorDiv(month - 1, 12);
|
||||
|
||||
// Step 3.
|
||||
int32_t mon = NonNegativeModulo(month - 1, 12) + 1;
|
||||
MOZ_ASSERT(1 <= mon && mon <= 12);
|
||||
int32_t balancedMonth = NonNegativeModulo(month - 1, 12) + 1;
|
||||
MOZ_ASSERT(1 <= balancedMonth && balancedMonth <= 12);
|
||||
|
||||
// Step 4.
|
||||
return {year, mon};
|
||||
return {balancedYear, balancedMonth};
|
||||
}
|
||||
|
||||
static bool CanBalanceISOYear(double year) {
|
||||
static bool CanBalanceISOYear(int64_t year) {
|
||||
// TODO: Export these values somewhere.
|
||||
constexpr int32_t minYear = -271821;
|
||||
constexpr int32_t maxYear = 275760;
|
||||
|
@ -654,7 +655,7 @@ static bool CanBalanceISOYear(double year) {
|
|||
return minYear <= year && year <= maxYear;
|
||||
}
|
||||
|
||||
static bool CanBalanceISODay(double day) {
|
||||
static bool CanBalanceISODay(int64_t day) {
|
||||
// The maximum number of seconds from the epoch is 8.64 * 10^12.
|
||||
constexpr int64_t maxInstantSeconds = 8'640'000'000'000;
|
||||
|
||||
|
@ -684,7 +685,7 @@ PlainDate js::temporal::BalanceISODateNew(int32_t year, int32_t month,
|
|||
MOZ_ASSERT(1 <= month && month <= 12);
|
||||
|
||||
// Steps 1-3.
|
||||
int64_t ms = MakeDate(year, month, day);
|
||||
double ms = double(MakeDate(year, month, day));
|
||||
|
||||
// FIXME: spec issue - |ms| can be non-finite
|
||||
// https://github.com/tc39/proposal-temporal/issues/2315
|
||||
|
@ -827,7 +828,6 @@ bool js::temporal::AddISODate(JSContext* cx, const PlainDate& date,
|
|||
// Step 3.
|
||||
auto yearMonth = BalanceISOYearMonth(date.year + duration.years,
|
||||
date.month + duration.months);
|
||||
MOZ_ASSERT(IsInteger(yearMonth.year) || std::isinf(yearMonth.year));
|
||||
MOZ_ASSERT(1 <= yearMonth.month && yearMonth.month <= 12);
|
||||
|
||||
// FIXME: spec issue?
|
||||
|
@ -875,7 +875,7 @@ bool js::temporal::AddISODate(JSContext* cx, const PlainDate& date,
|
|||
// about imprecise number arithmetic here.
|
||||
|
||||
// Steps 5-6.
|
||||
double d = regulated.day + (duration.days + duration.weeks * 7);
|
||||
int64_t d = regulated.day + (duration.days + duration.weeks * 7);
|
||||
|
||||
// Just as with |yearMonth.year|, also directly throw an error if the |days|
|
||||
// value is too large.
|
||||
|
|
|
@ -295,37 +295,39 @@ static PlainDateTimeObject* CreateTemporalDateTime(
|
|||
|
||||
// Step 6.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_YEAR_SLOT,
|
||||
Int32Value(isoYear));
|
||||
Int32Value(int32_t(isoYear)));
|
||||
|
||||
// Step 7.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_MONTH_SLOT,
|
||||
Int32Value(isoMonth));
|
||||
Int32Value(int32_t(isoMonth)));
|
||||
|
||||
// Step 8.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_DAY_SLOT, Int32Value(isoDay));
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_DAY_SLOT,
|
||||
Int32Value(int32_t(isoDay)));
|
||||
|
||||
// Step 9.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_HOUR_SLOT, Int32Value(hour));
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_HOUR_SLOT,
|
||||
Int32Value(int32_t(hour)));
|
||||
|
||||
// Step 10.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_MINUTE_SLOT,
|
||||
Int32Value(minute));
|
||||
Int32Value(int32_t(minute)));
|
||||
|
||||
// Step 11.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_SECOND_SLOT,
|
||||
Int32Value(second));
|
||||
Int32Value(int32_t(second)));
|
||||
|
||||
// Step 12.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_MILLISECOND_SLOT,
|
||||
Int32Value(millisecond));
|
||||
Int32Value(int32_t(millisecond)));
|
||||
|
||||
// Step 13.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_MICROSECOND_SLOT,
|
||||
Int32Value(microsecond));
|
||||
Int32Value(int32_t(microsecond)));
|
||||
|
||||
// Step 14.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::ISO_NANOSECOND_SLOT,
|
||||
Int32Value(nanosecond));
|
||||
Int32Value(int32_t(nanosecond)));
|
||||
|
||||
// Step 15.
|
||||
dateTime->setFixedSlot(PlainDateTimeObject::CALENDAR_SLOT,
|
||||
|
@ -929,8 +931,8 @@ static PlainDateTime RoundISODateTime(const PlainDateTime& dateTime,
|
|||
MOZ_ASSERT(0 <= roundedTime.days && roundedTime.days <= 1);
|
||||
|
||||
// Step 4.
|
||||
auto balanceResult =
|
||||
BalanceISODate(date.year, date.month, date.day + roundedTime.days);
|
||||
auto balanceResult = BalanceISODate(date.year, date.month,
|
||||
date.day + int32_t(roundedTime.days));
|
||||
|
||||
// Step 5.
|
||||
return {balanceResult, roundedTime.time};
|
||||
|
|
|
@ -96,16 +96,19 @@ static PlainMonthDayObject* CreateTemporalMonthDay(
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_MONTH_SLOT, Int32Value(isoMonth));
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_MONTH_SLOT,
|
||||
Int32Value(int32_t(isoMonth)));
|
||||
|
||||
// Step 6.
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_DAY_SLOT, Int32Value(isoDay));
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_DAY_SLOT,
|
||||
Int32Value(int32_t(isoDay)));
|
||||
|
||||
// Step 7.
|
||||
obj->setFixedSlot(PlainMonthDayObject::CALENDAR_SLOT, calendar.toValue());
|
||||
|
||||
// Step 8.
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_YEAR_SLOT, Int32Value(isoYear));
|
||||
obj->setFixedSlot(PlainMonthDayObject::ISO_YEAR_SLOT,
|
||||
Int32Value(int32_t(isoYear)));
|
||||
|
||||
// Step 9.
|
||||
return obj;
|
||||
|
|
|
@ -335,25 +335,28 @@ static PlainTimeObject* CreateTemporalTime(JSContext* cx, const CallArgs& args,
|
|||
}
|
||||
|
||||
// Step 4.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_HOUR_SLOT, Int32Value(hour));
|
||||
object->setFixedSlot(PlainTimeObject::ISO_HOUR_SLOT,
|
||||
Int32Value(int32_t(hour)));
|
||||
|
||||
// Step 5.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_MINUTE_SLOT, Int32Value(minute));
|
||||
object->setFixedSlot(PlainTimeObject::ISO_MINUTE_SLOT,
|
||||
Int32Value(int32_t(minute)));
|
||||
|
||||
// Step 6.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_SECOND_SLOT, Int32Value(second));
|
||||
object->setFixedSlot(PlainTimeObject::ISO_SECOND_SLOT,
|
||||
Int32Value(int32_t(second)));
|
||||
|
||||
// Step 7.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_MILLISECOND_SLOT,
|
||||
Int32Value(millisecond));
|
||||
Int32Value(int32_t(millisecond)));
|
||||
|
||||
// Step 8.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_MICROSECOND_SLOT,
|
||||
Int32Value(microsecond));
|
||||
Int32Value(int32_t(microsecond)));
|
||||
|
||||
// Step 9.
|
||||
object->setFixedSlot(PlainTimeObject::ISO_NANOSECOND_SLOT,
|
||||
Int32Value(nanosecond));
|
||||
Int32Value(int32_t(nanosecond)));
|
||||
|
||||
// Step 10.
|
||||
return object;
|
||||
|
|
|
@ -111,7 +111,7 @@ static PlainYearMonthObject* CreateTemporalYearMonth(
|
|||
// testing |referenceISODay|?
|
||||
|
||||
// Step 2.
|
||||
if (!ISOYearMonthWithinLimits(isoYear, isoMonth)) {
|
||||
if (!ISOYearMonthWithinLimits(isoYear, int32_t(isoMonth))) {
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
|
||||
JSMSG_TEMPORAL_PLAIN_YEAR_MONTH_INVALID);
|
||||
return nullptr;
|
||||
|
@ -130,16 +130,19 @@ static PlainYearMonthObject* CreateTemporalYearMonth(
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_YEAR_SLOT, Int32Value(isoYear));
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_YEAR_SLOT,
|
||||
Int32Value(int32_t(isoYear)));
|
||||
|
||||
// Step 6.
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_MONTH_SLOT, Int32Value(isoMonth));
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_MONTH_SLOT,
|
||||
Int32Value(int32_t(isoMonth)));
|
||||
|
||||
// Step 7.
|
||||
obj->setFixedSlot(PlainYearMonthObject::CALENDAR_SLOT, calendar.toValue());
|
||||
|
||||
// Step 8.
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_DAY_SLOT, Int32Value(isoDay));
|
||||
obj->setFixedSlot(PlainYearMonthObject::ISO_DAY_SLOT,
|
||||
Int32Value(int32_t(isoDay)));
|
||||
|
||||
// Step 9.
|
||||
return obj;
|
||||
|
|
|
@ -177,7 +177,7 @@ bool js::temporal::ValidateTemporalRoundingIncrement(JSContext* cx,
|
|||
// Steps 3-4.
|
||||
if (increment.value() > maximum || dividend % increment.value() != 0) {
|
||||
Int32ToCStringBuf cbuf;
|
||||
const char* numStr = Int32ToCString(&cbuf, increment.value());
|
||||
const char* numStr = Int32ToCString(&cbuf, int32_t(increment.value()));
|
||||
|
||||
// TODO: Better error message could be helpful.
|
||||
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr,
|
||||
|
|
|
@ -204,7 +204,7 @@ class Precision final {
|
|||
constexpr Precision(int8_t value, Tag) : value_(value) {}
|
||||
|
||||
public:
|
||||
constexpr explicit Precision(uint8_t value) : value_(value) {
|
||||
constexpr explicit Precision(uint8_t value) : value_(int8_t(value)) {
|
||||
MOZ_ASSERT(value < 10);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,9 +116,9 @@ static JSString* SystemTimeZoneIdentifier(JSContext* cx) {
|
|||
size_t n = etcGMT.copy(offsetString, etcGMT.length());
|
||||
offsetString[n++] = offset < 0 ? '+' : '-';
|
||||
if (offsetHours >= 10) {
|
||||
offsetString[n++] = '0' + (offsetHours / 10);
|
||||
offsetString[n++] = char('0' + (offsetHours / 10));
|
||||
}
|
||||
offsetString[n++] = '0' + (offsetHours % 10);
|
||||
offsetString[n++] = char('0' + (offsetHours % 10));
|
||||
|
||||
MOZ_ASSERT(n == etcGMT.length() + 2 || n == etcGMT.length() + 3);
|
||||
|
||||
|
|
|
@ -80,11 +80,11 @@ bool EqualCharIgnoreCaseAscii(CharT c1, char c2) {
|
|||
// Convert both characters to lower case before the comparison.
|
||||
char c = c1;
|
||||
if (mozilla::IsAsciiUppercaseAlpha(c1)) {
|
||||
c = c + toLower;
|
||||
c = char(c + toLower);
|
||||
}
|
||||
char d = c2;
|
||||
if (mozilla::IsAsciiUppercaseAlpha(c2)) {
|
||||
d = d + toLower;
|
||||
d = char(d + toLower);
|
||||
}
|
||||
return c == d;
|
||||
}
|
||||
|
@ -2106,14 +2106,14 @@ bool js::temporal::ParseTemporalDurationString(JSContext* cx,
|
|||
|
||||
// Steps 9.b-d.
|
||||
int64_t h = int64_t(parsed.hoursFraction) * 60;
|
||||
minutes = h / 1'000'000'000;
|
||||
minutes = double(h / 1'000'000'000);
|
||||
|
||||
// Steps 13 and 15-17.
|
||||
int64_t min = (h % 1'000'000'000) * 60;
|
||||
seconds = min / 1'000'000'000;
|
||||
milliseconds = (min % 1'000'000'000) / 1'000'000;
|
||||
microseconds = (min % 1'000'000) / 1'000;
|
||||
nanoseconds = (min % 1'000);
|
||||
seconds = double(min / 1'000'000'000);
|
||||
milliseconds = double((min % 1'000'000'000) / 1'000'000);
|
||||
microseconds = double((min % 1'000'000) / 1'000);
|
||||
nanoseconds = double(min % 1'000);
|
||||
}
|
||||
|
||||
// Step 11.
|
||||
|
@ -2130,10 +2130,10 @@ bool js::temporal::ParseTemporalDurationString(JSContext* cx,
|
|||
|
||||
// Steps 11.b-d and 15-17.
|
||||
int64_t min = int64_t(parsed.minutesFraction) * 60;
|
||||
seconds = min / 1'000'000'000;
|
||||
milliseconds = (min % 1'000'000'000) / 1'000'000;
|
||||
microseconds = (min % 1'000'000) / 1'000;
|
||||
nanoseconds = (min % 1'000);
|
||||
seconds = double(min / 1'000'000'000);
|
||||
milliseconds = double((min % 1'000'000'000) / 1'000'000);
|
||||
microseconds = double((min % 1'000'000) / 1'000);
|
||||
nanoseconds = double(min % 1'000);
|
||||
}
|
||||
|
||||
// Step 14.
|
||||
|
@ -2148,9 +2148,9 @@ bool js::temporal::ParseTemporalDurationString(JSContext* cx,
|
|||
seconds = parsed.seconds;
|
||||
|
||||
// Steps 14, 16-17
|
||||
milliseconds = (parsed.secondsFraction / 1'000'000);
|
||||
microseconds = ((parsed.secondsFraction % 1'000'000) / 1'000);
|
||||
nanoseconds = (parsed.secondsFraction % 1'000);
|
||||
milliseconds = double(parsed.secondsFraction / 1'000'000);
|
||||
microseconds = double((parsed.secondsFraction % 1'000'000) / 1'000);
|
||||
nanoseconds = double(parsed.secondsFraction % 1'000);
|
||||
} else {
|
||||
// Step 10.
|
||||
minutes = parsed.minutes;
|
||||
|
|
|
@ -228,7 +228,7 @@ struct SecondsAndNanoseconds {
|
|||
*/
|
||||
static constexpr Derived fromMilliseconds(int64_t milliseconds) {
|
||||
int64_t seconds = milliseconds / 1'000;
|
||||
int32_t millis = milliseconds % 1'000;
|
||||
int32_t millis = int32_t(milliseconds % 1'000);
|
||||
if (millis < 0) {
|
||||
seconds -= 1;
|
||||
millis += 1'000;
|
||||
|
@ -241,7 +241,7 @@ struct SecondsAndNanoseconds {
|
|||
*/
|
||||
static constexpr Derived fromMicroseconds(int64_t microseconds) {
|
||||
int64_t seconds = microseconds / 1'000'000;
|
||||
int32_t micros = microseconds % 1'000'000;
|
||||
int32_t micros = int32_t(microseconds % 1'000'000);
|
||||
if (micros < 0) {
|
||||
seconds -= 1;
|
||||
micros += 1'000'000;
|
||||
|
@ -254,7 +254,7 @@ struct SecondsAndNanoseconds {
|
|||
*/
|
||||
static constexpr Derived fromNanoseconds(int64_t nanoseconds) {
|
||||
int64_t seconds = nanoseconds / 1'000'000'000;
|
||||
int32_t nanos = nanoseconds % 1'000'000'000;
|
||||
int32_t nanos = int32_t(nanoseconds % 1'000'000'000);
|
||||
if (nanos < 0) {
|
||||
seconds -= 1;
|
||||
nanos += 1'000'000'000;
|
||||
|
|
|
@ -1131,23 +1131,23 @@ JSString* js::temporal::FormatUTCOffsetNanoseconds(JSContext* cx,
|
|||
|
||||
// Steps 7-8. (Inlined FormatTimeString).
|
||||
result[n++] = sign;
|
||||
result[n++] = '0' + (hour / 10);
|
||||
result[n++] = '0' + (hour % 10);
|
||||
result[n++] = char('0' + (hour / 10));
|
||||
result[n++] = char('0' + (hour % 10));
|
||||
result[n++] = ':';
|
||||
result[n++] = '0' + (minute / 10);
|
||||
result[n++] = '0' + (minute % 10);
|
||||
result[n++] = char('0' + (minute / 10));
|
||||
result[n++] = char('0' + (minute % 10));
|
||||
|
||||
if (second != 0 || subSecondNanoseconds != 0) {
|
||||
result[n++] = ':';
|
||||
result[n++] = '0' + (second / 10);
|
||||
result[n++] = '0' + (second % 10);
|
||||
result[n++] = char('0' + (second / 10));
|
||||
result[n++] = char('0' + (second % 10));
|
||||
|
||||
if (uint32_t fractional = subSecondNanoseconds) {
|
||||
result[n++] = '.';
|
||||
|
||||
uint32_t k = 100'000'000;
|
||||
do {
|
||||
result[n++] = '0' + (fractional / k);
|
||||
result[n++] = char('0' + (fractional / k));
|
||||
fractional %= k;
|
||||
k /= 10;
|
||||
} while (fractional);
|
||||
|
@ -1338,28 +1338,28 @@ static PlainDateTime GetISOPartsFromEpoch(const Instant& instant) {
|
|||
int32_t remainderNs = instant.nanoseconds % 1'000'000;
|
||||
|
||||
// Step 3.
|
||||
int64_t epochMilliseconds = instant.floorToMilliseconds();
|
||||
double epochMilliseconds = double(instant.floorToMilliseconds());
|
||||
|
||||
// Step 4.
|
||||
int32_t year = JS::YearFromTime(epochMilliseconds);
|
||||
int32_t year = int32_t(JS::YearFromTime(epochMilliseconds));
|
||||
|
||||
// Step 5.
|
||||
int32_t month = JS::MonthFromTime(epochMilliseconds) + 1;
|
||||
int32_t month = int32_t(JS::MonthFromTime(epochMilliseconds)) + 1;
|
||||
|
||||
// Step 6.
|
||||
int32_t day = JS::DayFromTime(epochMilliseconds);
|
||||
int32_t day = int32_t(JS::DayFromTime(epochMilliseconds));
|
||||
|
||||
// Step 7.
|
||||
int32_t hour = HourFromTime(epochMilliseconds);
|
||||
int32_t hour = int32_t(HourFromTime(epochMilliseconds));
|
||||
|
||||
// Step 8.
|
||||
int32_t minute = MinFromTime(epochMilliseconds);
|
||||
int32_t minute = int32_t(MinFromTime(epochMilliseconds));
|
||||
|
||||
// Step 9.
|
||||
int32_t second = SecFromTime(epochMilliseconds);
|
||||
int32_t second = int32_t(SecFromTime(epochMilliseconds));
|
||||
|
||||
// Step 10.
|
||||
int32_t millisecond = msFromTime(epochMilliseconds);
|
||||
int32_t millisecond = int32_t(msFromTime(epochMilliseconds));
|
||||
|
||||
// Step 11.
|
||||
int32_t microsecond = remainderNs / 1000;
|
||||
|
|
|
@ -169,7 +169,7 @@ static void FormatFractionalSeconds(TemporalStringBuilder& result,
|
|||
result.append('.');
|
||||
|
||||
// Steps 1.b-c.
|
||||
uint32_t k = 100'000'000;
|
||||
int32_t k = 100'000'000;
|
||||
do {
|
||||
result.append(char('0' + (subSecondNanoseconds / k)));
|
||||
subSecondNanoseconds %= k;
|
||||
|
@ -186,7 +186,7 @@ static void FormatFractionalSeconds(TemporalStringBuilder& result,
|
|||
result.append('.');
|
||||
|
||||
// Steps 2.b-c.
|
||||
uint32_t k = 100'000'000;
|
||||
int32_t k = 100'000'000;
|
||||
for (uint8_t i = 0; i < p; i++) {
|
||||
result.append(char('0' + (subSecondNanoseconds / k)));
|
||||
subSecondNanoseconds %= k;
|
||||
|
@ -274,7 +274,7 @@ static int32_t RoundNanosecondsToMinutes(int64_t offsetNanoseconds) {
|
|||
if (std::abs(remainder * 2) >= increment) {
|
||||
quotient += (offsetNanoseconds > 0 ? 1 : -1);
|
||||
}
|
||||
return quotient;
|
||||
return int32_t(quotient);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче