ChakraCore icon indicating copy to clipboard operation
ChakraCore copied to clipboard

error when JsPointerToString with null 0

Open karikera opened this issue 4 years ago • 9 comments

  • Source
JsPointerToString(NULL, 0, &str);
  • Expected str = empty string

  • Actual failed and returns JsErrorNullArgument

I think this should be possible

karikera avatar Mar 29 '21 09:03 karikera

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.

rhuanjl avatar Mar 29 '21 09:03 rhuanjl

data() of the empty std::wstring_view is nullptr. I needed to check it and bypassing for this issue

karikera avatar Mar 29 '21 10:03 karikera

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.

rhuanjl avatar Mar 29 '21 11:03 rhuanjl

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:

  1. Change the SAL annotation for the string input parameter from _In_ to _In_opt_ (implementation and headers)
  2. 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.
  3. Add tests for the updated functionality of both of these APIs
  4. 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.

rhuanjl avatar Mar 29 '21 12:03 rhuanjl

Hi @rhuanjl Is this issue still open will like to contribute.

ayushtyagi01 avatar May 13 '24 13:05 ayushtyagi01

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.

rhuanjl avatar May 13 '24 13:05 rhuanjl

You may also want to look at this aborted contribution as well: https://github.com/chakra-core/ChakraCore/pull/6739

rhuanjl avatar May 13 '24 13:05 rhuanjl

Hi! Can I work on this issue? @rhuanjl

Mang0codes avatar Oct 24 '24 13:10 Mang0codes

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.

rhuanjl avatar Oct 26 '24 08:10 rhuanjl