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

Resolved JsCreateString & JsPointerToString #6669 #6739

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/NativeTests/JsRTApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ namespace JsRTApiTest

JsValueRef value2 = JS_INVALID_REFERENCE;
REQUIRE(JsPointerToString(_u("value1"), wcslen(_u("value1")), &value2) == JsNoError);
//Testing JsPointerToString and JsCreateString on NULL inputs
JsValueRef nullStr;
REQUIRE(JsPointerToString(NULL, 0, &nullStr) == JsNoError);

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

REQUIRE(JsSetProperty(object, name1, value1, true) == JsNoError);
REQUIRE(JsSetProperty(object, name2, value2, true) == JsNoError);
Expand Down
3 changes: 2 additions & 1 deletion lib/Jsrt/ChakraCommonWindows.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,13 @@
/// <param name="stringValue">The string pointer to convert to a string value.</param>
/// <param name="stringLength">The length of the string to convert.</param>
/// <param name="value">The new string value.</param>
//<para> if stringlength = 0, a JS Empty string will be returned
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsPointerToString(
_In_reads_(stringLength) const wchar_t *stringValue,
_In_reads_opt_(stringLength) const wchar_t *stringValue,
_In_ size_t stringLength,
_Out_ JsValueRef *value);

Expand Down
4 changes: 3 additions & 1 deletion lib/Jsrt/ChakraCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,12 @@ typedef bool (CHAKRA_CALLBACK * JsSerializedLoadScriptCallback)
/// <param name="value">JsValueRef representing the JavascriptString</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
//<para> Have handled NULL Values by changing _In_ to _In_opt_ </para>
/// </returns>
CHAKRA_API
JsCreateString(
_In_ const char *content,

_In_opt_ const char *content,
_In_ size_t length,
_Out_ JsValueRef *value);

Expand Down
4 changes: 2 additions & 2 deletions lib/Jsrt/Core/JsrtCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ static void CastCopy(const SrcChar* src, DstChar* dst, size_t count)
}

CHAKRA_API JsCreateString(
_In_ const char *content,
_In_opt_ const char *content,
_In_ size_t length,
_Out_ JsValueRef *value)
{
Expand Down Expand Up @@ -902,7 +902,7 @@ CHAKRA_API JsCreateString(
}

CHAKRA_API JsCreateStringUtf16(
_In_ const uint16_t *content,
_In_opt_ const uint16_t *content,
_In_ size_t length,
_Out_ JsValueRef *value)
{
Expand Down
23 changes: 14 additions & 9 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,21 +1229,26 @@ CHAKRA_API JsGetStringLength(_In_ JsValueRef value, _Out_ int *length)
END_JSRT_NO_EXCEPTION
}

CHAKRA_API JsPointerToString(_In_reads_(stringLength) const WCHAR *stringValue, _In_ size_t stringLength, _Out_ JsValueRef *string)
CHAKRA_API JsPointerToString(_In_reads_opt_ (stringLength) const WCHAR *stringValue, _In_ size_t stringLength, _Out_ JsValueRef *string)
{
return ContextAPINoScriptWrapper([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
PERFORM_JSRT_TTD_RECORD_ACTION(scriptContext, RecordJsRTCreateString, stringValue, stringLength);

PARAM_NOT_NULL(stringValue);
PARAM_NOT_NULL(string);

if (!Js::IsValidCharCount(stringLength))
{
Js::JavascriptError::ThrowOutOfMemoryError(scriptContext);
}

*string = Js::JavascriptString::NewCopyBuffer(stringValue, static_cast<charcount_t>(stringLength), scriptContext);

if (stringLength == 0)
{
*string = scriptContext->GetLibrary()->GetEmptyString();
}
else{
PARAM_NOT_NULL(stringValue);
if (!Js::IsValidCharCount(stringLength))
{
Js::JavascriptError::ThrowOutOfMemoryError(scriptContext);
}
*string = Js::JavascriptString::NewCopyBuffer(stringValue, static_cast<charcount_t>(stringLength), scriptContext);
}

PERFORM_JSRT_TTD_RECORD_ACTION_RESULT(scriptContext, string);

return JsNoError;
Expand Down