error when JsPointerToString with null 0
- Source
JsPointerToString(NULL, 0, &str);
-
Expected str = empty string
-
Actual failed and returns JsErrorNullArgument
I think this should be possible
If you're using ChakraCore can you use JsCreateString("", 0, &str); instead? (I haven't tested but with a glance at the code I think that should work)
The JsPointerToString API is part of the deprecated windows only API which we probably weren't intending to update.
data() of the empty std::wstring_view is nullptr.
I needed to check it and bypassing for this issue
You make a good point - this is by design behaviour of a deprecated API BUT:
- it's not the best design AND
- the newer API acts the same way
So it would be good to update both JsCreateString and JsPointerToString to return an empty string when given a nullptr.
I've marked this as good first issue as it would be a simple PR for someone to raise.
Should update both JsCreateString and JsPointerToString in the following ways:
- Change the SAL annotation for the string input parameter from
_In_to_In_opt_(implementation and headers) - Change the implementation so that if the provided length == 0 a param not null check is not done but instead it does scriptContext->GetLibrary->GetEmptyString() and provides the result as the output parameter then returns JsNoError.
- Add tests for the updated functionality of both of these APIs
- Update the comments in the headers to mention that providing a 0 length will ignore the input string pointer and return a Js empty string.
Locations:
- APIs are in headers lib/Jsrt/ChakraCore.h AND lib/Jsrt/ChakraWindows.h
- Implementations are in lib/Jsrt/Jsrt.cpp AND lib/Jsrt/Core/JsrtCore.cpp
- Tests should be added to existing files in either test/native-tests/test-shared-basic OR bin/NativeTests
If you open a PR tag me for review.
Hi @rhuanjl Is this issue still open will like to contribute.
Hi @rhuanjl Is this issue still open will like to contribute.
Hi @ayushtyagi01 there's a previous incomplete contribution here: https://github.com/chakra-core/ChakraCore/pull/6737 though as the contributor didn't respond to a query and it's been a couple of years, I think that's probably defunct, so yes feel free to go ahead.
You may also want to look at this aborted contribution as well: https://github.com/chakra-core/ChakraCore/pull/6739
Hi! Can I work on this issue? @rhuanjl
Hi! Can I work on this issue? @rhuanjl
Sure; as you can see above a few people have attempted it before but never got to completion, perhaps have a look at their aborted contributions as a start.