Skip to content

Commit

Permalink
Update Jsrt Utf8 types and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
obastemur committed Dec 22, 2016
1 parent 61db315 commit 94f2158
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 207 deletions.
6 changes: 3 additions & 3 deletions bin/ch/ChakraRtInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ bool ChakraRTInterface::LoadChakraDll(ArgInfo* argInfo, HINSTANCE *outLibrary)
m_jsApiHooks.pfJsrtParse = (JsAPIHooks::JsrtParse)GetChakraCoreSymbol(library, "JsParse");
m_jsApiHooks.pfJsrtSerialize = (JsAPIHooks::JsrtSerialize)GetChakraCoreSymbol(library, "JsSerialize");
m_jsApiHooks.pfJsrtRunSerialized = (JsAPIHooks::JsrtRunSerialized)GetChakraCoreSymbol(library, "JsRunSerialized");
m_jsApiHooks.pfJsrtCreateStringUtf8 = (JsAPIHooks::JsrtCreateStringUtf8)GetChakraCoreSymbol(library, "JsCreateStringUtf8");
m_jsApiHooks.pfJsrtCopyStringUtf8 = (JsAPIHooks::JsrtCopyStringUtf8)GetChakraCoreSymbol(library, "JsCopyStringUtf8");
m_jsApiHooks.pfJsrtCreatePropertyIdUtf8= (JsAPIHooks::JsrtCreatePropertyIdUtf8)GetChakraCoreSymbol(library, "JsCreatePropertyIdUtf8");
m_jsApiHooks.pfJsrtCreateString = (JsAPIHooks::JsrtCreateString)GetChakraCoreSymbol(library, "JsCreateString");
m_jsApiHooks.pfJsrtCopyString = (JsAPIHooks::JsrtCopyString)GetChakraCoreSymbol(library, "JsCopyString");
m_jsApiHooks.pfJsrtCreatePropertyId = (JsAPIHooks::JsrtCreatePropertyId)GetChakraCoreSymbol(library, "JsCreatePropertyId");
m_jsApiHooks.pfJsrtCreateExternalArrayBuffer = (JsAPIHooks::JsrtCreateExternalArrayBuffer)GetChakraCoreSymbol(library, "JsCreateExternalArrayBuffer");

m_jsApiHooks.pfJsrtTTDCreateRecordRuntime = (JsAPIHooks::JsrtTTDCreateRecordRuntimePtr)GetChakraCoreSymbol(library, "JsTTDCreateRecordRuntime");
Expand Down
18 changes: 9 additions & 9 deletions bin/ch/ChakraRtInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ struct JsAPIHooks
typedef JsErrorCode(WINAPI *JsrtParse)(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result);
typedef JsErrorCode(WINAPI *JsrtSerialize)(JsValueRef script, JsValueRef *buffer, JsParseScriptAttributes parseAttributes);
typedef JsErrorCode(WINAPI *JsrtRunSerialized)(JsValueRef buffer, JsSerializedLoadScriptCallback scriptLoadCallback, JsSourceContext sourceContext, JsValueRef sourceUrl, JsValueRef * result);
typedef JsErrorCode(WINAPI *JsrtCopyStringUtf8)(JsValueRef value, unsigned char* buffer, size_t bufferSize, size_t* written);
typedef JsErrorCode(WINAPI *JsrtCreateStringUtf8)(const unsigned char *content, size_t length, JsValueRef *value);
typedef JsErrorCode(WINAPI *JsrtCopyString)(JsValueRef value, char* buffer, size_t bufferSize, size_t* written);
typedef JsErrorCode(WINAPI *JsrtCreateString)(const char *content, size_t length, JsValueRef *value);
typedef JsErrorCode(WINAPI *JsrtCreateExternalArrayBuffer)(void *data, unsigned int byteLength, JsFinalizeCallback finalizeCallback, void *callbackState, JsValueRef *result);
typedef JsErrorCode(WINAPI *JsrtCreatePropertyIdUtf8)(const char *name, size_t length, JsPropertyIdRef *propertyId);
typedef JsErrorCode(WINAPI *JsrtCreatePropertyId)(const char *name, size_t length, JsPropertyIdRef *propertyId);

