Skip to content

Commit dee1f8c

Browse files
committed
Use WCHAR instead of wchar_t
ChakraCore uses char16_t on xplat and wchar_t on Windows for 2 bytes wide strings. The reason we alter wchar_t to two bytes char16_t is that Unix wchar_t is 4 bytes long. This PR removes the code that alters wchar_t and replaces all the instances of wchar_t with WCHAR. Only ChakraCommonWindows.h is not updated.
1 parent 62f9668 commit dee1f8c

File tree

16 files changed

+79
-101
lines changed

16 files changed

+79
-101
lines changed

bin/External/catch.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ std::string toString( std::string const& value );
15711571
std::string toString( std::wstring const& value );
15721572
std::string toString( const char* const value );
15731573
std::string toString( char* const value );
1574-
std::string toString( const wchar_t* const value );
1575-
std::string toString( wchar_t* const value );
1574+
std::string toString( const WCHAR* const value );
1575+
std::string toString( WCHAR* const value );
15761576
std::string toString( int value );
15771577
std::string toString( unsigned long value );
15781578
std::string toString( unsigned int value );
@@ -8095,14 +8095,14 @@ std::string toString( char* const value ) {
80958095
return Catch::toString( static_cast<const char*>( value ) );
80968096
}
80978097

8098-
std::string toString( const wchar_t* const value )
8098+
std::string toString( const WCHAR* const value )
80998099
{
81008100
return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
81018101
}
81028102

8103-
std::string toString( wchar_t* const value )
8103+
std::string toString( WCHAR* const value )
81048104
{
8105-
return Catch::toString( static_cast<const wchar_t*>( value ) );
8105+
return Catch::toString( static_cast<const WCHAR*>( value ) );
81068106
}
81078107

