Skip to content

Cleanup JavascriptEnumerator interface #1400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2016

Conversation

curtisman
Copy link
Contributor

The JavascriptEnumerator function GetCurrentAndMoveNext is misleading because. Because it move to the next one before return the next element that we moved to. Change to MoveAndGetNext.

Also remove MoveNext/GetCurrentIndex/GetCurrentPropertyId, which is equivalent to GetCurrentAndMoveNext. Move all usage of those API to MoveAndGetNext.

The JavascriptEnumerator function GetCurrentAndMoveNext is misleading because.  Because it move to the next one before return the next element that we moved to. Change to MoveAndGetNext.

Also remove MoveNext/GetCurrentIndex/GetCurrentPropertyId, which is equivalent to GetCurrentAndMoveNext. Move all usage of those API to  MoveAndGetNext.
@@ -155,11 +150,11 @@ namespace Js
BOOL ForInObjectEnumerator::MoveNext()
Copy link
Contributor

@Yongqu Yongqu Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we going to change this sometime as well? #Resolved

Copy link
Contributor Author

@curtisman curtisman Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still used in Chakra.dll #Resolved

@Yongqu
Copy link
Contributor

Yongqu commented Aug 8, 2016

                propertyRecord = scriptContext->GetPropertyName(propertyId);

I'm always a bit confused here: should propertyId & propertyName be consistent at this point? should we assert at this point? #Resolved


Refers to: lib/Runtime/Library/JavascriptObject.cpp:1152 in 871a891. [](commit_id = 871a891, deletion_comment = False)

@curtisman
Copy link
Contributor Author

@dotnet-bot test Windows x64_release

@Yongqu
Copy link
Contributor

Yongqu commented Aug 8, 2016

    // Moves to the next element and gets the current value.

Can we update the comment here? I'll try to enumerate combinations of return value I know. Please let me know if I missed something:
. return nullptr. propertyId doesn't matter. we are done
. return undefined. propertyId is the real return value; we are not done yet.
. return JavascriptString. propertyId should be consistent with JavascriptString. ie, the return value is scriptContext->GetPropertyString()
. we have a special case for es5array enumerator where return PropertyString but propertyId is NoProperty? any other special cases?


Refers to: lib/Runtime/Types/JavascriptEnumerator.h:32 in 871a891. [](commit_id = 871a891, deletion_comment = False)


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))
Copy link
Contributor

@Yongqu Yongqu Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we reverse the check order (IsUndefined first before casting to JavascriptString? #Resolved

Copy link
Contributor Author

@curtisman curtisman Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? We are checking for undefined on newElement, and we are not casting that to string. #Resolved

@curtisman
Copy link
Contributor Author

    // Moves to the next element and gets the current value.

I am planning to refactor is next and change the behavior. So I will document it then.


In reply to: 238279890 [](ancestors = 238279890)


Refers to: lib/Runtime/Types/JavascriptEnumerator.h:32 in 871a891. [](commit_id = 871a891, deletion_comment = False)

@curtisman
Copy link
Contributor Author

                propertyRecord = scriptContext->GetPropertyName(propertyId);

It is, but you need propertyRecord here.


In reply to: 238278090 [](ancestors = 238278090)


Refers to: lib/Runtime/Library/JavascriptObject.cpp:1152 in 871a891. [](commit_id = 871a891, deletion_comment = False)

@Yongqu
Copy link
Contributor

Yongqu commented Aug 8, 2016

:shipit:

@chakrabot chakrabot merged commit 871a891 into chakra-core:master Aug 8, 2016
chakrabot pushed a commit that referenced this pull request Aug 8, 2016
Merge pull request #1400 from curtisman:enumclean

The JavascriptEnumerator function GetCurrentAndMoveNext is misleading because.  Because it move to the next one before return the next element that we moved to. Change to MoveAndGetNext.

Also remove MoveNext/GetCurrentIndex/GetCurrentPropertyId, which is equivalent to GetCurrentAndMoveNext. Move all usage of those API to  MoveAndGetNext.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants