MutationBreakpoint.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #ifdef ENABLE_MUTATION_BREAKPOINT
  7. namespace Js
  8. {
  9. class MutationBreakpoint;
  10. class MutationBreakpointDelegate : public IMutationBreakpoint
  11. {
  12. MutationBreakpointDelegate(MutationBreakpoint *bp);
  13. ULONG m_refCount;
  14. MutationBreakpoint *m_breakpoint;
  15. bool m_didCauseBreak;
  16. PropertyRecord *m_propertyRecord;
  17. MutationType m_type;
  18. public:
  19. // Creates a new delegate object on the heap
  20. static MutationBreakpointDelegate * New(MutationBreakpoint *bp);
  21. // Get the breakpoint which the the delegate object associate with
  22. MutationBreakpoint * GetBreakpoint() const;
  23. /* IMutationBreakpoint methods */
  24. STDMETHODIMP_(ULONG) AddRef();
  25. STDMETHODIMP_(ULONG) Release();
  26. STDMETHODIMP QueryInterface(REFIID iid, void ** ppv);
  27. STDMETHODIMP Delete(void);
  28. STDMETHODIMP DidCauseBreak(
  29. /* [out] */ __RPC__out BOOL *didCauseBreak);
  30. };
  31. struct PropertyMutation
  32. {
  33. const PropertyRecord *pr;
  34. MutationType mFlag;
  35. };
  36. class MutationBreakpoint : FinalizableObject
  37. {
  38. bool isValid;
  39. bool didCauseBreak;
  40. MutationType mFlag;
  41. RecyclerWeakReference<DynamicObject> * obj;
  42. Var newValue;
  43. PropertyId parentPropertyId;
  44. const PropertyRecord *propertyRecord;
  45. typedef JsUtil::List<PropertyMutation, Recycler> PropertyMutationList;
  46. PropertyMutationList *properties;
  47. MutationBreakpointDelegate *mutationBreakpointDelegate;
  48. MutationType breakMutationType;
  49. void Break(ScriptContext *scriptContext, MutationType mutationType, const PropertyRecord *pr);
  50. MutationBreakpointDelegate * GetDelegate();
  51. bool DeleteProperty(PropertyRecord *pr);
  52. static MutationBreakpoint * New(ScriptContext *scriptContext, DynamicObject *obj, const Js::PropertyRecord *pr, MutationType type, Js::PropertyId parentPropertyId);
  53. public:
  54. MutationBreakpoint(ScriptContext *scriptContext, DynamicObject *obj, const PropertyRecord *pr, MutationType type, Js::PropertyId parentPropertyId);
  55. ~MutationBreakpoint();
  56. bool IsValid() const;
  57. void Invalidate();
  58. // Invalidate(), release delegate, and remove strong reference from DynamicObject
  59. bool Reset();
  60. void SetBreak(MutationType type, const PropertyRecord *pr);
  61. bool ShouldBreak(MutationType type);
  62. bool ShouldBreak(MutationType type, PropertyId pid);
  63. bool GetDidCauseBreak() const;
  64. const PropertyId GetBreakPropertyId() const;
  65. const char16 * GetBreakPropertyName() const;
  66. const PropertyId GetParentPropertyId() const;
  67. const char16 * GetParentPropertyName() const;
  68. MutationType GetBreakMutationType() const;
  69. const Var GetMutationObjectVar() const;
  70. const Var GetBreakNewValueVar() const;
  71. /* Static methods */
  72. // Whether mutation breakpoint is enabled (and if debug is enabled on scriptContext)
  73. static bool IsFeatureEnabled();
  74. static bool IsFeatureEnabled(ScriptContext *scriptContext);
  75. // Whether a mutation breakpoint could be set on an object
  76. static bool CanSet(Var object);
  77. // Setting a mutation breakpoint on an object/property of an object
  78. static MutationBreakpointDelegate * Set(ScriptContext *scriptContext, Var obj, BOOL setOnObject, MutationType type, PropertyId parentPropertyId, PropertyId propertyId);
  79. // Mutation handlers
  80. static bool HandleSetProperty(ScriptContext *scriptContext, RecyclableObject *object, PropertyId propertyId, Var newValue);
  81. static void HandleDeleteProperty(ScriptContext *scriptContext, Var instance, PropertyId propertyId);
  82. static void HandleDeleteProperty(ScriptContext *scriptContext, Var instance, JavascriptString *propertyNameString);
  83. static const char16 * GetBreakMutationTypeName(MutationType mutationType);
  84. static const char16 * GetMutationTypeForConditionalEval(MutationType mutationType);
  85. /* Override methods - FinalizableObject */
  86. virtual void Finalize(bool isShutdown);
  87. virtual void Dispose(bool isShutdown);
  88. virtual void Mark(Recycler * recycler);
  89. };
  90. }
  91. #endif