-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathJavascriptArrayIndexEnumerator.cpp
More file actions
55 lines (49 loc) · 1.96 KB
/
JavascriptArrayIndexEnumerator.cpp
File metadata and controls
55 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "RuntimeLibraryPch.h"
namespace Js
{
JavascriptArrayIndexEnumerator::JavascriptArrayIndexEnumerator(
JavascriptArray* arrayObject, EnumeratorFlags flags, ScriptContext* scriptContext) :
JavascriptArrayIndexEnumeratorBase(arrayObject, flags, scriptContext)
{
#if ENABLE_COPYONACCESS_ARRAY
JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(arrayObject);
#endif
Reset();
}
JavascriptString * JavascriptArrayIndexEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes)
{
// TypedArrayIndexEnumerator follow the same logic but implementation is slightly
// different as we don't have sparse array in typed array, and typed array
// is DynamicObject instead of JavascriptArray.
propertyId = Constants::NoProperty;
if (!doneArray)
{
while (true)
{
uint32 lastIndex = index;
index = arrayObject->GetNextIndex(index);
if (index == JavascriptArray::InvalidIndex) // End of array
{
index = lastIndex;
doneArray = true;
break;
}
if (attributes != nullptr)
{
*attributes = PropertyEnumerable;
}
return this->GetScriptContext()->GetIntegerString(index);
}
}
return nullptr;
}
void JavascriptArrayIndexEnumerator::Reset()
{
index = JavascriptArray::InvalidIndex;
doneArray = false;
}
}