JavascriptArrayIndexSnapshotEnumerator.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "RuntimeLibraryPch.h"
  6. namespace Js
  7. {
  8. JavascriptArrayIndexSnapshotEnumerator::JavascriptArrayIndexSnapshotEnumerator(
  9. JavascriptArray* arrayObject, EnumeratorFlags flags, ScriptContext* scriptContext) :
  10. JavascriptArrayIndexEnumeratorBase(arrayObject, flags, scriptContext),
  11. initialLength(arrayObject->GetLength())
  12. {
  13. Reset();
  14. }
  15. Var JavascriptArrayIndexSnapshotEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes)
  16. {
  17. propertyId = Constants::NoProperty;
  18. if (!doneArray)
  19. {
  20. uint32 lastIndex = index;
  21. index = arrayObject->GetNextIndex(index);
  22. if (index >= initialLength) // End of array
  23. {
  24. index = lastIndex;
  25. doneArray = true;
  26. }
  27. else
  28. {
  29. if (attributes != nullptr)
  30. {
  31. *attributes = PropertyEnumerable;
  32. }
  33. return this->GetScriptContext()->GetIntegerString(index);
  34. }
  35. }
  36. return nullptr;
  37. }
  38. void JavascriptArrayIndexSnapshotEnumerator::Reset()
  39. {
  40. index = JavascriptArray::InvalidIndex;
  41. doneArray = false;
  42. initialLength = arrayObject->GetLength();
  43. }
  44. }