Uh oh!
There was an error while loading. Please reload this page.
[wasm] Throw exception if culture data does not exist in icu - #47301
Conversation
ghost
commented
Jan 21, 2021
Uh oh!
There was an error while loading. Please reload this page.
Add PredefinedOnly GlobalizationMode Modified tests if Culture Data not found
| internal static bool UseNls => false; | ||
| internal static bool PredefinedOnly { get; } = GetSwitchValue("System.Globalization.PredefinedOnly", "DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY"); |
There was a problem hiding this comment.
PredefinedOnly [](start = 29, length = 14)
are you adding this for Linux only? looks the calling site will call it even running on Windows. maybe you need to move this to the file GlobalizationMode.cs?
There was a problem hiding this comment.
Why we need to restrict this to the browser only? We may enable this flag globally if we need to. Note the calling site of this property is called from shared code which runs with ICU and Nls. Give me a few minutes and I can send you what I propose.
Also, does the browser always runs with Icu?
There was a problem hiding this comment.
I guess I just assumed only Browser would need this use case, but I can definitely move to GlobalizationMode.cs. And yes, the browser always runs with icu.
There was a problem hiding this comment.
I would suggest to move the checks
and
to its own methods, something like
[MethodImpl(MethodImplOptions.AggressiveInlining)]internalstaticIcuIsEnsurePredefinedLocaleName(stringname)// may put this in CultureData.Icu.cs{Debug.Assert(!GlobalizationMode.UseNls);if(!Interop.Globalization.IsPredefinedLocale(name)){thrownewCultureNotFoundException(nameof(name),SR.Format(SR.Argument_InvalidPredefinedCultureName,name));}}[MethodImpl(MethodImplOptions.AggressiveInlining)]internalstaticNlsIsEnsurePredefinedLocaleName(stringname)// may put this in CultureData.Nls.cs{Debug.Assert(GlobalizationMode.UseNls);if(CultureData.GetLocaleInfoExInt(name,Interop.Kernel32.LOCALE_ICONSTRUCTEDLOCALE)==1){thrownewCultureNotFoundException(nameof(name),SR.Format(SR.Argument_InvalidPredefinedCultureName,name));}}Then replace the code here with
if(GlobalizationMode.PredefinedOnly){if(GlobalizationMode.UseNls){NlsIsEnsurePredefinedLocaleName(cultureName);}else{IcuIsEnsurePredefinedLocaleName(cultureName);}}Last, replace the checks in the links I mentioned above with the new methods calls. and move the code in GlobalizationMode.Unix.cs to GlobalizationMode.cs.
| this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1"); | ||
| // Set globalization mode to PredefinedOnly | ||
| this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_ONLY", "1"); |
There was a problem hiding this comment.
Why is it env variable if it's always set?
There was a problem hiding this comment.
Just leaving the option open if we don't want it always set.
There was a problem hiding this comment.
This won't be easy to change and it'll cost us on size. I think we should just compile the setting in
There was a problem hiding this comment.
We want it always set for wasm but I'm not sure if other OS want this option by default. @tarekgh
There was a problem hiding this comment.
outside WASM, we shouldn't turn this option on by default. Whoever need it would need to opt-in to get it.
There was a problem hiding this comment.
We could do this by setting a default value for the flag and making that default value be true for wasm based on an OS check when you are setting the PredefinedCulturesOnly flag. Or, just if def the code for WASM to always be ON.
There was a problem hiding this comment.
Here is a place where we do something similar for WASM:
So we could do something like:
GetSwitchValue("System.Globalization.PredefinedCulturesOnly","DOTNET_SYSTEM_GLOBALIZATION_PREDEFINED_CULTURES_ONLY")||OperatingSystem.IsBrowser()tarekgh
commented
Jan 22, 2021
CC @safern |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Could you please replace the checks in and with the new introduced method calls? thank you! |
tarekgh
commented
Jan 22, 2021
One last ask, could you please add a new test (not specific to the browser) to test the new environment variable? here is some test example which doing similar idea (testing setting environment variable). |
Modify Globalization tests to catch unsupported locales Change var names
tqiu8
commented
Jan 25, 2021
I don't think RemoteExcutor or System.Diagnostics.Process are supported on wasm right now. I'm going to store the current env var and reset it back to that after the test? |
tarekgh
commented
Jan 25, 2021
Yes, just exclude the added test from running on WASM. just mark the test with the attribute |
…est data to indicate whether or not that locale is expected to throw exception on browser
Uh oh!
There was an error while loading. Please reload this page.
tqiu8
commented
Mar 3, 2021
Thank you so much for your feedback! |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
lewing
commented
Mar 5, 2021
This is looking good but the failures look like they might be related. |
…Tests/Assembly/AssemblyTests.cs Co-authored-by: Larry Ewing <lewing@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Fix#47068
Fix#46327
Throw exception if culture data doesn't exist. Currently defaults to
en-us.