DetachedStateBase.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. class DetachedStateBase
  9. {
  10. protected:
  11. TypeId typeId;
  12. bool hasBeenClaimed;
  13. public:
  14. DetachedStateBase(TypeId typeId)
  15. : typeId(typeId),
  16. hasBeenClaimed(false)
  17. {
  18. }
  19. virtual ~DetachedStateBase()
  20. {
  21. }
  22. TypeId GetTypeId() { return typeId; }
  23. bool HasBeenClaimed() { return hasBeenClaimed; }
  24. void MarkAsClaimed() { hasBeenClaimed = true; }
  25. void CleanUp()
  26. {
  27. if (!hasBeenClaimed)
  28. {
  29. DiscardState();
  30. }
  31. ClearSelfOnly();
  32. }
  33. virtual void ClearSelfOnly() = 0;
  34. virtual void DiscardState() = 0;
  35. virtual void Discard() = 0;
  36. };
  37. typedef enum ArrayBufferAllocationType
  38. {
  39. Heap = 0x0,
  40. CoTask = 0x1,
  41. MemAlloc = 0x02
  42. } ArrayBufferAllocationType;
  43. class ArrayBufferDetachedStateBase : public DetachedStateBase
  44. {
  45. public:
  46. BYTE* buffer;
  47. uint32 bufferLength;
  48. ArrayBufferAllocationType allocationType;
  49. ArrayBufferDetachedStateBase(TypeId typeId, BYTE* buffer, uint32 bufferLength, ArrayBufferAllocationType allocationType)
  50. : DetachedStateBase(typeId),
  51. buffer(buffer),
  52. bufferLength(bufferLength),
  53. allocationType(allocationType)
  54. {}
  55. };
  56. }