Backed out changeset 41722eea7dd5 (bug 1623778) for causing failures in l10n/test/mochitest/localization/test_format

CLOSED TREE
This commit is contained in:
Mihai Alexandru Michis 2020-03-21 04:28:33 +02:00
parent 54d91e0818
commit 63f586a915
2 changed files with 26 additions and 51 deletions

View File

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FluentBundle.h"
#include "nsContentUtils.h"
#include "mozilla/dom/UnionTypes.h"
#include "unicode/numberformatter.h"
#include "unicode/datefmt.h"
@ -103,16 +102,7 @@ void FluentBundle::AddResource(
FluentResource& aResource,
const dom::FluentBundleAddResourceOptions& aOptions) {
bool allowOverrides = aOptions.mAllowOverrides;
nsTArray<nsCString> errors;
fluent_bundle_add_resource(mRaw.get(), aResource.Raw(), allowOverrides,
&errors);
for (auto& err : errors) {
nsContentUtils::LogSimpleConsoleError(NS_ConvertUTF8toUTF16(err), "L10n",
false, true,
nsIScriptError::warningFlag);
}
fluent_bundle_add_resource(mRaw.get(), aResource.Raw(), allowOverrides);
}
bool FluentBundle::HasMessage(const nsACString& aId) {

View File

@ -213,7 +213,29 @@ pub unsafe extern "C" fn fluent_bundle_format_pattern(
let mut errors = vec![];
let value = bundle.format_pattern(pattern, args.as_ref(), &mut errors);
ret_val.assign(value.as_bytes());
append_fluent_errors_to_ret_errors(ret_errors, &errors);
for error in errors {
match error {
FluentError::ResolverError(ref err) => match err {
ResolverError::Reference(ref s) => {
let error = format!("ReferenceError: {}", s);
ret_errors.push((&error).into());
}
ResolverError::MissingDefault => {
let error = "RangeError: No default";
ret_errors.push(error.into());
}
ResolverError::Cyclic => {
let error = "RangeError: Cyclic reference";
ret_errors.push(error.into());
}
ResolverError::TooManyPlaceables => {
let error = "RangeError: Too many placeables";
ret_errors.push(error.into());
}
},
_ => panic!("Unknown error!"),
}
}
true
}
@ -222,15 +244,14 @@ pub unsafe extern "C" fn fluent_bundle_add_resource(
bundle: &mut FluentBundleRc,
r: &FluentResource,
allow_overrides: bool,
ret_errors: &mut ThinVec<nsCString>,
) {
// we don't own the resource
let r = mem::ManuallyDrop::new(Rc::from_raw(r));
if allow_overrides {
bundle.add_resource_overriding(Rc::clone(&r));
} else if let Err(errors) = bundle.add_resource(Rc::clone(&r)) {
append_fluent_errors_to_ret_errors(ret_errors, &errors);
} else if bundle.add_resource(Rc::clone(&r)).is_err() {
eprintln!("Error while adding a resource");
}
}
@ -251,39 +272,3 @@ fn convert_args<'a>(ids: &'a [String], arg_vals: &'a [FluentArgument]) -> Option
}
Some(args)
}
fn append_fluent_errors_to_ret_errors(ret_errors: &mut ThinVec<nsCString>, errors: &[FluentError]) {
for error in errors {
match error {
FluentError::ResolverError(ref err) => match err {
ResolverError::Reference(ref s) => {
let error = format!("[fluent] ReferenceError: {}.", s);
ret_errors.push(error.into());
}
ResolverError::MissingDefault => {
let error = "[fluent] RangeError: No default value for selector.";
ret_errors.push(error.into());
}
ResolverError::Cyclic => {
let error = "[fluent] RangeError: Cyclic reference encountered while resolving a message.";
ret_errors.push(error.into());
}
ResolverError::TooManyPlaceables => {
let error = "[fluent] RangeError: Too many placeables in a message.";
ret_errors.push(error.into());
}
},
FluentError::Overriding { kind, id } => {
let error = format!("[fluent] OverrideError: An entry {} of type {} is already defined in this bundle.", id, kind);
ret_errors.push(error.into());
}
FluentError::ParserError(pe) => {
let error = format!(
"[fluent] ParserError: Error of kind {:#?} in position: ({}, {})",
pe.kind, pe.pos.0, pe.pos.1
);
ret_errors.push(error.into());
}
}
}
}