DetachedStateBase.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. External = 0x03,
  43. } ArrayBufferAllocationType;
  44. class ArrayBufferDetachedStateBase : public DetachedStateBase
  45. {
  46. public:
  47. BYTE* buffer;
  48. uint32 bufferLength;
  49. ArrayBufferAllocationType allocationType;
  50. ArrayBufferDetachedStateBase(TypeId typeId, BYTE* buffer, uint32 bufferLength, ArrayBufferAllocationType allocationType)
  51. : DetachedStateBase(typeId),
  52. buffer(buffer),
  53. bufferLength(bufferLength),
  54. allocationType(allocationType)
  55. {}
  56. };
  57. }