typedef JsErrorCode(WINAPI *JsrtTTDCreateRecordRuntimePtr)(JsRuntimeAttributes attributes, const byte* infoUri, size_t infoUriCount, size_t snapInterval, size_t snapHistoryLength, JsTTDInitializeForWriteLogStreamCallback writeInitializeFunction, TTDOpenResourceStreamCallback openResourceStream, JsTTDReadBytesFromStreamCallback readBytesFromStream, JsTTDWriteBytesToStreamCallback writeBytesToStream, JsTTDFlushAndCloseStreamCallback flushAndCloseStream, JsThreadServiceCallback threadService, JsRuntimeHandle *runtime);
typedef JsErrorCode(WINAPI *JsrtTTDCreateReplayRuntimePtr)(JsRuntimeAttributes attributes, const byte* infoUri, size_t infoUriCount, bool enableDebugging, JsTTDInitializeForWriteLogStreamCallback writeInitializeFunction, TTDOpenResourceStreamCallback openResourceStream, JsTTDReadBytesFromStreamCallback readBytesFromStream, JsTTDWriteBytesToStreamCallback writeBytesToStream, JsTTDFlushAndCloseStreamCallback flushAndCloseStream, JsThreadServiceCallback threadService, JsRuntimeHandle *runtime);
Expand Down Expand Up @@ -164,9 +164,9 @@ struct JsAPIHooks
JsrtParse pfJsrtParse;
JsrtSerialize pfJsrtSerialize;
JsrtRunSerialized pfJsrtRunSerialized;
JsrtCreateStringUtf8 pfJsrtCreateStringUtf8;
JsrtCopyStringUtf8 pfJsrtCopyStringUtf8;
JsrtCreatePropertyIdUtf8 pfJsrtCreatePropertyIdUtf8;
JsrtCreateString pfJsrtCreateString;
JsrtCopyString pfJsrtCopyString;
JsrtCreatePropertyId pfJsrtCreatePropertyId;
JsrtCreateExternalArrayBuffer pfJsrtCreateExternalArrayBuffer;

JsrtTTDCreateRecordRuntimePtr pfJsrtTTDCreateRecordRuntime;
Expand Down Expand Up @@ -368,9 +368,9 @@ class ChakraRTInterface
static JsErrorCode WINAPI JsParse(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result) { return HOOK_JS_API(Parse(script, sourceContext, sourceUrl, parseAttributes, result)); }
static JsErrorCode WINAPI JsSerialize(JsValueRef script, JsValueRef *buffer, JsParseScriptAttributes parseAttributes) { return HOOK_JS_API(Serialize(script, buffer, parseAttributes)); }
static JsErrorCode WINAPI JsRunSerialized(JsValueRef buffer, JsSerializedLoadScriptCallback scriptLoadCallback, JsSourceContext sourceContext, JsValueRef sourceUrl, JsValueRef * result) { return HOOK_JS_API(RunSerialized(buffer, scriptLoadCallback, sourceContext, sourceUrl, result)); }
static JsErrorCode WINAPI JsCopyStringUtf8(JsValueRef value, unsigned char* buffer, size_t bufferSize, size_t* written) { return HOOK_JS_API(CopyStringUtf8(value, buffer, bufferSize, written)); }
static JsErrorCode WINAPI JsCreateStringUtf8(const unsigned char *content, size_t length, JsValueRef *value) { return HOOK_JS_API(CreateStringUtf8(content, length, value)); }
static JsErrorCode WINAPI JsCreatePropertyIdUtf8(const char *name, size_t length, JsPropertyIdRef *propertyId) { return HOOK_JS_API(CreatePropertyIdUtf8(name, length, propertyId)); }
static JsErrorCode WINAPI JsCopyString(JsValueRef value, char* buffer, size_t bufferSize, size_t* written) { return HOOK_JS_API(CopyString(value, buffer, bufferSize, written)); }
static JsErrorCode WINAPI JsCreateString(const char *content, size_t length, JsValueRef *value) { return HOOK_JS_API(CreateString(content, length, value)); }
static JsErrorCode WINAPI JsCreatePropertyId(const char *name, size_t length, JsPropertyIdRef *propertyId) { return HOOK_JS_API(CreatePropertyId(name, length, propertyId)); }
static JsErrorCode WINAPI JsCreateExternalArrayBuffer(void *data, unsigned int byteLength, JsFinalizeCallback finalizeCallback, void *callbackState, JsValueRef *result) { return HOOK_JS_API(CreateExternalArrayBuffer(data, byteLength, finalizeCallback, callbackState, result)); }
};

Expand Down
8 changes: 4 additions & 4 deletions bin/ch/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ bool Debugger::Initialize()
(void*)controllerScript, (unsigned int)strlen(controllerScript),
nullptr, nullptr, &scriptSource));
JsValueRef fname;
ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)"DbgController.js", strlen("DbgController.js"), &fname);
ChakraRTInterface::JsCreateString(
"DbgController.js", strlen("DbgController.js"), &fname);
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsParse(scriptSource,
JS_SOURCE_CONTEXT_NONE, fname, JsParseScriptAttributeLibraryCode,
&globalFunc));
Expand Down Expand Up @@ -323,8 +323,8 @@ bool Debugger::SetBaseline()
script[numChars] = '\0';

JsValueRef wideScriptRef;
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)script, strlen(script), &wideScriptRef));
IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString(
script, strlen(script), &wideScriptRef));

