mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-22 10:27:03 +00:00
Bug 1560038 - Use i64 for storing epoch instead of usize. r=emilio
epoch is stored as double in ICU. Storing it as usize caused overflow on 32-bit Windows 7 which resulted in dates being formatted to epoch=0. This patch switches to use f64 on the Rust side. Depends on D66504 Differential Revision: https://phabricator.services.mozilla.com/D66872 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ea853ecb4b
commit
e137e48a88
@ -78,8 +78,9 @@ already_AddRefed<FluentBundle> FluentBundle::Constructor(
|
||||
}
|
||||
|
||||
if (!raw) {
|
||||
aRv.ThrowInvalidStateError("Failed to create the FluentBundle. Check the "
|
||||
"locales and pseudo strategy arguments.");
|
||||
aRv.ThrowInvalidStateError(
|
||||
"Failed to create the FluentBundle. Check the "
|
||||
"locales and pseudo strategy arguments.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -177,8 +178,9 @@ void FluentBundle::FormatPattern(JSContext* aCx, const FluentPattern& aPattern,
|
||||
&argValues, &aRetVal, &errors);
|
||||
|
||||
if (!succeeded) {
|
||||
return aRv.ThrowInvalidStateError("Failed to format the FluentPattern. Likely the "
|
||||
"pattern could not be retrieved from the bundle.");
|
||||
return aRv.ThrowInvalidStateError(
|
||||
"Failed to format the FluentPattern. Likely the "
|
||||
"pattern could not be retrieved from the bundle.");
|
||||
}
|
||||
|
||||
if (aErrors.WasPassed()) {
|
||||
@ -208,8 +210,7 @@ ffi::RawNumberFormatter* FluentBuiltInNumberFormatterCreate(
|
||||
|
||||
if (aOptions->style == ffi::FluentNumberStyleRaw::Currency) {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
formatter =
|
||||
formatter.unit(icu::CurrencyUnit(aOptions->currency.get(), ec));
|
||||
formatter = formatter.unit(icu::CurrencyUnit(aOptions->currency.get(), ec));
|
||||
MOZ_ASSERT(U_SUCCESS(ec), "Failed to format the currency unit.");
|
||||
}
|
||||
if (aOptions->style == ffi::FluentNumberStyleRaw::Percent) {
|
||||
@ -234,14 +235,17 @@ ffi::RawNumberFormatter* FluentBuiltInNumberFormatterCreate(
|
||||
formatter.locale(aLocale->get()).clone().orphan());
|
||||
}
|
||||
|
||||
uint8_t* FluentBuiltInNumberFormatterFormat(const ffi::RawNumberFormatter* aFormatter,
|
||||
double input, uint32_t* aOutCount) {
|
||||
uint8_t* FluentBuiltInNumberFormatterFormat(
|
||||
const ffi::RawNumberFormatter* aFormatter, double input,
|
||||
uint32_t* aOutCount) {
|
||||
auto formatter =
|
||||
reinterpret_cast<const icu::number::LocalizedNumberFormatter*>(aFormatter);
|
||||
reinterpret_cast<const icu::number::LocalizedNumberFormatter*>(
|
||||
aFormatter);
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
icu::number::FormattedNumber result = formatter->formatDouble(input, ec);
|
||||
icu::UnicodeString str = result.toTempString(ec);
|
||||
return reinterpret_cast<uint8_t*>(ToNewUTF8String(nsDependentSubstring(str.getBuffer(), str.length()), aOutCount));
|
||||
return reinterpret_cast<uint8_t*>(ToNewUTF8String(
|
||||
nsDependentSubstring(str.getBuffer(), str.length()), aOutCount));
|
||||
}
|
||||
|
||||
void FluentBuiltInNumberFormatterDestroy(ffi::RawNumberFormatter* aFormatter) {
|
||||
@ -297,14 +301,16 @@ ffi::RawDateTimeFormatter* FluentBuiltInDateTimeFormatterCreate(
|
||||
return reinterpret_cast<ffi::RawDateTimeFormatter*>(dtmf);
|
||||
}
|
||||
|
||||
uint8_t* FluentBuiltInDateTimeFormatterFormat(const ffi::RawDateTimeFormatter* aFormatter,
|
||||
uintptr_t input, uint32_t* aOutCount) {
|
||||
uint8_t* FluentBuiltInDateTimeFormatterFormat(
|
||||
const ffi::RawDateTimeFormatter* aFormatter, double input,
|
||||
uint32_t* aOutCount) {
|
||||
auto formatter = reinterpret_cast<const icu::DateFormat*>(aFormatter);
|
||||
UDate myDate = input;
|
||||
|
||||
icu::UnicodeString str;
|
||||
formatter->format(myDate, str);
|
||||
return reinterpret_cast<uint8_t*>(ToNewUTF8String(nsDependentSubstring(str.getBuffer(), str.length()), aOutCount));
|
||||
return reinterpret_cast<uint8_t*>(ToNewUTF8String(
|
||||
nsDependentSubstring(str.getBuffer(), str.length()), aOutCount));
|
||||
}
|
||||
|
||||
void FluentBuiltInDateTimeFormatterDestroy(
|
||||
|
@ -375,7 +375,7 @@ impl From<&FluentDateTimeOptions> for FluentDateTimeOptionsRaw {
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct FluentDateTime {
|
||||
epoch: usize,
|
||||
epoch: f64,
|
||||
options: FluentDateTimeOptions,
|
||||
}
|
||||
|
||||
@ -406,7 +406,7 @@ impl std::fmt::Display for FluentDateTime {
|
||||
}
|
||||
|
||||
impl FluentDateTime {
|
||||
pub fn new(epoch: usize, options: FluentDateTimeOptions) -> Self {
|
||||
pub fn new(epoch: f64, options: FluentDateTimeOptions) -> Self {
|
||||
Self { epoch, options }
|
||||
}
|
||||
}
|
||||
@ -436,7 +436,7 @@ impl DateTimeFormat {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format(&self, input: usize) -> String {
|
||||
pub fn format(&self, input: f64) -> String {
|
||||
unsafe {
|
||||
let mut byte_count = 0;
|
||||
let buffer = ffi::FluentBuiltInDateTimeFormatterFormat(
|
||||
|
@ -118,8 +118,7 @@ pub unsafe extern "C" fn fluent_bundle_new(
|
||||
if let Some(FluentValue::Number(n)) = args.get(0) {
|
||||
let mut options = FluentDateTimeOptions::default();
|
||||
options.merge(&named);
|
||||
let epoch = n.value as usize;
|
||||
FluentValue::Custom(Box::new(FluentDateTime::new(epoch, options)))
|
||||
FluentValue::Custom(Box::new(FluentDateTime::new(n.value, options)))
|
||||
} else {
|
||||
FluentValue::None
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ extern "C" {
|
||||
) -> *mut RawDateTimeFormatter;
|
||||
pub fn FluentBuiltInDateTimeFormatterFormat(
|
||||
formatter: *const RawDateTimeFormatter,
|
||||
input: usize,
|
||||
input: f64,
|
||||
out_count: &mut u32,
|
||||
) -> *mut u8;
|
||||
pub fn FluentBuiltInDateTimeFormatterDestroy(formatter: *mut RawDateTimeFormatter);
|
||||
|
Loading…
x
Reference in New Issue
Block a user