DetachedStateBase.h 1.7 KB

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