JavascriptExceptionContext.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. class JavascriptExceptionContext
  8. {
  9. public:
  10. struct StackFrame
  11. {
  12. private:
  13. // Real script frames: functionBody, byteCodeOffset
  14. // Native library builtin (or potentially virtual) frames: name
  15. Field(FunctionBody*) functionBody;
  16. union
  17. {
  18. Field(uint32) byteCodeOffset; // used for script functions (functionBody != nullptr)
  19. Field(PCWSTR) name; // used for native/virtual frames (functionBody == nullptr)
  20. };
  21. Field(StackTraceArguments) argumentTypes;
  22. public:
  23. StackFrame() {}
  24. StackFrame(JavascriptFunction* func, const JavascriptStackWalker& walker, bool initArgumentTypes);
  25. StackFrame(const StackFrame& other)
  26. :functionBody(other.functionBody), name(other.name), argumentTypes(other.argumentTypes)
  27. {}
  28. StackFrame& operator=(const StackFrame& other)
  29. {
  30. functionBody = other.functionBody;
  31. name = other.name;
  32. argumentTypes = other.argumentTypes;
  33. return *this;
  34. }
  35. bool IsScriptFunction() const;
  36. FunctionBody* GetFunctionBody() const;
  37. uint32 GetByteCodeOffset() const { return byteCodeOffset; }
  38. LPCWSTR GetFunctionName() const;
  39. HRESULT GetFunctionNameWithArguments(_In_ LPCWSTR *outResult) const;
  40. };
  41. typedef JsUtil::List<StackFrame> StackTrace;
  42. public:
  43. JavascriptExceptionContext() :
  44. m_throwingFunction(nullptr),
  45. m_throwingFunctionByteCodeOffset(0),
  46. m_stackTrace(nullptr),
  47. m_originalStackTrace(nullptr)
  48. {
  49. }
  50. JavascriptFunction* ThrowingFunction() const { return m_throwingFunction; }
  51. uint32 ThrowingFunctionByteCodeOffset() const { return m_throwingFunctionByteCodeOffset; }
  52. void SetThrowingFunction(JavascriptFunction* function, uint32 byteCodeOffset, void * returnAddress);
  53. bool HasStackTrace() const { return m_stackTrace && m_stackTrace->Count() > 0; }
  54. StackTrace* GetStackTrace() const { return m_stackTrace; }
  55. void SetStackTrace(StackTrace *stackTrace) { m_stackTrace = stackTrace; }
  56. void SetOriginalStackTrace(StackTrace *stackTrace) { Assert(m_originalStackTrace == nullptr); m_originalStackTrace = stackTrace; }
  57. StackTrace* GetOriginalStackTrace() const { return m_originalStackTrace; }
  58. private:
  59. Field(JavascriptFunction*) m_throwingFunction;
  60. Field(uint32) m_throwingFunctionByteCodeOffset;
  61. Field(StackTrace *) m_stackTrace;
  62. Field(StackTrace *) m_originalStackTrace;
  63. };
  64. }