Skip to content

Commit e8e9baa

Browse files
committed
[MERGE #5375 @dilijev] OS#10368428: Failfast if IsExternalUnicodeLibraryAvailable would return false.
Merge pull request #5375 from dilijev:fatal-unicode-lib-unavailable The only caller of IsExternalUnicodeLibraryAvailable (Js::CharClassifier::CharClassifier) will failfast when this method returns false, so move the failfast closer the cause of the problem to improve diagnosis and attribution by stack. Also create a specific failfast type for this failure mode to improve attribution.
2 parents 42ed4d4 + fab6267 commit e8e9baa

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

lib/Common/Exceptions/Throw.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ namespace Js {
7777
ReportFatalException(NULL, E_FAIL, Fatal_Internal_Error, scenario);
7878
}
7979

80+
void Throw::FatalInternalGlobalizationError()
81+
{
82+
AssertMsg(false, "Failure in initializing Globalization library");
83+
int scenario = 2;
84+
ReportFatalException(NULL, E_FAIL, Fatal_Internal_Error, scenario);
85+
}
86+
8087
void Throw::FatalProjectionError()
8188
{
8289
RaiseException((DWORD)DBG_TERMINATE_PROCESS, EXCEPTION_NONCONTINUABLE, 0, NULL);

lib/Common/Exceptions/Throw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace Js {
2121
static void __declspec(noreturn) InternalError();
2222
static void __declspec(noreturn) FatalInternalError();
2323
static void __declspec(noreturn) FatalInternalErrorEx(int scenario);
24+
static void __declspec(noreturn) FatalInternalGlobalizationError();
25+
2426
static void __declspec(noreturn) FatalProjectionError();
2527
#if ENABLE_JS_REENTRANCY_CHECK
2628
static void __declspec(noreturn) FatalJsReentrancyError();

lib/Parser/CharClassifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,11 @@ Js::CharClassifier::CharClassifier(void)
411411
bool isES6UnicodeModeEnabled = CONFIG_FLAG(ES6Unicode);
412412
bool isFullUnicodeSupportAvailable = PlatformAgnostic::UnicodeText::IsExternalUnicodeLibraryAvailable();
413413

414-
#ifdef NTBUILD
414+
#if INTL_ICU || INTL_WINGLOB // don't assert in _no_icu builds (where there is no i18n library, by design)
415415
AssertMsg(isFullUnicodeSupportAvailable, "Windows.Globalization needs to present with IUnicodeCharacterStatics support for Chakra.dll to work");
416416
if (!isFullUnicodeSupportAvailable)
417417
{
418-
Js::Throw::FatalInternalError();
418+
Js::Throw::FatalInternalGlobalizationError();
419419
}
420420
#endif
421421

@@ -450,7 +450,6 @@ Js::CharClassifier::CharClassifier(void)
450450
getBigCharFlagsFunc = &CharClassifier::GetBigCharFlagsES5;
451451
}
452452
#endif
453-
454453
}
455454

456455
const OLECHAR* Js::CharClassifier::SkipWhiteSpaceNonSurrogate(LPCOLESTR psz, const CharClassifier *instance)

lib/Runtime/PlatformAgnostic/Platform/Windows/UnicodeText.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,31 @@ namespace PlatformAgnostic
399399
Js::WindowsGlobalizationAdapter* globalizationAdapter = threadContext->GetWindowsGlobalizationAdapter();
400400
Js::DelayLoadWindowsGlobalization* globLibrary = threadContext->GetWindowsGlobalizationLibrary();
401401
HRESULT hr = globalizationAdapter->EnsureDataTextObjectsInitialized(globLibrary);
402-
// Failed to load windows.globalization.dll or jsintl.dll. No unicodeStatics support
403-
// in that case.
402+
// Failed to load windows.globalization.dll or jsintl.dll. No unicodeStatics support in that case.
404403
if (SUCCEEDED(hr))
405404
{
406405
auto winGlobCharApi = globalizationAdapter->GetUnicodeStatics();
407406
if (winGlobCharApi != nullptr)
408407
{
409408
return true;
410409
}
410+
#if INTL_ICU || INTL_WINGLOB // don't assert in _no_icu builds (where there is no i18n library, by design)
411+
else
412+
{
413+
// did not find winGlobCharApi
414+
Js::Throw::FatalInternalGlobalizationError();
415+
}
416+
}
417+
else
418+
{
419+
// failed to initialize Windows Globalization
420+
Js::Throw::FatalInternalGlobalizationError();
421+
#endif
411422
}
412423

413-
return false;
424+
#if (INTL_ICU || INTL_WINGLOB) && !defined(DBG)
425+
return false; // in debug builds, this is unreachable code
426+
#endif
414427
}, false);
415428
}
416429

0 commit comments

Comments
 (0)