JavascriptArrayIndexEnumerator.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. //
  9. // An enumerator to enumerate JavascriptArray index property names as uint32 indices.
  10. //
  11. class JavascriptArrayIndexEnumerator
  12. {
  13. public:
  14. typedef JavascriptArray ArrayType;
  15. private:
  16. JavascriptArray* m_array; // The JavascriptArray to enumerate on
  17. uint32 m_index; // Current index
  18. public:
  19. JavascriptArrayIndexEnumerator(JavascriptArray* array)
  20. : m_array(array)
  21. {
  22. Reset();
  23. }
  24. //
  25. // Reset to enumerate from beginning.
  26. //
  27. void Reset()
  28. {
  29. m_index = JavascriptArray::InvalidIndex;
  30. }
  31. //
  32. // Get the current index. Valid only when MoveNext() returns true.
  33. //
  34. uint32 GetIndex() const
  35. {
  36. return m_index;
  37. }
  38. //
  39. // Move to next index. If successful, use GetIndex() to get the index.
  40. //
  41. bool MoveNext(PropertyAttributes* attributes = nullptr)
  42. {
  43. m_index = m_array->GetNextIndex(m_index);
  44. if (m_index != JavascriptArray::InvalidIndex)
  45. {
  46. if (attributes != nullptr)
  47. {
  48. *attributes = PropertyEnumerable;
  49. }
  50. return true;
  51. }
  52. return false;
  53. }
  54. };
  55. }