this->CallFunctionNoResult("SetBaseline", wideScriptRef);
}
Expand Down
50 changes: 23 additions & 27 deletions bin/ch/WScriptJsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ DWORD_PTR WScriptJsrt::sourceContext = 0;
char *errorMessageNarrow; \
if (FAILED(WideStringToNarrowDynamic(errorMessage, &errorMessageNarrow))) \
{ \
errorCode = ChakraRTInterface::JsCreateStringUtf8( \
(const unsigned char*)outOfMemoryString, \
errorCode = ChakraRTInterface::JsCreateString(outOfMemoryString, \
strlen(outOfMemoryString), &errorMessageString); \
} \
else \
{ \
errorCode = ChakraRTInterface::JsCreateStringUtf8( \
(const unsigned char*)errorMessageNarrow, \
errorCode = ChakraRTInterface::JsCreateString(errorMessageNarrow, \
strlen(errorMessageNarrow), &errorMessageString); \
free(errorMessageNarrow); \
} \
Expand Down Expand Up @@ -90,8 +88,8 @@ bool WScriptJsrt::CreateArgumentsObject(JsValueRef *argsObject)
{
return false;
}
JsErrorCode errCode = ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)argNarrow,
JsErrorCode errCode = ChakraRTInterface::JsCreateString(
argNarrow,
strlen(argNarrow), &value);
free(argNarrow);
IfJsrtErrorFail(errCode, false);
Expand Down Expand Up @@ -325,8 +323,8 @@ JsErrorCode WScriptJsrt::LoadModuleFromString(LPCSTR fileName, LPCSTR fileConten
if (moduleRecordEntry == moduleRecordMap.end())
{
JsValueRef specifier;
errorCode = ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)fileName, strlen(fileName), &specifier);
errorCode = ChakraRTInterface::JsCreateString(
fileName, strlen(fileName), &specifier);
if (errorCode == JsNoError)
{
errorCode = ChakraRTInterface::JsInitializeModuleRecord(
Expand Down Expand Up @@ -413,7 +411,7 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateExternalArrayBuffer((void*)fileContent,
(unsigned int)strlen(fileContent), nullptr, nullptr, &scriptSource));
JsValueRef fname;
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateStringUtf8((const unsigned char*)fullPathNarrow,
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateString(fullPathNarrow,
strlen(fullPathNarrow), &fname));
errorCode = ChakraRTInterface::JsRun(scriptSource, GetNextSourceContext(),
fname, JsParseScriptAttributeNone, &returnValue);
Expand Down Expand Up @@ -446,7 +444,7 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateExternalArrayBuffer((void*)fileContent,
(unsigned int)strlen(fileContent), nullptr, nullptr, &scriptSource));
JsValueRef fname;
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateStringUtf8((const unsigned char*)fullPathNarrow,
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateString(fullPathNarrow,
strlen(fullPathNarrow), &fname));
errorCode = ChakraRTInterface::JsRun(scriptSource, GetNextSourceContext(),
fname, JsParseScriptAttributeNone, &returnValue);
Expand Down Expand Up @@ -723,8 +721,8 @@ bool WScriptJsrt::CreateNamedFunction(const char* nameString, JsNativeFunction c
JsValueRef* functionVar)
{
JsValueRef nameVar;
IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)nameString, strlen(nameString), &nameVar), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
nameString, strlen(nameString), &nameVar), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateNamedFunction(nameVar, callback,
nullptr, functionVar), false);
return true;
Expand Down Expand Up @@ -851,8 +849,8 @@ bool WScriptJsrt::Initialize()
JsPropertyIdRef archProperty;
IfJsrtErrorFail(CreatePropertyIdFromString("ARCH", &archProperty), false);
JsValueRef archValue;
IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)CPU_ARCH_TEXT, strlen(CPU_ARCH_TEXT), &archValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
CPU_ARCH_TEXT, strlen(CPU_ARCH_TEXT), &archValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, archProperty,
archValue, true), false);

Expand All @@ -865,8 +863,8 @@ bool WScriptJsrt::Initialize()
#else
#define BUILD_TYPE_STRING_CH "Release" // consider Test is also Release build (O3)
#endif
IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)BUILD_TYPE_STRING_CH, strlen(BUILD_TYPE_STRING_CH), &buildValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
BUILD_TYPE_STRING_CH, strlen(BUILD_TYPE_STRING_CH), &buildValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, buildProperty,
buildValue, true), false);
#undef BUILD_TYPE_STRING_CH
Expand All @@ -875,8 +873,8 @@ bool WScriptJsrt::Initialize()
JsPropertyIdRef linkProperty;
IfJsrtErrorFail(CreatePropertyIdFromString("LINK_TYPE", &linkProperty), false);
JsValueRef linkValue;
IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)LINK_TYPE, strlen(LINK_TYPE), &linkValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
LINK_TYPE, strlen(LINK_TYPE), &linkValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, linkProperty,
linkValue, true), false);

