JavascriptArrayIndexEnumerator.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. JavascriptArrayIndexEnumerator::JavascriptArrayIndexEnumerator(
  9. JavascriptArray* arrayObject, EnumeratorFlags flags, ScriptContext* scriptContext) :
  10. JavascriptArrayIndexEnumeratorBase(arrayObject, flags, scriptContext)
  11. {
  12. #if ENABLE_COPYONACCESS_ARRAY
  13. JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(arrayObject);
  14. #endif
  15. Reset();
  16. }
  17. JavascriptString * JavascriptArrayIndexEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes)
  18. {
  19. // TypedArrayIndexEnumerator follow the same logic but implementation is slightly
  20. // different as we don't have sparse array in typed array, and typed array
  21. // is DynamicObject instead of JavascriptArray.
  22. propertyId = Constants::NoProperty;
  23. if (!doneArray)
  24. {
  25. while (true)
  26. {
  27. uint32 lastIndex = index;
  28. index = arrayObject->GetNextIndex(index);
  29. if (index == JavascriptArray::InvalidIndex) // End of array
  30. {
  31. index = lastIndex;
  32. doneArray = true;
  33. break;
  34. }
  35. if (attributes != nullptr)
  36. {
  37. *attributes = PropertyEnumerable;
  38. }
  39. return this->GetScriptContext()->GetIntegerString(index);
  40. }
  41. }
  42. return nullptr;
  43. }
  44. void JavascriptArrayIndexEnumerator::Reset()
  45. {
  46. index = JavascriptArray::InvalidIndex;
  47. doneArray = false;
  48. }
  49. }