Skip to content

Commit c0397a0

Browse files
author
Jianchun Xu
committed
[MERGE #3400 @jianchun] jsrt: cleanup CHAKRACOREBUILD_ symbol in headers
Merge pull request #3400 from jianchun:ccblddef `CHAKRACOREBUILD_` symbol should not be defined in `ChakraCommon.h`. The later is included by Chakra JSRT (Windows 10 SDK) and would thus incorrectly define `CHAKRACOREBUILD_` and expose ChakraCore APIs (Note that `NTBUILD` is not defined when a user includes Windows SDK headers). Move the def to `ChakraCore.h` to solve this problem. Normally including `ChakraCore.h` means using ChakraCore only APIs. (We define the symbol only when `!NTBUILD` because of one exception -- shared implementation `Jsrt.cpp` includes `ChakraCore.h`.) Moved `#ifdef CHAKRACOREBUILD_` to top of file to enclose all recent new ChakraCore APIs, to help ensure those APIs not defined/exposed to Chakra. Lastly renamed all `CHAKRACOREBUILD_` to `_CHAKRACOREBUILD`. Use this one symbol to differentiate ChakraCore APIs and implementations.
2 parents 4f5a9d9 + cf1e46c commit c0397a0

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ if(STATIC_LIBRARY)
237237
endif()
238238

239239
if(CLR_CMAKE_PLATFORM_XPLAT)
240+
add_definitions(-D_CHAKRACOREBUILD)
240241
add_definitions(-DFEATURE_PAL)
241242
add_definitions(-DPLATFORM_UNIX=1)
242243

lib/Jsrt/ChakraCommon.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ typedef unsigned short WCHAR;
9494

9595
#if (defined(_MSC_VER) && _MSC_VER <= 1900) || (!defined(_MSC_VER) && __cplusplus <= 199711L) // !C++11
9696
typedef unsigned short uint16_t;
97-
#endif
98-
99-
#if !defined(NTBUILD) && !defined(CHAKRACOREBUILD_)
100-
#define CHAKRACOREBUILD_
10197
#endif
10298

10399
/// <summary>

lib/Jsrt/ChakraCore.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@
2121
#ifndef _CHAKRACORE_H_
2222
#define _CHAKRACORE_H_
2323

24-
#include "ChakraCommon.h"
24+
#if !defined(NTBUILD) && !defined(_CHAKRACOREBUILD)
25+
#define _CHAKRACOREBUILD
26+
#endif
2527

28+
#include "ChakraCommon.h"
2629
#include "ChakraDebug.h"
2730

31+
// Begin ChakraCore only APIs
32+
#ifdef _CHAKRACOREBUILD
33+
2834
typedef void* JsModuleRecord;
2935

3036
/// <summary>
3137
/// A reference to an object owned by the SharedArrayBuffer.
3238
/// </summary>
3339
/// <remarks>
34-
/// This represents SharedContents which is heap allocated object, it can be passed through
40+
/// This represents SharedContents which is heap allocated object, it can be passed through
3541
/// different runtimes to share the underlying buffer.
3642
/// </remarks>
3743
typedef void *JsSharedArrayBufferContentHandle;
@@ -188,7 +194,6 @@ JsGetModuleHostInfo(
188194
_In_ JsModuleHostInfoKind moduleHostInfo,
189195
_Outptr_result_maybenull_ void** hostInfo);
190196

191-
#ifdef CHAKRACOREBUILD_
192197
/// <summary>
193198
/// Returns metadata relating to the exception that caused the runtime of the current context
194199
/// to be in the exception state and resets the exception state for that runtime. The metadata
@@ -661,5 +666,5 @@ CHAKRA_API
661666
JsReleaseSharedArrayBufferContentHandle(
662667
_In_ JsSharedArrayBufferContentHandle sharedContents);
663668

664-
#endif // CHAKRACOREBUILD_
669+
#endif // _CHAKRACOREBUILD
665670
#endif // _CHAKRACORE_H_

lib/Jsrt/ChakraDebug.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#ifndef _CHAKRADEBUG_H_
2121
#define _CHAKRADEBUG_H_
2222

23-
#include "ChakraCommon.h"
24-
2523
#ifdef _WIN32
2624
//Other platforms already include <stdint.h> and have this defined automatically
2725
typedef __int64 int64_t;

lib/Jsrt/Jsrt.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ CHAKRA_API JsCreateArrayBuffer(_In_ unsigned int byteLength, _Out_ JsValueRef *r
15591559
});
15601560
}
15611561

1562+
#ifdef _CHAKRACOREBUILD
15621563
CHAKRA_API JsCreateSharedArrayBufferWithSharedContent(_In_ JsSharedArrayBufferContentHandle sharedContents, _Out_ JsValueRef *result)
15631564
{
15641565
return ContextAPIWrapper<true>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
@@ -1585,7 +1586,7 @@ CHAKRA_API JsGetSharedArrayBufferContent(_In_ JsValueRef sharedArrayBuffer, _Out
15851586
{
15861587
return JsErrorInvalidArgument;
15871588
}
1588-
1589+
15891590
Js::SharedContents**& content = (Js::SharedContents**&)sharedContents;
15901591
*content = Js::SharedArrayBuffer::FromVar(sharedArrayBuffer)->GetSharedContents();
15911592

@@ -1607,6 +1608,7 @@ CHAKRA_API JsReleaseSharedArrayBufferContentHandle(_In_ JsSharedArrayBufferConte
16071608
return JsNoError;
16081609
});
16091610
}
1611+
#endif // _CHAKRACOREBUILD
16101612

16111613
CHAKRA_API JsCreateExternalArrayBuffer(_Pre_maybenull_ _Pre_writable_byte_size_(byteLength) void *data, _In_ unsigned int byteLength,
16121614
_In_opt_ JsFinalizeCallback finalizeCallback, _In_opt_ void *callbackState, _Out_ JsValueRef *result)
@@ -4130,7 +4132,7 @@ CHAKRA_API JsTTDReplayExecution(_Inout_ JsTTDMoveMode* moveMode, _Out_ int64_t*
41304132
#endif
41314133
}
41324134

4133-
#ifdef CHAKRACOREBUILD_
4135+
#ifdef _CHAKRACOREBUILD
41344136

41354137
template <class SrcChar, class DstChar>
41364138
static void CastCopy(const SrcChar* src, DstChar* dst, size_t count)
@@ -4731,4 +4733,4 @@ CHAKRA_API JsGetAndClearExceptionWithMetadata(_Out_ JsValueRef *metadata)
47314733
return JsNoError;
47324734
});
47334735
}
4734-
#endif // CHAKRACOREBUILD_
4736+
#endif // _CHAKRACOREBUILD

0 commit comments

Comments
 (0)