Expand All @@ -887,8 +885,8 @@ bool WScriptJsrt::Initialize()
JsPropertyIdRef binaryPathProperty;
IfJsrtErrorFail(CreatePropertyIdFromString("BINARY_PATH", &binaryPathProperty), false);

IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)CH_BINARY_LOCATION,
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
CH_BINARY_LOCATION,
strlen(CH_BINARY_LOCATION), &binaryPathValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(
platformObject, binaryPathProperty, binaryPathValue, true), false);
Expand All @@ -897,9 +895,8 @@ bool WScriptJsrt::Initialize()
JsPropertyIdRef osProperty;
IfJsrtErrorFail(CreatePropertyIdFromString("OS", &osProperty), false);
JsValueRef osValue;
IfJsrtErrorFail(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)DEST_PLATFORM_TEXT,
strlen(DEST_PLATFORM_TEXT), &osValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsCreateString(
DEST_PLATFORM_TEXT, strlen(DEST_PLATFORM_TEXT), &osValue), false);
IfJsrtErrorFail(ChakraRTInterface::JsSetProperty(platformObject, osProperty,
osValue, true), false);

Expand Down Expand Up @@ -978,9 +975,8 @@ JsValueRef __stdcall WScriptJsrt::LoadTextFileCallback(JsValueRef callee, bool i
else
{
JsValueRef stringObject;
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateStringUtf8(
(const unsigned char*)fileContent,
lengthBytes, &stringObject));
IfJsrtErrorSetGo(ChakraRTInterface::JsCreateString(
fileContent, lengthBytes, &stringObject));
return stringObject;
}
}
Expand Down Expand Up @@ -1204,7 +1200,7 @@ HRESULT WScriptJsrt::CallbackMessage::CallFunction(LPCSTR fileName)
IfJsrtErrorHR(ChakraRTInterface::JsConvertValueToString(m_function, &stringValue));

JsValueRef fname;
ChakraRTInterface::JsCreateStringUtf8((const unsigned char*)"", strlen(""), &fname);
ChakraRTInterface::JsCreateString("", strlen(""), &fname);
// Run the code
errorCode = ChakraRTInterface::JsRun(stringValue, JS_SOURCE_CONTEXT_NONE,
fname, JsParseScriptAttributeArrayBufferIsUtf16Encoded,
Expand Down
2 changes: 1 addition & 1 deletion bin/ch/ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ HRESULT RunScript(const char* fileName, LPCSTR fileContents, JsValueRef bufferVa

JsErrorCode runScript;
JsValueRef fname;
IfJsErrorFailLog(ChakraRTInterface::JsCreateStringUtf8((const unsigned char*)fullPath,
IfJsErrorFailLog(ChakraRTInterface::JsCreateString(fullPath,
strlen(fullPath), &fname));

if(bufferValue != nullptr)
Expand Down
7 changes: 3 additions & 4 deletions bin/ch/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ class AutoString
if (errorCode == JsNoError)
{
size_t len = 0;
errorCode = ChakraRTInterface::JsCopyStringUtf8(strValue, nullptr, 0, &len);
errorCode = ChakraRTInterface::JsCopyString(strValue, nullptr, 0, &len);
if (errorCode == JsNoError)
{
data = (char*) malloc((len + 1) * sizeof(char));
unsigned char *udata = (unsigned char*)data;
ChakraRTInterface::JsCopyStringUtf8(strValue, udata, len + 1, &length);
ChakraRTInterface::JsCopyString(strValue, data, len + 1, &length);
AssertMsg(len == length, "If you see this message.. There is something seriously wrong. Good Luck!");
*(data + len) = char(0);
}
Expand Down Expand Up @@ -256,7 +255,7 @@ class AutoString

inline JsErrorCode CreatePropertyIdFromString(const char* str, JsPropertyIdRef *Id)
{
return ChakraRTInterface::JsCreatePropertyIdUtf8(str, strlen(str), Id);
return ChakraRTInterface::JsCreatePropertyId(str, strlen(str), Id);
}

#ifdef __ANDROID__
Expand Down
8 changes: 8 additions & 0 deletions lib/Jsrt/ChakraCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ typedef UINT32 DWORD;

#endif // defined(_WIN32) && defined(_MSC_VER)

#if (defined(_MSC_VER) && _MSC_VER < 1900) || (!defined(_MSC_VER) && __cplusplus <= 199711L) // !C++11
typedef unsigned short uint16_t;
#endif

#if !defined(NTBUILD) && !defined(CHAKRACOREBUILD_)
#define CHAKRACOREBUILD_
#endif

/// <summary>
/// An error code returned from a Chakra hosting API.
/// </summary>
Expand Down
Loading

0 comments on commit 94f2158

Please sign in to comment.