Skip to content
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

Fix for JsPointerToString and JsCreateString #6669 #6737

Closed
wants to merge 5 commits into from

Conversation

dagarxji
Copy link

#6669

  • Update for JsPointerToString and JsCreateString to ignore input string if length is 0. The function will return an empty string instead of JsErrorNullArgument.
  • This passed all unit tests.
  • The test included in the JsRTApiTest will fail without these changes.

Tagged as per issue request:
@rhuanjl

Update for JsPointerToString and JsCreateString to ignore input string if length is 0. The function will return an empty string instead of JsErrorNullArgument.
Copy link
Collaborator

@rhuanjl rhuanjl left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, always good to see a new contributor.

I've added a couple of comments below, but as well as that:

Comment on lines 168 to 174
// Test JsPointerToString and JsCreateString on NULL inputs
JsValueRef nullStr;
REQUIRE(JsPointerToString(NULL, 0, &nullStr) == JsNoError);

JsValueRef nullFname;
REQUIRE(JsCreateString(NULL, 0, &nullFname) == JsNoError);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please could you use spaces instead of tabs for the indent (here and other files) - our code base uses spaces consistently.

Comment on lines 875 to 878
if (length == 0)
{
content = "";
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please could you bring this in line with the way you've done JsPointerToString below? If length = 0, skip the PARAM_NOT_NULL(content); and then use scriptContext->GetLibrary()->GetEmptyString(); instead of the logic on lines 896 and 898 below.

Copy link
Author

@dagarxji dagarxji Aug 13, 2021

Choose a reason for hiding this comment

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

Oh, I see. I had issues with GetEmptyString() because I was including line 898. Executing 896 and 898 only when length isn't zero fixed this. Thank you.

dagarxji and others added 3 commits August 13, 2021 14:44
Update for JsPointerToString and JsCreateString to ignore input string if length is 0. The function will return an empty string instead of JsErrorNullArgument.
@dagarxji
Copy link
Author

dagarxji commented Aug 13, 2021

Well noted. I have updated the files as requested. Hopefully that will remove all of the issues.

@dagarxji dagarxji marked this pull request as draft August 13, 2021 21:08
@rhuanjl
Copy link
Collaborator

rhuanjl commented Aug 18, 2021

Looks good apart from the test failure. I think it may be because you've put the PERFORM_JSRT_TTD_RECORD_ACTION macro inside the 'if' in one of the functions - can you move that so it's always called then hopefully the test will pass.

Moved PERFORM_JSRT_TTD_RECORD_ACTION to execute outside of if statement.
Copy link
Collaborator

@rhuanjl rhuanjl left a comment

Choose a reason for hiding this comment

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

Someone else had made a start on trying to do the same issue - though this is still closer to complete - I've looked through and think I've found the likely cause of the test failure.

Comment on lines 894 to +895
Js::JavascriptString *stringValue = Js::LiteralStringWithPropertyStringPtr::
NewFromCString(content, (CharCount)length, scriptContext->GetLibrary());

NewFromCString(content, (CharCount)length, scriptContext->GetLibrary());
Copy link
Collaborator

Choose a reason for hiding this comment

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

These calls should not happen on the length = 0 path, may be the cause of the test failures

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.

None yet

2 participants