JavascriptArrayIndexStaticEnumerator.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 JavascriptArrayIndexStaticEnumerator
  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. JavascriptArrayIndexStaticEnumerator(JavascriptArray* array)
  20. : m_array(array)
  21. {
  22. #if ENABLE_COPYONACCESS_ARRAY
  23. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(m_array);
  24. #endif
  25. Reset();
  26. }
  27. //
  28. // Reset to enumerate from beginning.
  29. //
  30. void Reset()
  31. {
  32. m_index = JavascriptArray::InvalidIndex;
  33. }
  34. //
  35. // Get the current index. Valid only when MoveNext() returns true.
  36. //
  37. uint32 GetIndex() const
  38. {
  39. return m_index;
  40. }
  41. //
  42. // Move to next index. If successful, use GetIndex() to get the index.
  43. //
  44. bool MoveNext()
  45. {
  46. m_index = m_array->GetNextIndex(m_index);
  47. if (m_index != JavascriptArray::InvalidIndex)
  48. {
  49. return true;
  50. }
  51. return false;
  52. }
  53. };
  54. }