diff --git a/lib/Runtime/Base/CrossSiteEnumerator.h b/lib/Runtime/Base/CrossSiteEnumerator.h index 2d13c36e968..9201dfd41f8 100644 --- a/lib/Runtime/Base/CrossSiteEnumerator.h +++ b/lib/Runtime/Base/CrossSiteEnumerator.h @@ -28,10 +28,8 @@ namespace Js DEFINE_VTABLE_CTOR(CrossSiteEnumerator, T); public: - virtual Var GetCurrentIndex() override; virtual void Reset() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; virtual BOOL IsCrossSiteEnumerator() override { return true; @@ -39,23 +37,6 @@ namespace Js }; - template - Var CrossSiteEnumerator::GetCurrentIndex() - { - Var result = __super::GetCurrentIndex(); - if (result) - { - result = CrossSite::MarshalVar(this->GetScriptContext(), result); - } - return result; - } - - template - BOOL CrossSiteEnumerator::MoveNext(PropertyAttributes* attributes) - { - return __super::MoveNext(attributes); - } - template void CrossSiteEnumerator::Reset() { @@ -63,9 +44,9 @@ namespace Js } template - Var CrossSiteEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var CrossSiteEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { - Var result = __super::GetCurrentAndMoveNext(propertyId, attributes); + Var result = __super::MoveAndGetNext(propertyId, attributes); if (result) { result = CrossSite::MarshalVar(this->GetScriptContext(), result); diff --git a/lib/Runtime/ByteCode/ByteCodeEmitter.cpp b/lib/Runtime/ByteCode/ByteCodeEmitter.cpp index d42659607ea..bfab916b88f 100644 --- a/lib/Runtime/ByteCode/ByteCodeEmitter.cpp +++ b/lib/Runtime/ByteCode/ByteCodeEmitter.cpp @@ -9116,7 +9116,7 @@ void EmitForIn(ParseNode *loopNode, // The EndStatement will happen in the EmitForInOfLoopBody function byteCodeGenerator->StartStatement(loopNode->sxForInOrForOf.pnodeLval); - // branch past loop when GetCurrentAndMoveNext returns nullptr + // branch past loop when MoveAndGetNext returns nullptr byteCodeGenerator->Writer()->BrReg2(Js::OpCode::BrOnEmpty, continuePastLoop, loopNode->sxForInOrForOf.itemLocation, loopNode->location); EmitForInOfLoopBody(loopNode, loopEntrance, continuePastLoop, byteCodeGenerator, funcInfo, fReturnValue); diff --git a/lib/Runtime/Debug/DiagObjectModel.cpp b/lib/Runtime/Debug/DiagObjectModel.cpp index 37eb76bd977..5de7c5ca600 100644 --- a/lib/Runtime/Debug/DiagObjectModel.cpp +++ b/lib/Runtime/Debug/DiagObjectModel.cpp @@ -2063,7 +2063,8 @@ namespace Js if (object->CanHaveInterceptors()) { Js::ForInObjectEnumerator enumerator(object, object->GetScriptContext(), /* enumSymbols */ true); - if (enumerator.MoveNext()) + Js::PropertyId propertyId; + if (enumerator.MoveAndGetNext(propertyId)) { enumerator.Clear(); return TRUE; @@ -2378,7 +2379,7 @@ namespace Js Js::PropertyId propertyId; Var obj; - while ((obj = enumerator->GetCurrentAndMoveNext(propertyId)) != nullptr) + while ((obj = enumerator->MoveAndGetNext(propertyId)) != nullptr) { if (!JavascriptString::Is(obj)) { @@ -2402,7 +2403,7 @@ namespace Js propertyId = propertyRecord->GetPropertyId(); } } - // GetCurrentAndMoveNext shouldn't return an internal property id + // MoveAndGetNext shouldn't return an internal property id Assert(!Js::IsInternalPropertyId(propertyId)); uint32 indexVal; diff --git a/lib/Runtime/Language/JavascriptOperators.cpp b/lib/Runtime/Language/JavascriptOperators.cpp index 9c9f157e694..b67c3f83d34 100644 --- a/lib/Runtime/Language/JavascriptOperators.cpp +++ b/lib/Runtime/Language/JavascriptOperators.cpp @@ -5214,7 +5214,7 @@ namespace Js Var JavascriptOperators::OP_BrOnEmpty(ForInObjectEnumerator * aEnumerator) { PropertyId id; - return aEnumerator->GetCurrentAndMoveNext(id); + return aEnumerator->MoveAndGetNext(id); } ForInObjectEnumerator * JavascriptOperators::OP_GetForInEnumerator(Var enumerable, ScriptContext* scriptContext) diff --git a/lib/Runtime/Library/ArgumentsObjectEnumerator.cpp b/lib/Runtime/Library/ArgumentsObjectEnumerator.cpp index b2c8fedff25..a22cce2cb5a 100644 --- a/lib/Runtime/Library/ArgumentsObjectEnumerator.cpp +++ b/lib/Runtime/Library/ArgumentsObjectEnumerator.cpp @@ -15,16 +15,7 @@ namespace Js Reset(); } - Var ArgumentsObjectEnumerator::GetCurrentIndex() - { - if (!doneFormalArgs) - { - return argumentsObject->GetScriptContext()->GetIntegerString(formalArgIndex); - } - return objectEnumerator->GetCurrentIndex(); - } - - BOOL ArgumentsObjectEnumerator::MoveNext(PropertyAttributes* attributes) + Var ArgumentsObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { if (!doneFormalArgs) { @@ -32,13 +23,14 @@ namespace Js if (formalArgIndex != JavascriptArray::InvalidIndex && formalArgIndex < argumentsObject->GetNumberOfArguments()) { - return true; + propertyId = Constants::NoProperty; + return argumentsObject->GetScriptContext()->GetIntegerString(formalArgIndex); } doneFormalArgs = true; } - return objectEnumerator->MoveNext(attributes); - } + return objectEnumerator->MoveAndGetNext(propertyId, attributes); + } void ArgumentsObjectEnumerator::Reset() { @@ -50,16 +42,6 @@ namespace Js objectEnumerator = (Js::JavascriptEnumerator*)enumerator; } - bool ArgumentsObjectEnumerator::GetCurrentPropertyId(PropertyId *pPropertyId) - { - if (!doneFormalArgs) - { - *pPropertyId = Constants::NoProperty; - return false; - } - return objectEnumerator->GetCurrentPropertyId(pPropertyId); - } - //---------------------- ES5ArgumentsObjectEnumerator ------------------------------- ES5ArgumentsObjectEnumerator::ES5ArgumentsObjectEnumerator(ArgumentsObject* argumentsObject, ScriptContext* requestcontext, BOOL enumNonEnumerable, bool enumSymbols) @@ -69,7 +51,7 @@ namespace Js this->Reset(); } - BOOL ES5ArgumentsObjectEnumerator::MoveNext(PropertyAttributes* attributes) + Var ES5ArgumentsObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { // Formals: // - deleted => not in objectArray && not connected -- do not enum, do not advance @@ -80,24 +62,24 @@ namespace Js { ES5HeapArgumentsObject* es5HAO = static_cast(argumentsObject); formalArgIndex = es5HAO->GetNextFormalArgIndexHelper(formalArgIndex, this->enumNonEnumerable, attributes); - if (formalArgIndex != JavascriptArray::InvalidIndex) - { - if (formalArgIndex < argumentsObject->GetNumberOfArguments()) + if (formalArgIndex != JavascriptArray::InvalidIndex + && formalArgIndex < argumentsObject->GetNumberOfArguments()) + { + if (argumentsObject->HasObjectArrayItem(formalArgIndex)) { - if (argumentsObject->HasObjectArrayItem(formalArgIndex)) - { - BOOL tempResult = objectEnumerator->MoveNext(attributes); - AssertMsg(tempResult, "We advanced objectEnumerator->MoveNext() too many times."); - } - - return TRUE; + PropertyId tempPropertyId; + Var tempIndex = objectEnumerator->MoveAndGetNext(tempPropertyId, attributes); + AssertMsg(tempIndex, "We advanced objectEnumerator->MoveNext() too many times."); } + + propertyId = Constants::NoProperty; + return argumentsObject->GetScriptContext()->GetIntegerString(formalArgIndex); } doneFormalArgs = true; } - return objectEnumerator->MoveNext(attributes); + return objectEnumerator->MoveAndGetNext(propertyId, attributes); } void ES5ArgumentsObjectEnumerator::Reset() diff --git a/lib/Runtime/Library/ArgumentsObjectEnumerator.h b/lib/Runtime/Library/ArgumentsObjectEnumerator.h index 44ce7d25f25..42753bb5274 100644 --- a/lib/Runtime/Library/ArgumentsObjectEnumerator.h +++ b/lib/Runtime/Library/ArgumentsObjectEnumerator.h @@ -22,10 +22,8 @@ namespace Js public: ArgumentsObjectEnumerator(ArgumentsObject* argumentsObject, ScriptContext* requestcontext, BOOL enumNonEnumerable, bool enumSymbols = false); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; class ES5ArgumentsObjectEnumerator : public ArgumentsObjectEnumerator @@ -36,10 +34,8 @@ namespace Js public: ES5ArgumentsObjectEnumerator(ArgumentsObject* argumentsObject, ScriptContext* requestcontext, BOOL enumNonEnumerable, bool enumSymbols = false); - - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; private: uint enumeratedFormalsInObjectArrayCount; // The number of enumerated formals for far. }; diff --git a/lib/Runtime/Library/ES5ArrayEnumerator.cpp b/lib/Runtime/Library/ES5ArrayEnumerator.cpp index 1b61eb18ed7..d7ffc4e4993 100644 --- a/lib/Runtime/Library/ES5ArrayEnumerator.cpp +++ b/lib/Runtime/Library/ES5ArrayEnumerator.cpp @@ -17,21 +17,7 @@ namespace Js Reset(); } - Var ES5ArrayEnumerator::GetCurrentIndex() - { - if (!doneArray && index != JavascriptArray::InvalidIndex) - { - return arrayObject->GetScriptContext()->GetIntegerString(index); - } - else if (!doneObject) - { - return objectEnumerator->GetCurrentIndex(); - } - - return GetLibrary()->GetUndefined(); - } - - Var ES5ArrayEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var ES5ArrayEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { propertyId = Constants::NoProperty; @@ -77,7 +63,7 @@ namespace Js } if (!doneObject) { - Var currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex) { return currentIndex; diff --git a/lib/Runtime/Library/ES5ArrayEnumerator.h b/lib/Runtime/Library/ES5ArrayEnumerator.h index 043772911e5..9f0930a11e8 100644 --- a/lib/Runtime/Library/ES5ArrayEnumerator.h +++ b/lib/Runtime/Library/ES5ArrayEnumerator.h @@ -24,8 +24,7 @@ namespace Js public: ES5ArrayEnumerator(Var originalInstance, ES5Array* arrayObject, ScriptContext* scriptContext, BOOL enumNonEnumerable, bool enumSymbols = false); - virtual Var GetCurrentIndex() override; virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; } diff --git a/lib/Runtime/Library/ForInObjectEnumerator.cpp b/lib/Runtime/Library/ForInObjectEnumerator.cpp index da35d191015..8cfcd96265a 100644 --- a/lib/Runtime/Library/ForInObjectEnumerator.cpp +++ b/lib/Runtime/Library/ForInObjectEnumerator.cpp @@ -136,12 +136,7 @@ namespace Js Var ForInObjectEnumerator::GetCurrentIndex() { - if (currentIndex) - { - return currentIndex; - } - Assert(currentEnumerator != nullptr); - return currentEnumerator->GetCurrentIndex(); + return currentIndex; } BOOL ForInObjectEnumerator::TestAndSetEnumerated(PropertyId propertyId) @@ -155,11 +150,11 @@ namespace Js BOOL ForInObjectEnumerator::MoveNext() { PropertyId propertyId; - currentIndex = GetCurrentAndMoveNext(propertyId); + currentIndex = MoveAndGetNext(propertyId); return currentIndex != NULL; } - Var ForInObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId) + Var ForInObjectEnumerator::MoveAndGetNext(PropertyId& propertyId) { JavascriptEnumerator *pEnumerator = currentEnumerator; PropertyRecord const * propRecord; @@ -168,7 +163,7 @@ namespace Js while (true) { propertyId = Constants::NoProperty; - currentIndex = pEnumerator->GetCurrentAndMoveNext(propertyId, &attributes); + currentIndex = pEnumerator->MoveAndGetNext(propertyId, &attributes); #if ENABLE_COPYONACCESS_ARRAY JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray(currentIndex); #endif @@ -177,7 +172,7 @@ namespace Js if (firstPrototype == nullptr) { // We are calculating correct shadowing for non-enumerable properties of the child object, we will receive - // both enumerable and non-enumerable properties from GetCurrentAndMoveNext so we need to check before we simply + // both enumerable and non-enumerable properties from MoveAndGetNext so we need to check before we simply // return here. If this property is non-enumerable we're going to skip it. if (!(attributes & PropertyEnumerable)) { diff --git a/lib/Runtime/Library/ForInObjectEnumerator.h b/lib/Runtime/Library/ForInObjectEnumerator.h index cd2f6cd6339..10a35037ef3 100644 --- a/lib/Runtime/Library/ForInObjectEnumerator.h +++ b/lib/Runtime/Library/ForInObjectEnumerator.h @@ -39,7 +39,7 @@ namespace Js Var GetCurrentIndex(); BOOL MoveNext(); void Reset(); - Var GetCurrentAndMoveNext(PropertyId& propertyId); + Var MoveAndGetNext(PropertyId& propertyId); static uint32 GetOffsetOfCurrentEnumerator() { return offsetof(ForInObjectEnumerator, currentEnumerator); } static uint32 GetOffsetOfFirstPrototype() { return offsetof(ForInObjectEnumerator, firstPrototype); } @@ -56,12 +56,10 @@ namespace Js { } - virtual Var GetCurrentIndex() override { return forInObjectEnumerator.GetCurrentIndex(); } - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override { return forInObjectEnumerator.MoveNext(); } virtual void Reset() override { forInObjectEnumerator.Reset(); } - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) { - return forInObjectEnumerator.GetCurrentAndMoveNext(propertyId); + return forInObjectEnumerator.MoveAndGetNext(propertyId); } protected: DEFINE_VTABLE_CTOR(ForInObjectEnumeratorWrapper, JavascriptEnumerator); diff --git a/lib/Runtime/Library/IteratorObjectEnumerator.cpp b/lib/Runtime/Library/IteratorObjectEnumerator.cpp index f4ab5b42657..15477ecc6d2 100644 --- a/lib/Runtime/Library/IteratorObjectEnumerator.cpp +++ b/lib/Runtime/Library/IteratorObjectEnumerator.cpp @@ -20,43 +20,17 @@ namespace Js iteratorObject = RecyclableObject::FromVar(iterator); } - void IteratorObjectEnumerator::EnsureIterator() - { - if (value == nullptr) - { - MoveNext(); - } - } - - Var IteratorObjectEnumerator::GetCurrentIndex() - { - EnsureIterator(); - if (done) - { - return GetScriptContext()->GetLibrary()->GetUndefined(); - } - return value; - } - - BOOL IteratorObjectEnumerator::MoveNext(PropertyAttributes* attributes) + Var IteratorObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { ScriptContext* scriptContext = GetScriptContext(); - done = !JavascriptOperators::IteratorStepAndValue(iteratorObject, scriptContext, &value); - - if (attributes != nullptr) + if (JavascriptOperators::IteratorStepAndValue(iteratorObject, scriptContext, &value)) { - *attributes = PropertyEnumerable; - } - - return !done; - } + if (attributes != nullptr) + { + *attributes = PropertyEnumerable; + } - Var IteratorObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) - { - if (MoveNext(attributes)) - { - Var currentIndex = GetCurrentIndex(); - ScriptContext* scriptContext = GetScriptContext(); + Var currentIndex = value; const PropertyRecord* propertyRecord = nullptr; if (!TaggedInt::Is(currentIndex) && JavascriptString::Is(currentIndex) && VirtualTableInfo::HasVirtualTable(JavascriptString::FromVar(currentIndex))) diff --git a/lib/Runtime/Library/IteratorObjectEnumerator.h b/lib/Runtime/Library/IteratorObjectEnumerator.h index 4496ef984d8..91c86af5416 100644 --- a/lib/Runtime/Library/IteratorObjectEnumerator.h +++ b/lib/Runtime/Library/IteratorObjectEnumerator.h @@ -10,9 +10,7 @@ namespace Js { public: static Var Create(ScriptContext* scriptContext, Var iteratorObject); - virtual Var GetCurrentIndex() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr); - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr); virtual void Reset() override; protected: IteratorObjectEnumerator(ScriptContext* scriptContext, Var iteratorObject); diff --git a/lib/Runtime/Library/JSON.cpp b/lib/Runtime/Library/JSON.cpp index 39a8c830fc1..1f7bb030b5b 100644 --- a/lib/Runtime/Library/JSON.cpp +++ b/lib/Runtime/Library/JSON.cpp @@ -650,7 +650,7 @@ namespace JSON { Js::Var propertyNameVar; enumerator->Reset(); - while ((propertyNameVar = enumerator->GetCurrentAndMoveNext(id)) != NULL) + while ((propertyNameVar = enumerator->MoveAndGetNext(id)) != NULL) { if (!Js::JavascriptOperators::IsUndefinedObject(propertyNameVar, undefined)) { @@ -692,7 +692,7 @@ namespace JSON enumerator->Reset(); uint32 index = 0; Js::Var propertyNameVar; - while ((propertyNameVar = enumerator->GetCurrentAndMoveNext(id)) != NULL && index < precisePropertyCount) + while ((propertyNameVar = enumerator->MoveAndGetNext(id)) != NULL && index < precisePropertyCount) { if (!Js::JavascriptOperators::IsUndefinedObject(propertyNameVar, undefined)) { @@ -925,7 +925,7 @@ namespace JSON Js::Var propertyNameVar; Js::PropertyId id; enumerator->Reset(); - while ((propertyNameVar = enumerator->GetCurrentAndMoveNext(id)) != NULL) + while ((propertyNameVar = enumerator->MoveAndGetNext(id)) != NULL) { if (!Js::JavascriptOperators::IsUndefinedObject(propertyNameVar, this->scriptContext->GetLibrary()->GetUndefined())) { diff --git a/lib/Runtime/Library/JSONParser.cpp b/lib/Runtime/Library/JSONParser.cpp index d19f704d711..fdd0f3c4364 100644 --- a/lib/Runtime/Library/JSONParser.cpp +++ b/lib/Runtime/Library/JSONParser.cpp @@ -131,16 +131,21 @@ namespace JSON { Js::JavascriptEnumerator* enumerator = static_cast(enumeratorVar); Js::Var propertyNameVar; - Js::PropertyId idMember; - while(enumerator->MoveNext()) + while (true) { - propertyNameVar = enumerator->GetCurrentIndex(); + Js::PropertyId idMember = Js::Constants::NoProperty; + propertyNameVar = enumerator->MoveAndGetNext(idMember); + if (propertyNameVar == nullptr) + { + break; + } + //NOTE: If testing key value call enumerator->GetCurrentValue() to confirm value is correct; - AssertMsg(!Js::JavascriptOperators::IsUndefinedObject(propertyNameVar, undefined) && Js::JavascriptString::Is(propertyNameVar) , "bad enumeration on a JSON Object"); + AssertMsg(Js::JavascriptString::Is(propertyNameVar) , "bad enumeration on a JSON Object"); - if (enumerator->GetCurrentPropertyId(&idMember)) + if (idMember != Js::Constants::NoProperty) { Js::Var newElement = Walk(Js::JavascriptString::FromVar(propertyNameVar), idMember, value); if (Js::JavascriptOperators::IsUndefinedObject(newElement, undefined)) diff --git a/lib/Runtime/Library/JavascriptArrayEnumerator.cpp b/lib/Runtime/Library/JavascriptArrayEnumerator.cpp index 3d45cb1870f..c396c93243e 100644 --- a/lib/Runtime/Library/JavascriptArrayEnumerator.cpp +++ b/lib/Runtime/Library/JavascriptArrayEnumerator.cpp @@ -13,7 +13,7 @@ namespace Js Reset(); } - Var JavascriptArrayEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptArrayEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { // TypedArrayEnumerator follow the same logic but implementation is slightly // different as we don't have sparse array in typed array, and typed array @@ -46,7 +46,7 @@ namespace Js } if (!doneObject) { - Var currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex) { return currentIndex; diff --git a/lib/Runtime/Library/JavascriptArrayEnumerator.h b/lib/Runtime/Library/JavascriptArrayEnumerator.h index b5e7756a8c1..0e2f24b9f3f 100644 --- a/lib/Runtime/Library/JavascriptArrayEnumerator.h +++ b/lib/Runtime/Library/JavascriptArrayEnumerator.h @@ -15,6 +15,6 @@ namespace Js public: JavascriptArrayEnumerator(JavascriptArray* arrayObject, ScriptContext* scriptContext, BOOL enumNonEnumerable, bool enumSymbols = false); virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; } diff --git a/lib/Runtime/Library/JavascriptArrayEnumeratorBase.cpp b/lib/Runtime/Library/JavascriptArrayEnumeratorBase.cpp index 892651a1a87..5178578ce92 100644 --- a/lib/Runtime/Library/JavascriptArrayEnumeratorBase.cpp +++ b/lib/Runtime/Library/JavascriptArrayEnumeratorBase.cpp @@ -14,45 +14,4 @@ namespace Js enumSymbols(enumSymbols) { } - - Var JavascriptArrayEnumeratorBase::GetCurrentIndex() - { - if (index != JavascriptArray::InvalidIndex && !doneArray) - { - return arrayObject->GetScriptContext()->GetIntegerString(index); - } - else if (!doneObject) - { - return objectEnumerator->GetCurrentIndex(); - } - else - { - return GetLibrary()->GetUndefined(); - } - } - - BOOL JavascriptArrayEnumeratorBase::MoveNext(PropertyAttributes* attributes) - { - PropertyId propId; - return GetCurrentAndMoveNext(propId, attributes) != nullptr; - } - - bool JavascriptArrayEnumeratorBase::GetCurrentPropertyId(PropertyId *pPropertyId) - { - if (index != JavascriptArray::InvalidIndex && !doneArray) - { - *pPropertyId = Constants::NoProperty; - return false; - } - else if (!doneObject) - { - return objectEnumerator->GetCurrentPropertyId(pPropertyId); - } - else - { - *pPropertyId = Constants::NoProperty; - return false; - } - } - } diff --git a/lib/Runtime/Library/JavascriptArrayEnumeratorBase.h b/lib/Runtime/Library/JavascriptArrayEnumeratorBase.h index a684a4c8913..2fe2b210685 100644 --- a/lib/Runtime/Library/JavascriptArrayEnumeratorBase.h +++ b/lib/Runtime/Library/JavascriptArrayEnumeratorBase.h @@ -20,9 +20,6 @@ namespace Js DEFINE_VTABLE_CTOR_ABSTRACT(JavascriptArrayEnumeratorBase, JavascriptEnumerator) JavascriptArrayEnumeratorBase(JavascriptArray* arrayObject, ScriptContext* scriptContext, BOOL enumNonEnumerable, bool enumSymbols = false); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual uint32 GetCurrentItemIndex() override { return index; } - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; }; } diff --git a/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.cpp b/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.cpp index 60dab30f5f5..af422ae038d 100644 --- a/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.cpp +++ b/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.cpp @@ -14,7 +14,7 @@ namespace Js Reset(); } - Var JavascriptArraySnapshotEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptArraySnapshotEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { propertyId = Constants::NoProperty; @@ -39,7 +39,7 @@ namespace Js } if (!doneObject) { - Var currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (!currentIndex) { doneObject = true; diff --git a/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.h b/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.h index 777edeac9fa..40c4918967f 100644 --- a/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.h +++ b/lib/Runtime/Library/JavascriptArraySnapshotEnumerator.h @@ -18,6 +18,6 @@ namespace Js public: JavascriptArraySnapshotEnumerator(JavascriptArray* arrayObject, ScriptContext* scriptContext, BOOL enumNonEnumerable, bool enumSymbols = false); virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr); + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr); }; } diff --git a/lib/Runtime/Library/JavascriptEnumeratorIterator.cpp b/lib/Runtime/Library/JavascriptEnumeratorIterator.cpp index a2c11e1f2cc..b13d2df0cb1 100644 --- a/lib/Runtime/Library/JavascriptEnumeratorIterator.cpp +++ b/lib/Runtime/Library/JavascriptEnumeratorIterator.cpp @@ -66,7 +66,7 @@ namespace Js if (enumerator != nullptr) { - index = enumerator->GetCurrentAndMoveNext(propertyId); + index = enumerator->MoveAndGetNext(propertyId); if (index == nullptr) { // when done with iterator, cleanup the enumerator to avoid GC pressure. diff --git a/lib/Runtime/Library/JavascriptObject.cpp b/lib/Runtime/Library/JavascriptObject.cpp index de523cb2e34..f58e604427a 100644 --- a/lib/Runtime/Library/JavascriptObject.cpp +++ b/lib/Runtime/Library/JavascriptObject.cpp @@ -1143,7 +1143,7 @@ namespace Js const PropertyRecord* propertyRecord; JavascriptSymbol* symbol; - while ((propertyName = pEnumerator->GetCurrentAndMoveNext(propertyId)) != NULL) + while ((propertyName = pEnumerator->MoveAndGetNext(propertyId)) != NULL) { if (!JavascriptOperators::IsUndefinedObject(propertyName, undefined)) //There are some code paths in which GetCurrentIndex can return undefined { @@ -1521,7 +1521,7 @@ namespace Js Var propertyVar = nullptr; //enumerate through each property of properties and fetch the property descriptor - while ((propertyVar = pEnumerator->GetCurrentAndMoveNext(nextKey)) != NULL) + while ((propertyVar = pEnumerator->MoveAndGetNext(nextKey)) != NULL) { if (nextKey == Constants::NoProperty) { @@ -1684,7 +1684,7 @@ namespace Js RecyclableObject *undefined = scriptContext->GetLibrary()->GetUndefined(); //enumerate through each property of properties and fetch the property descriptor - while ((tempVar = pEnumerator->GetCurrentAndMoveNext(propId)) != NULL) + while ((tempVar = pEnumerator->MoveAndGetNext(propId)) != NULL) { if (propId == Constants::NoProperty) //try current property id query first { diff --git a/lib/Runtime/Library/JavascriptRegExpEnumerator.cpp b/lib/Runtime/Library/JavascriptRegExpEnumerator.cpp index 19a7f7831db..7d78d5af24e 100644 --- a/lib/Runtime/Library/JavascriptRegExpEnumerator.cpp +++ b/lib/Runtime/Library/JavascriptRegExpEnumerator.cpp @@ -13,44 +13,12 @@ namespace Js index = (uint)-1; } - Var JavascriptRegExpEnumerator::GetCurrentIndex() - { - ScriptContext *scriptContext = regExpObject->GetScriptContext(); - - if (index != (uint)-1 && index < regExpObject->GetSpecialEnumerablePropertyCount()) - { - return scriptContext->GetIntegerString(index); - } - else - { - return scriptContext->GetLibrary()->GetUndefined(); - } - } - - BOOL JavascriptRegExpEnumerator::MoveNext(PropertyAttributes* attributes) - { - if (++index < regExpObject->GetSpecialEnumerablePropertyCount()) - { - if (attributes != nullptr) - { - *attributes = PropertyEnumerable; - } - - return true; - } - else - { - index = regExpObject->GetSpecialEnumerablePropertyCount(); - return false; - } - } - void JavascriptRegExpEnumerator::Reset() { index = (uint)-1; } - Var JavascriptRegExpEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptRegExpEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { propertyId = Constants::NoProperty; ScriptContext* scriptContext = regExpObject->GetScriptContext(); @@ -85,66 +53,12 @@ namespace Js Reset(); } - Var JavascriptRegExpObjectEnumerator::GetCurrentIndex() - { - if (regExpEnumerator != nullptr) - { - return regExpEnumerator->GetCurrentIndex(); - } - else if (objectEnumerator != nullptr) - { - return objectEnumerator->GetCurrentIndex(); - } - else - { - return GetLibrary()->GetUndefined(); - } - } - - BOOL JavascriptRegExpObjectEnumerator::MoveNext(PropertyAttributes* attributes) - { - if (regExpEnumerator != nullptr) - { - if (regExpEnumerator->MoveNext(attributes)) - { - return true; - } - regExpEnumerator = nullptr; - } - if (objectEnumerator != nullptr) - { - if (objectEnumerator->MoveNext(attributes)) - { - return true; - } - objectEnumerator = nullptr; - } - return false; - } - - bool JavascriptRegExpObjectEnumerator::GetCurrentPropertyId(PropertyId *pPropertyId) - { - if (regExpEnumerator != nullptr) - { - *pPropertyId = Constants::NoProperty; - return false; - } - - if (objectEnumerator != nullptr) - { - return objectEnumerator->GetCurrentPropertyId(pPropertyId); - } - - *pPropertyId = Constants::NoProperty; - return false; - } - - Var JavascriptRegExpObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptRegExpObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { Var currentIndex; if (regExpEnumerator != nullptr) { - currentIndex = regExpEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + currentIndex = regExpEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex != nullptr) { return currentIndex; @@ -153,7 +67,7 @@ namespace Js } if (objectEnumerator != nullptr) { - currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex != nullptr) { return currentIndex; diff --git a/lib/Runtime/Library/JavascriptRegExpEnumerator.h b/lib/Runtime/Library/JavascriptRegExpEnumerator.h index 307b3777c9c..6432bc7ff46 100644 --- a/lib/Runtime/Library/JavascriptRegExpEnumerator.h +++ b/lib/Runtime/Library/JavascriptRegExpEnumerator.h @@ -18,10 +18,8 @@ namespace Js public: JavascriptRegExpEnumerator(JavascriptRegExpConstructor* regExpObject, ScriptContext * requestContext, BOOL enumNonEnumerable); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; class JavascriptRegExpObjectEnumerator : public JavascriptEnumerator @@ -39,10 +37,7 @@ namespace Js public: JavascriptRegExpObjectEnumerator(JavascriptRegExpConstructor* regExpObject, ScriptContext * requestContext, BOOL enumNonEnumerable, bool enumSymbols); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; } diff --git a/lib/Runtime/Library/JavascriptStringEnumerator.cpp b/lib/Runtime/Library/JavascriptStringEnumerator.cpp index a9a350920e2..24a9dee840b 100644 --- a/lib/Runtime/Library/JavascriptStringEnumerator.cpp +++ b/lib/Runtime/Library/JavascriptStringEnumerator.cpp @@ -13,45 +13,13 @@ namespace Js { } - Var JavascriptStringEnumerator::GetCurrentIndex() - { - ScriptContext *scriptContext = stringObject->GetScriptContext(); - - if (index >= 0 && index < stringObject->GetLengthAsSignedInt()) - { - return scriptContext->GetIntegerString(index); - } - else - { - return scriptContext->GetLibrary()->GetUndefined(); - } - } - - BOOL JavascriptStringEnumerator::MoveNext(PropertyAttributes* attributes) - { - if (++index < stringObject->GetLengthAsSignedInt()) - { - if (attributes != nullptr) - { - *attributes = PropertyEnumerable; - } - - return true; - } - else - { - index = stringObject->GetLength(); - return false; - } - } - void JavascriptStringEnumerator::Reset() { index = -1; } - Var JavascriptStringEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptStringEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { propertyId = Constants::NoProperty; if (++index < stringObject->GetLengthAsSignedInt()) @@ -82,64 +50,12 @@ namespace Js Reset(); } - Var JavascriptStringObjectEnumerator::GetCurrentIndex() - { - if (stringEnumerator != nullptr) - { - return stringEnumerator->GetCurrentIndex(); - } - else if (objectEnumerator != nullptr) - { - return objectEnumerator->GetCurrentIndex(); - } - else - { - return GetLibrary()->GetUndefined(); - } - } - - BOOL JavascriptStringObjectEnumerator::MoveNext(PropertyAttributes* attributes) - { - if (stringEnumerator != nullptr) - { - if (stringEnumerator->MoveNext(attributes)) - { - return true; - } - stringEnumerator = nullptr; - } - if (objectEnumerator != nullptr) - { - if (objectEnumerator->MoveNext(attributes)) - { - return true; - } - objectEnumerator = nullptr; - } - return false; - } - - bool JavascriptStringObjectEnumerator::GetCurrentPropertyId(PropertyId* propertyId) - { - if (stringEnumerator != nullptr) - { - *propertyId = Constants::NoProperty; - return false; - } - if (objectEnumerator != nullptr) - { - return objectEnumerator->GetCurrentPropertyId(propertyId); - } - *propertyId = Constants::NoProperty; - return false; - } - - Var JavascriptStringObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var JavascriptStringObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { Var currentIndex; if (stringEnumerator != nullptr) { - currentIndex = stringEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + currentIndex = stringEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex != nullptr) { return currentIndex; @@ -148,7 +64,7 @@ namespace Js } if (objectEnumerator != nullptr) { - currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (currentIndex != nullptr) { return currentIndex; diff --git a/lib/Runtime/Library/JavascriptStringEnumerator.h b/lib/Runtime/Library/JavascriptStringEnumerator.h index df96f79ca75..ddd0dfe9066 100644 --- a/lib/Runtime/Library/JavascriptStringEnumerator.h +++ b/lib/Runtime/Library/JavascriptStringEnumerator.h @@ -17,10 +17,8 @@ namespace Js public: JavascriptStringEnumerator(JavascriptString* stringObject, ScriptContext * requestContext); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; class JavascriptStringObjectEnumerator : public JavascriptEnumerator @@ -38,10 +36,7 @@ namespace Js public: JavascriptStringObjectEnumerator(JavascriptStringObject* stringObject, ScriptContext * requestContext, BOOL enumNonEnumerable, bool enumSymbols = false); - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; } diff --git a/lib/Runtime/Library/NullEnumerator.cpp b/lib/Runtime/Library/NullEnumerator.cpp index 8effb427009..37b3621dbd7 100644 --- a/lib/Runtime/Library/NullEnumerator.cpp +++ b/lib/Runtime/Library/NullEnumerator.cpp @@ -8,30 +8,12 @@ namespace Js { - Var NullEnumerator::GetCurrentIndex() - { - // This function may be called without calling MoveNext to verify element availability - // by JavascriptDispatch::GetNextDispIDWithScriptEnter which call - // GetEnumeratorCurrentPropertyId to resume an enumeration - return this->GetLibrary()->GetUndefined(); - } - - BOOL NullEnumerator::MoveNext(PropertyAttributes* attributes) - { - return FALSE; - } - void NullEnumerator::Reset() { } - Var NullEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) - { - return NULL; - } - - bool NullEnumerator::GetCurrentPropertyId(PropertyId *propertyId) + Var NullEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { - return false; + return nullptr; } }; diff --git a/lib/Runtime/Library/NullEnumerator.h b/lib/Runtime/Library/NullEnumerator.h index b145c175498..8b6a602b8ba 100644 --- a/lib/Runtime/Library/NullEnumerator.h +++ b/lib/Runtime/Library/NullEnumerator.h @@ -11,11 +11,8 @@ namespace Js class NullEnumerator : public JavascriptEnumerator { private: - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; protected: DEFINE_VTABLE_CTOR(NullEnumerator, JavascriptEnumerator); diff --git a/lib/Runtime/Library/TypedArrayEnumerator.cpp b/lib/Runtime/Library/TypedArrayEnumerator.cpp index d99bab30283..bc6c54cf6c0 100644 --- a/lib/Runtime/Library/TypedArrayEnumerator.cpp +++ b/lib/Runtime/Library/TypedArrayEnumerator.cpp @@ -15,29 +15,7 @@ namespace Js Reset(); } - Var TypedArrayEnumerator::GetCurrentIndex() - { - if (index != JavascriptArray::InvalidIndex && !doneArray) - { - return typedArrayObject->GetScriptContext()->GetIntegerString(index); - } - else if (!doneObject) - { - return objectEnumerator->GetCurrentIndex(); - } - else - { - return typedArrayObject->GetType()->GetLibrary()->GetUndefined(); - } - } - - BOOL TypedArrayEnumerator::MoveNext(PropertyAttributes* attributes) - { - PropertyId propId; - return GetCurrentAndMoveNext(propId, attributes) != nullptr; - } - - Var TypedArrayEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var TypedArrayEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { // TypedArrayEnumerator follows the same logic in JavascriptArrayEnumerator, // but the implementation is slightly different as we don't have sparse array @@ -68,7 +46,7 @@ namespace Js } if (!doneObject) { - Var currentIndex = objectEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = objectEnumerator->MoveAndGetNext(propertyId, attributes); if (!currentIndex) { doneObject = true; @@ -87,19 +65,4 @@ namespace Js typedArrayObject->DynamicObject::GetEnumerator(enumNonEnumerable, &enumerator, GetScriptContext(), true, enumSymbols); objectEnumerator = (JavascriptEnumerator*)enumerator; } - - bool TypedArrayEnumerator::GetCurrentPropertyId(PropertyId* propertyId) - { - if (!doneArray) - { - *propertyId = Constants::NoProperty; - return false; - } - if (!doneObject) - { - return objectEnumerator->GetCurrentPropertyId(propertyId); - } - *propertyId = Constants::NoProperty; - return false; - } } diff --git a/lib/Runtime/Library/TypedArrayEnumerator.h b/lib/Runtime/Library/TypedArrayEnumerator.h index 51b8b4a89ec..78a216a4589 100644 --- a/lib/Runtime/Library/TypedArrayEnumerator.h +++ b/lib/Runtime/Library/TypedArrayEnumerator.h @@ -23,10 +23,7 @@ namespace Js public: TypedArrayEnumerator(BOOL enumNonEnumerable, TypedArrayBase* typeArrayBase, ScriptContext* scriptContext, bool enumSymbols = false); - virtual Var GetCurrentIndex() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; }; } diff --git a/lib/Runtime/Types/DynamicObjectEnumerator.cpp b/lib/Runtime/Types/DynamicObjectEnumerator.cpp index 9d9f102417f..dc0e3791f92 100644 --- a/lib/Runtime/Types/DynamicObjectEnumerator.cpp +++ b/lib/Runtime/Types/DynamicObjectEnumerator.cpp @@ -25,53 +25,6 @@ namespace Js : object->GetDynamicType(); } - template - Var DynamicObjectEnumerator::GetCurrentIndex() - { - if (arrayEnumerator) - { - return arrayEnumerator->GetCurrentIndex(); - } - - JavascriptString* propertyString = nullptr; - PropertyId propertyId = Constants::NoProperty; - if (!object->FindNextProperty(objectIndex, &propertyString, &propertyId, nullptr, GetTypeToEnumerate(), !enumNonEnumerable, enumSymbols)) - { - return this->GetLibrary()->GetUndefined(); - } - - Assert(propertyId == Constants::NoProperty || !Js::IsInternalPropertyId(propertyId)); - - return propertyString; - } - - template - BOOL DynamicObjectEnumerator::MoveNext(PropertyAttributes* attributes) - { - PropertyId propId; - return GetCurrentAndMoveNext(propId, attributes) != NULL; - } - - template - bool DynamicObjectEnumerator::GetCurrentPropertyId(PropertyId *pPropertyId) - { - if (arrayEnumerator) - { - return arrayEnumerator->GetCurrentPropertyId(pPropertyId); - } - Js::PropertyId propertyId = object->GetPropertyId((T) objectIndex); - - if ((enumNonEnumerable || (propertyId != Constants::NoProperty && object->IsEnumerable(propertyId)))) - { - *pPropertyId = propertyId; - return true; - } - else - { - return false; - } - } - template uint32 DynamicObjectEnumerator::GetCurrentItemIndex() { @@ -100,11 +53,11 @@ namespace Js } template - Var DynamicObjectEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var DynamicObjectEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { if (arrayEnumerator) { - Var currentIndex = arrayEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = arrayEnumerator->MoveAndGetNext(propertyId, attributes); if(currentIndex != NULL) { return currentIndex; diff --git a/lib/Runtime/Types/DynamicObjectEnumerator.h b/lib/Runtime/Types/DynamicObjectEnumerator.h index f300dcf88df..ea4dfca61ce 100644 --- a/lib/Runtime/Types/DynamicObjectEnumerator.h +++ b/lib/Runtime/Types/DynamicObjectEnumerator.h @@ -34,12 +34,9 @@ namespace Js DynamicType *GetTypeToEnumerate() const; public: - virtual Var GetCurrentIndex() override; - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) override; virtual void Reset() override; - virtual bool GetCurrentPropertyId(PropertyId *propertyId) override; virtual uint32 GetCurrentItemIndex() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; static uint32 GetOffsetOfObject() { return offsetof(DynamicObjectEnumerator, object); } static uint32 GetOffsetOfArrayEnumerator() { return offsetof(DynamicObjectEnumerator, arrayEnumerator); } diff --git a/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.cpp b/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.cpp index 6d53430e0a5..2785e8e89e1 100644 --- a/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.cpp +++ b/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.cpp @@ -15,11 +15,11 @@ namespace Js } template - Var DynamicObjectSnapshotEnumerator::GetCurrentAndMoveNextFromArray(PropertyId& propertyId, PropertyAttributes* attributes) + Var DynamicObjectSnapshotEnumerator::MoveAndGetNextFromArray(PropertyId& propertyId, PropertyAttributes* attributes) { if (this->arrayEnumerator) { - Var currentIndex = this->arrayEnumerator->GetCurrentAndMoveNext(propertyId, attributes); + Var currentIndex = this->arrayEnumerator->MoveAndGetNext(propertyId, attributes); if(currentIndex != nullptr) { return currentIndex; @@ -31,7 +31,7 @@ namespace Js } template - JavascriptString * DynamicObjectSnapshotEnumerator::GetCurrentAndMoveNextFromObject(T& index, PropertyId& propertyId, PropertyAttributes* attributes) + JavascriptString * DynamicObjectSnapshotEnumerator::MoveAndGetNextFromObject(T& index, PropertyId& propertyId, PropertyAttributes* attributes) { JavascriptString* propertyString = nullptr; auto newIndex = this->objectIndex; @@ -52,11 +52,11 @@ namespace Js } template - Var DynamicObjectSnapshotEnumerator::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var DynamicObjectSnapshotEnumerator::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { - Var currentIndex = GetCurrentAndMoveNextFromArray(propertyId, attributes); + Var currentIndex = MoveAndGetNextFromArray(propertyId, attributes); return (currentIndex != nullptr)? currentIndex : - this->GetCurrentAndMoveNextFromObject(this->objectIndex, propertyId, attributes); + this->MoveAndGetNextFromObject(this->objectIndex, propertyId, attributes); } template diff --git a/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.h b/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.h index 632feed16f7..df206458a5f 100644 --- a/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.h +++ b/lib/Runtime/Types/DynamicObjectSnapshotEnumerator.h @@ -21,8 +21,8 @@ namespace Js DEFINE_VTABLE_CTOR(DynamicObjectSnapshotEnumerator, Base); DEFINE_MARSHAL_ENUMERATOR_TO_SCRIPT_CONTEXT(DynamicObjectSnapshotEnumerator); - Var GetCurrentAndMoveNextFromArray(PropertyId& propertyId, PropertyAttributes* attributes); - JavascriptString * GetCurrentAndMoveNextFromObject(T& index, PropertyId& propertyId, PropertyAttributes* attributes); + Var MoveAndGetNextFromArray(PropertyId& propertyId, PropertyAttributes* attributes); + JavascriptString * MoveAndGetNextFromObject(T& index, PropertyId& propertyId, PropertyAttributes* attributes); DynamicObjectSnapshotEnumerator() { /* Do nothing, needed by the vtable ctor for ForInObjectEnumeratorWrapper */ } void Initialize(DynamicObject* object); @@ -31,7 +31,7 @@ namespace Js static JavascriptEnumerator* New(ScriptContext* scriptContext, DynamicObject* object); virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; }; } // namespace Js diff --git a/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.cpp b/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.cpp index a87c1975cb4..db22a9be111 100644 --- a/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.cpp +++ b/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.cpp @@ -57,7 +57,7 @@ namespace Js template JavascriptString * - DynamicObjectSnapshotEnumeratorWPCache::GetCurrentAndMoveNextFromObjectWPCache(T& index, PropertyId& propertyId, PropertyAttributes* attributes) + DynamicObjectSnapshotEnumeratorWPCache::MoveAndGetNextFromObjectWPCache(T& index, PropertyId& propertyId, PropertyAttributes* attributes) { if (this->initialType != this->object->GetDynamicType()) { @@ -71,7 +71,7 @@ namespace Js // downgrade back to the normal snapshot enumerator VirtualTableInfo>::SetVirtualTable(this); } - return this->GetCurrentAndMoveNextFromObject(this->objectIndex, propertyId, attributes); + return this->MoveAndGetNextFromObject(this->objectIndex, propertyId, attributes); } Assert(enumeratedCount <= cachedData->cachedCount); JavascriptString* propertyStringName; @@ -84,7 +84,7 @@ namespace Js #if ENABLE_TTD // - //TODO: We have code in GetCurrentAndMoveNextFromObject to record replay the order in which properties are enumerated. + //TODO: We have code in MoveAndGetNextFromObject to record replay the order in which properties are enumerated. // Since caching may happen differently at record/replay time we need to force this to ensure the log/order is consistent. // Later we may want to optimize by lifting the TTD code from the call and explicitly calling it here (but not the rest of the enumeration work). // @@ -92,14 +92,14 @@ namespace Js if(actionCtx->ShouldPerformRecordAction() | actionCtx->ShouldPerformDebugAction()) { PropertyId tempPropertyId; - /* JavascriptString * tempPropertyString = */ this->GetCurrentAndMoveNextFromObject(this->objectIndex, tempPropertyId, attributes); + /* JavascriptString * tempPropertyString = */ this->MoveAndGetNextFromObject(this->objectIndex, tempPropertyId, attributes); Assert(tempPropertyId == propertyId); Assert(this->objectIndex == cachedData->indexes[enumeratedCount]); } #elif DBG PropertyId tempPropertyId; - /* JavascriptString * tempPropertyString = */ this->GetCurrentAndMoveNextFromObject(this->objectIndex, tempPropertyId, attributes); + /* JavascriptString * tempPropertyString = */ this->MoveAndGetNextFromObject(this->objectIndex, tempPropertyId, attributes); Assert(tempPropertyId == propertyId); Assert(this->objectIndex == cachedData->indexes[enumeratedCount]); @@ -112,7 +112,7 @@ namespace Js } else if (!cachedData->completed) { - propertyStringName = this->GetCurrentAndMoveNextFromObject(this->objectIndex, propertyId, &propertyAttributes); + propertyStringName = this->MoveAndGetNextFromObject(this->objectIndex, propertyId, &propertyAttributes); if (propertyStringName && VirtualTableInfo::HasVirtualTable(propertyStringName)) { @@ -131,7 +131,7 @@ namespace Js { #if ENABLE_TTD // - //TODO: We have code in GetCurrentAndMoveNextFromObject to record replay the order in which properties are enumerated. + //TODO: We have code in MoveAndGetNextFromObject to record replay the order in which properties are enumerated. // Since caching may happen differently at record/replay time we need to force this to ensure the log/order is consistent. // Later we may want to optimize by lifting the TTD code from the call and explicitly calling it here (but not the rest of the enumeration work). // @@ -139,11 +139,11 @@ namespace Js if(actionCtx->ShouldPerformRecordAction() | actionCtx->ShouldPerformDebugAction()) { PropertyId tempPropertyId; - /*JavascriptString* tempPropertyStringName =*/ this->GetCurrentAndMoveNextFromObject(this->objectIndex, tempPropertyId, attributes); + /*JavascriptString* tempPropertyStringName =*/ this->MoveAndGetNextFromObject(this->objectIndex, tempPropertyId, attributes); } #elif DBG PropertyId tempPropertyId; - Assert(this->GetCurrentAndMoveNextFromObject(this->objectIndex, tempPropertyId, attributes) == nullptr); + Assert(this->MoveAndGetNextFromObject(this->objectIndex, tempPropertyId, attributes) == nullptr); #endif propertyStringName = nullptr; @@ -158,13 +158,13 @@ namespace Js } template - Var DynamicObjectSnapshotEnumeratorWPCache::GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes) + Var DynamicObjectSnapshotEnumeratorWPCache::MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes) { - Var currentIndex = this->GetCurrentAndMoveNextFromArray(propertyId, attributes); + Var currentIndex = this->MoveAndGetNextFromArray(propertyId, attributes); if (currentIndex == nullptr) { - currentIndex = this->GetCurrentAndMoveNextFromObjectWPCache(this->objectIndex, propertyId, attributes); + currentIndex = this->MoveAndGetNextFromObjectWPCache(this->objectIndex, propertyId, attributes); } return currentIndex; diff --git a/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.h b/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.h index 495c84cf8b2..237fc7fd8b4 100644 --- a/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.h +++ b/lib/Runtime/Types/DynamicObjectSnapshotEnumeratorWPCache.h @@ -29,7 +29,7 @@ namespace Js { } - JavascriptString * GetCurrentAndMoveNextFromObjectWPCache(T& index, PropertyId& propertyId, PropertyAttributes* attributes); + JavascriptString * MoveAndGetNextFromObjectWPCache(T& index, PropertyId& propertyId, PropertyAttributes* attributes); struct CachedData { @@ -51,7 +51,7 @@ namespace Js public: static JavascriptEnumerator* New(ScriptContext* scriptContext, DynamicObject* object); virtual void Reset() override; - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) override; static uint32 GetOffsetOfInitialType() { return offsetof(DynamicObjectSnapshotEnumeratorWPCache, initialType); } static uint32 GetOffsetOfEnumeratedCount() { return offsetof(DynamicObjectSnapshotEnumeratorWPCache, enumeratedCount); } diff --git a/lib/Runtime/Types/JavascriptEnumerator.h b/lib/Runtime/Types/JavascriptEnumerator.h index f5a46830e31..a15e8d5eef3 100644 --- a/lib/Runtime/Types/JavascriptEnumerator.h +++ b/lib/Runtime/Types/JavascriptEnumerator.h @@ -23,16 +23,6 @@ namespace Js { // virtual uint32 GetCurrentItemIndex() { return Constants::InvalidSourceIndex; } - // - // Returns the current index - // - virtual Var GetCurrentIndex() = 0; - - // - // Moves to next element - // - virtual BOOL MoveNext(PropertyAttributes* attributes = nullptr) = 0; - // // Sets the enumerator to its initial position // @@ -48,22 +38,7 @@ namespace Js { // If that code is added in this base class use JavaScriptRegExpEnumerator.h/cpp // as a reference and then remove it. If you have already made the edits before // seeing this comment please just consolidate the changes. - virtual Var GetCurrentAndMoveNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) - { - propertyId = Constants::NoProperty; - if (MoveNext(attributes)) - { - Var currentIndex = GetCurrentIndex(); - return currentIndex; - } - return NULL; - } - - virtual bool GetCurrentPropertyId(PropertyId *propertyId) - { - *propertyId = Constants::NoProperty; - return false; - }; + virtual Var MoveAndGetNext(PropertyId& propertyId, PropertyAttributes* attributes = nullptr) = 0; virtual BOOL IsCrossSiteEnumerator() {