DetachedStateBase.h 1.7 KB

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