rterror.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "ParserPch.h"
  6. // PUBLIC ERROR codes
  7. // verify HR is as-expected for the Legacy (private) error JSERR_CantExecute
  8. C_ASSERT(JSCRIPT_E_CANTEXECUTE != JSERR_CantExecute);
  9. // verify the HR value (as MAKE_HRESULT(SEVERITY_ERROR, FACILITY_CONTROL, 0x1393))
  10. C_ASSERT(JSERR_CantExecute == 0x800A1393);
  11. // verify HR matches between public SDK and private (.h) files
  12. C_ASSERT(JSCRIPT_E_CANTEXECUTE == JSPUBLICERR_CantExecute);
  13. // verify the HR value (as MAKE_HRESULT(SEVERITY_ERROR, FACILITY_JSCRIPT, 0x0001))
  14. C_ASSERT(JSPUBLICERR_CantExecute == _HRESULT_TYPEDEF_(0x89020001L));
  15. // /PUBLIC ERROR codes
  16. // boundary check - all errNum should be capped to 10,000 (RTERROR_STRINGFORMAT_OFFSET) - except for VBSERR_CantDisplayDate==32812
  17. #define VERIFY_BOUNDARY_ERRNUM(name,errnum) C_ASSERT(name == VBSERR_CantDisplayDate || errnum < RTERROR_STRINGFORMAT_OFFSET);
  18. #define RT_ERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) VERIFY_BOUNDARY_ERRNUM(name, errnum)
  19. #define RT_PUBLICERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) VERIFY_BOUNDARY_ERRNUM(name, errnum)
  20. #include "rterrors.h"
  21. #undef RT_PUBLICERROR_MSG
  22. #undef RT_ERROR_MSG
  23. //------------------------------------------------------------------------------
  24. // xplat: simulate resource strings
  25. #ifndef _WIN32
  26. #include <rterrors_limits.h>
  27. struct _ResourceStr
  28. {
  29. UINT id;
  30. const char16* str;
  31. };
  32. static _ResourceStr s_resourceStrs[] =
  33. {
  34. //
  35. // Copy from jserr.gen
  36. //
  37. #define RT_ERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) \
  38. { errnum, _u(str2) },
  39. #define RT_PUBLICERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) \
  40. { errnum + RTERROR_PUBLIC_RESOURCEOFFSET, _u(str2) },
  41. #include <rterrors.h>
  42. #undef RT_PUBLICERROR_MSG
  43. #undef RT_ERROR_MSG
  44. #define RT_ERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) \
  45. { errnum + RTERROR_STRINGFORMAT_OFFSET, _u(str1) },
  46. #define RT_PUBLICERROR_MSG(name, errnum, str1, str2, jst, errorNumSource) \
  47. { errnum + RTERROR_STRINGFORMAT_OFFSET + RTERROR_PUBLIC_RESOURCEOFFSET, \
  48. _u(str1) },
  49. #include <rterrors.h>
  50. #undef RT_PUBLICERROR_MSG
  51. #undef RT_ERROR_MSG
  52. #define LSC_ERROR_MSG(errnum, name, str) \
  53. { errnum, _u(str) },
  54. #include <perrors.h>
  55. #undef LSC_ERROR_MSG
  56. { IDS_COMPILATION_ERROR_SOURCE, _u("JavaScript compilation error") },
  57. { IDS_RUNTIME_ERROR_SOURCE, _u("JavaScript runtime error") },
  58. { IDS_UNKNOWN_RUNTIME_ERROR, _u("Unknown runtime error") },
  59. { IDS_INFINITY, _u("Infinity") },
  60. { IDS_MINUSINFINITY, _u("-Infinity") }
  61. };
  62. static int compare_ResourceStr(const void* a, const void* b)
  63. {
  64. UINT id1 = reinterpret_cast<const _ResourceStr*>(a)->id;
  65. UINT id2 = reinterpret_cast<const _ResourceStr*>(b)->id;
  66. return id1 - id2;
  67. }
  68. static bool s_resourceStrsSorted = false;
  69. const char16* LoadResourceStr(UINT id)
  70. {
  71. if (!s_resourceStrsSorted)
  72. {
  73. qsort(s_resourceStrs,
  74. _countof(s_resourceStrs), sizeof(s_resourceStrs[0]),
  75. compare_ResourceStr);
  76. s_resourceStrsSorted = true;
  77. }
  78. _ResourceStr key = { id, nullptr };
  79. const void* p = bsearch(&key,
  80. s_resourceStrs, _countof(s_resourceStrs), sizeof(s_resourceStrs[0]),
  81. compare_ResourceStr);
  82. return p ? reinterpret_cast<const _ResourceStr*>(p)->str : nullptr;
  83. }
  84. #endif