JavascriptErrorDebug.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #pragma once
  6. namespace Js
  7. {
  8. // Specialized Error Object, containing WinRT specific information.
  9. class JavascriptErrorDebug : public JavascriptError
  10. {
  11. protected:
  12. DEFINE_VTABLE_CTOR(JavascriptErrorDebug, JavascriptError);
  13. public:
  14. JavascriptErrorDebug(IErrorInfo* perrinfo, DynamicType* type, BOOL isExternalError = FALSE) :
  15. JavascriptError(type, isExternalError)
  16. {
  17. Assert(perrinfo);
  18. pErrorInfo = perrinfo;
  19. restrictedStrings.referenceStr = nullptr;
  20. restrictedStrings.restrictedErrStr = nullptr;
  21. restrictedStrings.capabilitySid = nullptr;
  22. }
  23. static bool Is(Var aValue);
  24. static JavascriptErrorDebug* FromVar(Var aValue)
  25. {
  26. AssertMsg(Is(aValue), "Ensure var is actually a 'JavascriptErrorDebug'");
  27. return static_cast<JavascriptErrorDebug *>(JavascriptError::FromVar(aValue));
  28. }
  29. // For differentiating between JavascriptError and JavascriptErrorDebug
  30. bool HasDebugInfo();
  31. void Finalize(bool isShutdown) override;
  32. void Dispose(bool isShutdown) override;
  33. static void __declspec(noreturn) MapAndThrowErrorWithInfo(ScriptContext* scriptContext, HRESULT hr);
  34. #ifdef ENABLE_PROJECTION
  35. static void ClearErrorInfo(ScriptContext* scriptContext);
  36. #endif
  37. static void SetErrorMessage(JavascriptError *pError, long errCode, PCWSTR varDescription, ScriptContext* scriptContext);
  38. void SetRestrictedErrorStrings(RestrictedErrorStrings * proerrstr)
  39. {
  40. Assert(proerrstr);
  41. restrictedStrings.referenceStr = proerrstr->referenceStr;
  42. restrictedStrings.restrictedErrStr = proerrstr->restrictedErrStr;
  43. restrictedStrings.capabilitySid = proerrstr->capabilitySid;
  44. }
  45. BSTR GetRestrictedErrorString()
  46. {
  47. if (restrictedStrings.restrictedErrStr)
  48. {
  49. return SysAllocString(restrictedStrings.restrictedErrStr);
  50. }
  51. return nullptr;
  52. }
  53. BSTR GetRestrictedErrorReference()
  54. {
  55. if (restrictedStrings.referenceStr)
  56. {
  57. return SysAllocString(restrictedStrings.referenceStr);
  58. }
  59. return nullptr;
  60. }
  61. BSTR GetCapabilitySid()
  62. {
  63. if (restrictedStrings.capabilitySid)
  64. {
  65. return SysAllocString(restrictedStrings.capabilitySid);
  66. }
  67. return nullptr;
  68. }
  69. IErrorInfo * GetRestrictedErrorInfo() { return pErrorInfo; }
  70. void SetErrorInfo();
  71. private:
  72. DEFINE_MARSHAL_OBJECT_TO_SCRIPT_CONTEXT(JavascriptErrorDebug);
  73. static void GetErrorTypeFromNumber(HRESULT hr, ErrorTypeEnum * errorTypeOut);
  74. static HRESULT GetExcepAndErrorInfo(ScriptContext* scriptContext, HRESULT hrReturned, EXCEPINFO *pexcepinfo, RestrictedErrorStrings * proerrstr, IErrorInfo ** pperrinfo);
  75. RestrictedErrorStrings restrictedStrings; // WinRT specific error strings
  76. IErrorInfo * pErrorInfo; // reference to the original IErrorInfo object
  77. static __declspec(thread) wchar_t msgBuff[512];
  78. };
  79. }