81088108
std::string toString( int value ) {
@@ -10506,4 +10506,3 @@ int main (int argc, char * const argv[]) {
1050610506
using Catch::Detail::Approx;
1050710507

1050810508
#endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
10509-

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace JsRTApiTest
108108
REQUIRE(JsCreateObject(&object) == JsNoError);
109109

110110
JsPropertyIdRef name1 = JS_INVALID_REFERENCE;
111-
const wchar_t* name = nullptr;
111+
const WCHAR* name = nullptr;
112112
REQUIRE(JsGetPropertyIdFromName(_u("stringProperty1"), &name1) == JsNoError);
113113
REQUIRE(JsGetPropertyNameFromId(name1, &name) == JsNoError);
114114
CHECK(!wcscmp(name, _u("stringProperty1")));
@@ -582,7 +582,7 @@ namespace JsRTApiTest
582582
JsValueRef CALLBACK ExternalFunctionPreScriptAbortionCallback(JsValueRef /* function */, bool /* isConstructCall */, JsValueRef * args /* args */, USHORT /* cargs */, void * /* callbackState */)
583583
{
584584
JsValueRef result = JS_INVALID_REFERENCE;
585-
const wchar_t *scriptText = nullptr;
585+
const WCHAR *scriptText = nullptr;
586586
size_t scriptTextLen;
587587

588588
REQUIRE(JsStringToPointer(args[0], &scriptText, &scriptTextLen) == JsNoError);
@@ -593,7 +593,7 @@ namespace JsRTApiTest
593593
JsValueRef CALLBACK ExternalFunctionPostScriptAbortionCallback(JsValueRef /* function */, bool /* isConstructCall */, JsValueRef * args /* args */, USHORT /* cargs */, void * /* callbackState */)
594594
{
595595
JsValueRef result = JS_INVALID_REFERENCE;
596-
const wchar_t *scriptText = nullptr;
596+
const WCHAR *scriptText = nullptr;
597597
size_t scriptTextLen;
598598

599599
REQUIRE(JsStringToPointer(args[0], &scriptText, &scriptTextLen) == JsNoError);
@@ -656,7 +656,7 @@ namespace JsRTApiTest
656656
REQUIRE(JsCreateFunction(ExternalFunctionCallback, nullptr, &function) == JsNoError);
657657
testConstructorName(function, _u(""), 0);
658658

659-
wchar_t name[] = _u("FooName");
659+
WCHAR name[] = _u("FooName");
660660
JsValueRef nameString = JS_INVALID_REFERENCE;
661661
REQUIRE(JsPointerToString(name, _countof(name) - 1, &nameString) == JsNoError);
662662
REQUIRE(JsCreateNamedFunction(nameString, ExternalFunctionCallback, nullptr, &function) == JsNoError);
@@ -688,7 +688,7 @@ namespace JsRTApiTest
688688

689689
JsValueRef args[] = { GetUndefined() };
690690

691-
// throw from script, handle in host
691+
// throw from script, handle in host
692692
REQUIRE(JsGetPropertyIdFromName(_u("throwAtHost"), &name) == JsNoError);
693693
REQUIRE(JsGetProperty(global, name, &function) == JsNoError);
694694
REQUIRE(JsCallFunction(function, args, _countof(args), &result) == JsErrorScriptException);
@@ -701,12 +701,12 @@ namespace JsRTApiTest
701701
REQUIRE(JsGetPropertyIdFromName(_u("callHost"), &name) == JsNoError);
702702
REQUIRE(JsSetProperty(global, name, result, true) == JsNoError);
703703

704-
// throw from host callback, catch in script
704+
// throw from host callback, catch in script
705705
REQUIRE(JsGetPropertyIdFromName(_u("callHostWithTryCatch"), &name) == JsNoError);
706706
REQUIRE(JsGetProperty(global, name, &function) == JsNoError);
707707
REQUIRE(JsCallFunction(function, args, _countof(args), &result) == JsNoError);
708708

709-
// throw from host callback, through script, handle in host
709+
// throw from host callback, through script, handle in host
710710
REQUIRE(JsGetPropertyIdFromName(_u("callHostWithNoTryCatch"), &name) == JsNoError);
711711
REQUIRE(JsGetProperty(global, name, &function) == JsNoError);
712712
REQUIRE(JsCallFunction(function, args, _countof(args), &result) == JsErrorScriptException);
@@ -855,7 +855,7 @@ namespace JsRTApiTest
855855
JsValueRef nameValue = JS_INVALID_REFERENCE;
856856
REQUIRE(JsGetIndexedProperty(propertyNames, indexValue, &nameValue) == JsNoError);
857857

858-
const wchar_t *name = nullptr;
858+
const WCHAR *name = nullptr;
859859
size_t length;
860860
REQUIRE(JsStringToPointer(nameValue, &name, &length) == JsNoError);
861861

@@ -879,7 +879,7 @@ namespace JsRTApiTest
879879
JsPropertyIdRef propertyId = JS_INVALID_REFERENCE;
880880
JsValueRef outValue = JS_INVALID_REFERENCE;
881881
JsValueRef propertySymbols = JS_INVALID_REFERENCE;
882-
const wchar_t* name = nullptr;
882+
const WCHAR* name = nullptr;
883883
JsPropertyIdType propertyIdType;
884884

885885
REQUIRE(JsCreateObject(&object) == JsNoError);
@@ -1003,7 +1003,7 @@ namespace JsRTApiTest
10031003
bool boolValue;
10041004
BYTE *compiledScript = nullptr;
10051005
unsigned int scriptSize = 0;
1006-
const wchar_t *stringValue;
1006+
const WCHAR *stringValue;
10071007
size_t stringLength;
10081008
ByteCodeCallbackTracker tracker = {};
10091009

@@ -1030,7 +1030,7 @@ namespace JsRTApiTest
10301030

10311031
tracker.script = script;
10321032
REQUIRE(JsRunSerializedScriptWithCallback(
1033-
[](JsSourceContext sourceContext, const wchar_t** scriptBuffer)
1033+
[](JsSourceContext sourceContext, const WCHAR** scriptBuffer)
10341034
{
10351035
((ByteCodeCallbackTracker*)sourceContext)->loadedScript = true;
10361036
*scriptBuffer = ((ByteCodeCallbackTracker*)sourceContext)->script;
@@ -1079,7 +1079,7 @@ namespace JsRTApiTest
10791079
REQUIRE(oldProtect == PAGE_READWRITE);
10801080
tracker.script = scriptFnToString;
10811081
REQUIRE(JsRunSerializedScriptWithCallback(
1082-
[](JsSourceContext sourceContext, const wchar_t** scriptBuffer)
1082+
[](JsSourceContext sourceContext, const WCHAR** scriptBuffer)
10831083
{
10841084
((ByteCodeCallbackTracker*)sourceContext)->loadedScript = true;
10851085
*scriptBuffer = ((ByteCodeCallbackTracker*)sourceContext)->script;
@@ -1619,7 +1619,7 @@ namespace JsRTApiTest
16191619
REQUIRE(JsCreateFunction(ExternalFunctionPostScriptAbortionCallback, nullptr, &postScriptAbortFunction) == JsNoError);
16201620
JsValueRef scriptTextArg = JS_INVALID_REFERENCE;
16211621

1622-
wchar_t *scriptText = const_cast<wchar_t *>(terminationTests[i]);
1622+
WCHAR *scriptText = const_cast<WCHAR *>(terminationTests[i]);
16231623
REQUIRE(JsPointerToString(scriptText, wcslen(scriptText), &scriptTextArg) == JsNoError);
16241624
JsValueRef args[] = { scriptTextArg };
16251625

bin/ch/ch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ JsRuntimeHandle chRuntime = JS_INVALID_RUNTIME_HANDLE;
2121

2222
BOOL doTTRecord = false;
2323
BOOL doTTDebug = false;
24-
byte ttUri[MAX_PATH * sizeof(wchar_t)];
24+
byte ttUri[MAX_PATH * sizeof(WCHAR)];
2525
size_t ttUriByteLength = 0;
2626
UINT32 snapInterval = MAXUINT32;
2727
UINT32 snapHistoryLength = MAXUINT32;

lib/Common/CommonPal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@
7070
#undef Yield /* winbase.h defines this but we want to use it for Js::OpCode::Yield; it is Win16 legacy, no harm undef'ing it */
7171
#pragma warning(pop)
7272

73-
typedef wchar_t char16;
74-
7573
// xplat-todo: get a better name for this macro
7674
#define _u(s) L##s
7775
#define INIT_PRIORITY(x)
@@ -635,7 +633,7 @@ void TryFinally(const TryFunc& tryFunc, const FinallyFunc& finallyFunc)
635633
#else
636634
#define __TRY_FINALLY_BEGIN __try
637635
#define __FINALLY __finally
638-
#define __TRY_FINALLY_END
636+
#define __TRY_FINALLY_END
639637
#endif
640638

641639
namespace PlatformAgnostic

lib/JITIDL/JITTypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ typedef struct PropertyIdArrayIDL
435435

436436
typedef struct JavascriptStringIDL
437437
{
438-
IDL_DEF([size_is(m_charLength + 1)]) wchar_t* m_pszValue;
438+
IDL_DEF([size_is(m_charLength + 1)]) WCHAR* m_pszValue;
439439
unsigned int m_charLength;
440440
} JavascriptStringIDL;
441441

@@ -553,7 +553,7 @@ typedef struct FunctionBodyDataIDL
553553

554554
IDL_DEF([size_is(referencedPropertyIdCount)]) int * referencedPropertyIdMap;
555555

556-
IDL_DEF([size_is(nameLength)]) wchar_t * displayName;
556+
IDL_DEF([size_is(nameLength)]) WCHAR * displayName;
557557

558558
IDL_DEF([size_is(literalRegexCount)]) CHAKRA_PTR * literalRegexes;
559559

lib/Jsrt/ChakraCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ typedef void* HANDLE;
8787
typedef unsigned char BYTE;
8888
typedef BYTE byte;
8989
typedef UINT32 DWORD;
90+
typedef char16_t WCHAR;
9091
#endif
9192

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

lib/Jsrt/ChakraCommonWindows.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/// <returns>
2121
/// true if the operation succeeded, false otherwise.
2222
/// </returns>
23-
typedef bool (CHAKRA_CALLBACK * JsSerializedScriptLoadSourceCallback)(_In_ JsSourceContext sourceContext, _Outptr_result_z_ const wchar_t** scriptBuffer);
23+
typedef bool (CHAKRA_CALLBACK * JsSerializedScriptLoadSourceCallback)(_In_ JsSourceContext sourceContext, _Outptr_result_z_ const WCHAR** scriptBuffer);
2424

2525
/// <summary>
2626
/// Parses a script and returns a function representing the script.

lib/Jsrt/ChakraDebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ typedef unsigned __int32 uint32_t;
591591
/// </remarks>
592592
CHAKRA_API
593593
JsDiagEvaluate(
594-
_In_z_ const wchar_t *expression,
594+
_In_z_ const WCHAR *expression,
595595
_In_ unsigned int stackFrameIndex,
596596
_Out_ JsValueRef *evalResult);
597597

0 commit comments

Comments
 (0)