ES5ArrayIndexEnumerator.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ES5ArrayIndexEnumerator::ES5ArrayIndexEnumerator(ES5Array* arrayObject, EnumeratorFlags flags, ScriptContext* scriptContext)
  9. : JavascriptArrayIndexEnumeratorBase(arrayObject, flags, scriptContext)
  10. {
  11. Reset();
  12. }
  13. JavascriptString * ES5ArrayIndexEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes)
  14. {
  15. propertyId = Constants::NoProperty;
  16. if (!doneArray)
  17. {
  18. while (true)
  19. {
  20. if (index == dataIndex)
  21. {
  22. dataIndex = arrayObject->GetNextIndex(dataIndex);
  23. }
  24. if (index == descriptorIndex || !GetArray()->IsValidDescriptorToken(descriptorValidationToken))
  25. {
  26. Js::IndexPropertyDescriptor * pResultDescriptor = nullptr;
  27. void* tmpDescriptorValidationToken = nullptr;
  28. descriptorIndex = GetArray()->GetNextDescriptor(
  29. index, &pResultDescriptor, &tmpDescriptorValidationToken);
  30. this->descriptor = pResultDescriptor;
  31. this->descriptorValidationToken = tmpDescriptorValidationToken;
  32. }
  33. index = min(dataIndex, descriptorIndex);
  34. if (index >= initialLength) // End of array
  35. {
  36. doneArray = true;
  37. break;
  38. }
  39. if (!!(flags & EnumeratorFlags::EnumNonEnumerable)
  40. || index < descriptorIndex
  41. || (descriptor->Attributes & PropertyEnumerable))
  42. {
  43. if (attributes != nullptr)
  44. {
  45. if (index < descriptorIndex)
  46. {
  47. *attributes = PropertyEnumerable;
  48. }
  49. else
  50. {
  51. *attributes = descriptor->Attributes;
  52. }
  53. }
  54. return this->GetScriptContext()->GetIntegerString(index);
  55. }
  56. }
  57. }
  58. return nullptr;
  59. }
  60. void ES5ArrayIndexEnumerator::Reset()
  61. {
  62. initialLength = arrayObject->GetLength();
  63. dataIndex = JavascriptArray::InvalidIndex;
  64. descriptorIndex = JavascriptArray::InvalidIndex;
  65. descriptor = nullptr;
  66. descriptorValidationToken = nullptr;
  67. index = JavascriptArray::InvalidIndex;
  68. doneArray = false;
  69. }
  70. }