Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created August 24, 2016 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpodwysocki/ee56f7f7d58fb5974350cc7344ccbe46 to your computer and use it in GitHub Desktop.
Save mattpodwysocki/ee56f7f7d58fb5974350cc7344ccbe46 to your computer and use it in GitHub Desktop.
JsErrorCode Stringify(JsValueRef value, ChakraHost* self, const wchar_t** szResult, size_t* sResult)
{
JsValueType type;
IfFailRet(JsGetValueType(value, &type));
switch (type)
{
case JsUndefined:
*szResult = L"undefined";
*sResult = wcslen(*szResult);
break;
case JsNull:
*szResult = L"null";
*sResult = wcslen(*szResult);
break;
case JsBoolean:
bool bResult;
IfFailRet(JsBooleanToBool(value, &bResult));
*szResult = bResult ? L"true" : L"false";
*sResult = wcslen(*szResult);
break;
case JsString:
IfFailRet(JsStringToPointer(value, szResult, sResult));
break;
case JsNumber:
case JsObject:
case JsArray:
case JsTypedArray:
JsValueRef resultJSON;
IfFailRet(self->JsonStringify(value, &resultJSON));
IfFailRet(JsStringToPointer(resultJSON, szResult, sResult));
break;
case JsFunction:
case JsError:
case JsSymbol:
case JsArrayBuffer:
JsValueRef resultString;
IfFailRet(JsConvertValueToString(value, &resultString));
IfFailRet(JsStringToPointer(resultString, szResult, sResult));
break;
}
return JsNoError;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment